mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-21 20:06:18 +00:00
98_JsonList2.pm: add (optional) value, just like for list
git-svn-id: https://svn.fhem.de/fhem/trunk@8525 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
a02a0fd70e
commit
7d9c32e1e7
@ -40,14 +40,16 @@ JsonList2_Escape($)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub
|
sub
|
||||||
JsonList2_dumpHash($$$$$)
|
JsonList2_dumpHash($$$$$$)
|
||||||
{
|
{
|
||||||
my ($name, $h, $isReading, $si, $next) = @_;
|
my ($arrp, $name, $h, $isReading, $si, $attr) = @_;
|
||||||
my $ret = "";
|
my $ret = "";
|
||||||
|
|
||||||
$ret .= " \"$name\": {\n";
|
|
||||||
my @arr = grep { $si || $_ !~ m/^\./ } sort keys %{$h};
|
my @arr = grep { $si || $_ !~ m/^\./ } sort keys %{$h};
|
||||||
@arr = grep { !ref($h->{$_}) } @arr if(!$isReading);
|
@arr = grep { !ref($h->{$_}) } @arr if(!$isReading);
|
||||||
|
if($attr) {
|
||||||
|
@arr = grep { $attr eq $_ } @arr;
|
||||||
|
}
|
||||||
|
|
||||||
for(my $i2=0; $i2 < @arr; $i2++) {
|
for(my $i2=0; $i2 < @arr; $i2++) {
|
||||||
my $k = $arr[$i2];
|
my $k = $arr[$i2];
|
||||||
@ -59,10 +61,10 @@ JsonList2_dumpHash($$$$$)
|
|||||||
$ret .= "\"".JsonList2_Escape($h->{$k})."\"";
|
$ret .= "\"".JsonList2_Escape($h->{$k})."\"";
|
||||||
}
|
}
|
||||||
$ret .= "," if($i2 < int(@arr)-1);
|
$ret .= "," if($i2 < int(@arr)-1);
|
||||||
$ret .= "\n";
|
$ret .= "\n" if(int(@arr)>1);
|
||||||
}
|
}
|
||||||
$ret .= " }".($next ? ",":"")."\n";
|
return if($attr && !$ret);
|
||||||
return $ret;
|
push(@{$arrp}, " \"$name\": {".(int(@arr)>1 ? "\n" : "")."$ret }");
|
||||||
}
|
}
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
@ -74,9 +76,12 @@ CommandJsonList2($$)
|
|||||||
my $ret;
|
my $ret;
|
||||||
my $cnt=0;
|
my $cnt=0;
|
||||||
my $si = AttrVal("global", "showInternalValues", 0);
|
my $si = AttrVal("global", "showInternalValues", 0);
|
||||||
|
my $attr;
|
||||||
|
|
||||||
if($param) {
|
if($param) {
|
||||||
@d = devspec2array($param);
|
my @arg = split(" ", $param);
|
||||||
|
$attr = $arg[1];
|
||||||
|
@d = devspec2array($arg[0]);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@d = keys %defs;
|
@d = keys %defs;
|
||||||
@ -95,20 +100,22 @@ CommandJsonList2($$)
|
|||||||
my $h = $defs{$d};
|
my $h = $defs{$d};
|
||||||
my $n = $h->{NAME};
|
my $n = $h->{NAME};
|
||||||
next if(!$h || !$n);
|
next if(!$h || !$n);
|
||||||
$cnt++;
|
|
||||||
|
|
||||||
|
my @r;
|
||||||
|
if(!$attr) {
|
||||||
|
push(@r," \"PossibleSets\":\"".JsonList2_Escape(getAllSets($n))."\"");
|
||||||
|
push(@r," \"PossibleAttrs\":\"".JsonList2_Escape(getAllAttr($n))."\"");
|
||||||
|
}
|
||||||
|
JsonList2_dumpHash(\@r, "Internals", $h, 0, $si, $attr);
|
||||||
|
JsonList2_dumpHash(\@r, "Readings", $h->{READINGS}, 1, $si, $attr);
|
||||||
|
JsonList2_dumpHash(\@r, "Attributes",$attr{$d}, 0, $si, $attr);
|
||||||
|
|
||||||
|
next if(!@r);
|
||||||
|
$ret .= ",\n" if($cnt);
|
||||||
$ret .= " {\n";
|
$ret .= " {\n";
|
||||||
$ret .= " \"Name\":\"".JsonList2_Escape($n)."\",\n";
|
$ret .= " \"Name\":\"".JsonList2_Escape($n)."\",\n".join(",\n",@r)."\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 .= " }";
|
||||||
$ret .= "," if($i1 < int(@d)-1);
|
$cnt++;
|
||||||
$ret .= "\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret .= " ],\n";
|
$ret .= " ],\n";
|
||||||
@ -126,7 +133,7 @@ CommandJsonList2($$)
|
|||||||
<a name="JsonList2"></a>
|
<a name="JsonList2"></a>
|
||||||
<h3>JsonList2</h3>
|
<h3>JsonList2</h3>
|
||||||
<ul>
|
<ul>
|
||||||
<code>jsonlist [<devspec>]</code>
|
<code>jsonlist [<devspec>] [<value>]</code>
|
||||||
<br><br>
|
<br><br>
|
||||||
This is a command, to be issued on the command line (FHEMWEB or telnet
|
This is a command, to be issued on the command line (FHEMWEB or telnet
|
||||||
interface). Can also be called via HTTP by
|
interface). Can also be called via HTTP by
|
||||||
@ -135,6 +142,9 @@ CommandJsonList2($$)
|
|||||||
</ul>
|
</ul>
|
||||||
Returns an JSON tree of the internal values, readings and attributes of the
|
Returns an JSON tree of the internal values, readings and attributes of the
|
||||||
requested definitions.<br>
|
requested definitions.<br>
|
||||||
|
If value is specified, then output only the corresponding internal (like DEF,
|
||||||
|
TYPE, etc), reading (actuator, measured-temp) or attribute for all devices
|
||||||
|
from the devspec.<br><br>
|
||||||
<b>Note</b>: the old command jsonlist (without the 2 as suffix) is deprecated
|
<b>Note</b>: the old command jsonlist (without the 2 as suffix) is deprecated
|
||||||
and will be removed in the future<br>
|
and will be removed in the future<br>
|
||||||
</ul>
|
</ul>
|
||||||
@ -154,7 +164,12 @@ CommandJsonList2($$)
|
|||||||
http://fhemhost:8083/fhem?cmd=jsonlist2&XHR=1
|
http://fhemhost:8083/fhem?cmd=jsonlist2&XHR=1
|
||||||
</ul>
|
</ul>
|
||||||
Es liefert die JSON Darstellung der internen Variablen, Readings und
|
Es liefert die JSON Darstellung der internen Variablen, Readings und
|
||||||
Attribute zurück.
|
Attribute zurück.<br>
|
||||||
|
|
||||||
|
Wenn value angegeben ist, dann wird nur der entsprechende Internal (DEF,
|
||||||
|
TYPE, usw), Reading (actuator, measured-temp) oder Attribut
|
||||||
|
zurückgeliefert für alle Geräte die in devspec angegeben sind.
|
||||||
|
<br><br>
|
||||||
<b>Achtung</b>: die alte Version dieses Befehls (jsonlist, ohne 2 am Ende) is
|
<b>Achtung</b>: die alte Version dieses Befehls (jsonlist, ohne 2 am Ende) is
|
||||||
überholt, und wird in der Zukunft entfernt.<br>
|
überholt, und wird in der Zukunft entfernt.<br>
|
||||||
</ul>
|
</ul>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user