mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
JsonList2 added
git-svn-id: https://svn.fhem.de/fhem/trunk@5177 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
5954c2c8fe
commit
257ddc6026
@ -1,6 +1,7 @@
|
||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
||||
# Do not insert empty lines here, update check depends on it.
|
||||
- SVN
|
||||
- feature: jsonlist2 added, jsonlist is deprecated.
|
||||
- change: renamed 98_configDB to 98_configDBwrap
|
||||
- feature: DbLog: Added new function : ReadingsVal/ReadingsTimestamp
|
||||
- feature: Text2Speech: added new attribute TTS_VolumeAdjust
|
||||
|
@ -406,6 +406,9 @@ CommandJsonList($$)
|
||||
<a name="JsonList"></a>
|
||||
<h3>JsonList</h3>
|
||||
<ul>
|
||||
<b>Note</b>: this command is deprecated, use <a
|
||||
href="#JsonList2">jsonlist2</a> instead.<br><br>
|
||||
|
||||
<code>jsonlist [<devspec>|<typespec>|ROOMS]</code>
|
||||
<br><br>
|
||||
Returns an JSON tree of all definitions, all notify settings and all at
|
||||
|
163
fhem/FHEM/98_JsonList2.pm
Normal file
163
fhem/FHEM/98_JsonList2.pm
Normal file
@ -0,0 +1,163 @@
|
||||
################################################################
|
||||
# $Id: 98_JsonList2.pm 4128 2013-10-29 06:51:24Z rudolfkoenig $
|
||||
################################################################
|
||||
|
||||
package main;
|
||||
use strict;
|
||||
use warnings;
|
||||
use POSIX;
|
||||
|
||||
sub CommandJsonList2($$);
|
||||
|
||||
#####################################
|
||||
sub
|
||||
JsonList2_Initialize($$)
|
||||
{
|
||||
my %lhash = ( Fn=>"CommandJsonList2",
|
||||
Hlp=>"[<devspec>],list definitions as JSON" );
|
||||
$cmds{jsonlist2} = \%lhash;
|
||||
}
|
||||
|
||||
|
||||
#####################################
|
||||
sub
|
||||
JsonList2_Escape($)
|
||||
{
|
||||
my $a = shift;
|
||||
return "null" if(!defined($a));
|
||||
my %esc = (
|
||||
"\n" => '\n',
|
||||
"\r" => '\r',
|
||||
"\t" => '\t',
|
||||
"\f" => '\f',
|
||||
"\b" => '\b',
|
||||
"\"" => '\"',
|
||||
"\\" => '\\\\',
|
||||
"\'" => '\\\'',
|
||||
);
|
||||
$a =~ s/([\x22\x5c\n\r\t\f\b])/$esc{$1}/eg;
|
||||
return $a;
|
||||
}
|
||||
|
||||
sub
|
||||
JsonList2_dumpHash($$$$$)
|
||||
{
|
||||
my ($name, $h, $isReading, $si, $next) = @_;
|
||||
my $ret = "";
|
||||
|
||||
$ret .= " \"$name\": {\n";
|
||||
my @arr = grep { $si || $_ !~ m/^\./ } sort keys %{$h};
|
||||
@arr = grep { !ref($h->{$_}) } @arr if(!$isReading);
|
||||
|
||||
for(my $i2=0; $i2 < @arr; $i2++) {
|
||||
my $k = $arr[$i2];
|
||||
$ret .= " \"".JsonList2_Escape($k)."\": ";
|
||||
if($isReading) {
|
||||
$ret .= "{ \"Value\":\"".JsonList2_Escape($h->{$k}{VAL})."\",";
|
||||
$ret .= " \"Time\":\"".JsonList2_Escape($h->{$k}{TIME})."\" }";
|
||||
} else {
|
||||
$ret .= "\"".JsonList2_Escape($h->{$k})."\"";
|
||||
}
|
||||
$ret .= "," if($i2 < int(@arr)-1);
|
||||
$ret .= "\n";
|
||||
}
|
||||
$ret .= " }".($next ? ",":"")."\n";
|
||||
return $ret;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
CommandJsonList2($$)
|
||||
{
|
||||
my ($cl, $param) = @_;
|
||||
my @d;
|
||||
my $ret;
|
||||
my $cnt=0;
|
||||
my $si = AttrVal("global", "showInternalValues", 0);
|
||||
|
||||
if($param) {
|
||||
@d = devspec2array($param);
|
||||
|
||||
} else {
|
||||
@d = keys %defs;
|
||||
$param="";
|
||||
|
||||
}
|
||||
|
||||
$ret = "{\n";
|
||||
$ret .= " \"Arg\":\"".JsonList2_Escape($param)."\",\n",
|
||||
$ret .= " \"Results\": [\n";
|
||||
|
||||
for(my $i1 = 0; $i1 < int(@d); $i1++) {
|
||||
my $d = $d[$i1];
|
||||
next if(IsIgnored($d));
|
||||
$cnt++;
|
||||
|
||||
my $h = $defs{$d};
|
||||
my $n = $h->{NAME};
|
||||
next if(!$h || !$n);
|
||||
|
||||
$ret .= " {\n";
|
||||
$ret .= " \"Name\":\"".JsonList2_Escape($n)."\",\n";
|
||||
$ret .= " \"PossibleSets\":\"".JsonList2_Escape(getAllSets($n))."\",\n";
|
||||
$ret .= " \"PossibleAttrs\":\"".JsonList2_Escape(getAllAttr($n))."\",\n";
|
||||
|
||||
$ret .= JsonList2_dumpHash("Internals", $h, 0, $si, 1);
|
||||
$ret .= JsonList2_dumpHash("Readings", $h->{READINGS}, 1, $si, 1);
|
||||
$ret .= JsonList2_dumpHash("Attributes",$attr{$d}, 0, $si, 0);
|
||||
|
||||
$ret .= " }";
|
||||
$ret .= "," if($i1 < int(@d)-1);
|
||||
$ret .= "\n";
|
||||
}
|
||||
|
||||
$ret .= " ],\n";
|
||||
$ret .= " \"totalResultsReturned\":$cnt\n";
|
||||
$ret .= "}\n";
|
||||
return $ret;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=begin html
|
||||
|
||||
<a name="JsonList2"></a>
|
||||
<h3>JsonList2</h3>
|
||||
<ul>
|
||||
<code>jsonlist [<devspec>]</code>
|
||||
<br><br>
|
||||
This is a command, to be issued on the command line (FHEMWEB or telnet
|
||||
interface). Can also be called via HTTP by
|
||||
<ul>
|
||||
http://fhemhost:8083/fhem?cmd=jsonlist2&XHR=1
|
||||
</ul>
|
||||
Returns an JSON tree of the internal values, readings and attributes of the
|
||||
requested definitions.<br>
|
||||
<b>Note</b>: the old command jsonlist (without the 2 as suffix) is deprecated
|
||||
and will be removed in the future<br>
|
||||
</ul>
|
||||
|
||||
=end html
|
||||
|
||||
=begin html_DE
|
||||
|
||||
<a name="JsonList2"></a>
|
||||
<h3>JsonList2</h3>
|
||||
<ul>
|
||||
<code>jsonlist [<devspec>]</code>
|
||||
<br><br>
|
||||
Dieses Befehl sollte in der FHEMWEB oder telnet Eingabezeile ausgeführt
|
||||
werden, kann aber auch direkt über HTTP abgerufen werden über
|
||||
<ul>
|
||||
http://fhemhost:8083/fhem?cmd=jsonlist2&XHR=1
|
||||
</ul>
|
||||
Es liefert die JSON Darstellung der internen Variablen, Readings und
|
||||
Attribute zurück.
|
||||
<b>Achtung</b>: die alte Version dieses Befehls (jsonlist, ohne 2 am Ende) is
|
||||
überholt, und wird in der Zukunft entfernt.<br>
|
||||
</ul>
|
||||
|
||||
=end html_DE
|
||||
=cut
|
@ -51,6 +51,7 @@
|
||||
<a href="#include">include</a>
|
||||
<a href="#inform">inform</a>
|
||||
<a href="#JsonList">JsonList</a>
|
||||
<a href="#JsonList2">JsonList2</a>
|
||||
<a href="#list">list</a>
|
||||
<a href="#modify">modify</a>
|
||||
<a href="#notice">notice</a>
|
||||
|
@ -49,6 +49,7 @@
|
||||
<a href="#include">include</a>
|
||||
<a href="#inform">inform</a>
|
||||
<a href="#JsonList">JsonList</a>
|
||||
<a href="#JsonList2">JsonList2</a>
|
||||
<a href="#list">list</a>
|
||||
<a href="#modify">modify</a>
|
||||
<a href="#notice">notice</a>
|
||||
|
Loading…
Reference in New Issue
Block a user