mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
98_JsonList.pm: specify multiple Attributes (Forum #65900)
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@13258 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
2b9838f190
commit
f7e27b9a9f
@ -36,12 +36,13 @@ JsonList2_dumpHash($$$$$$)
|
||||
{
|
||||
my ($arrp, $name, $h, $isReading, $si, $attr) = @_;
|
||||
my $ret = "";
|
||||
my %filter;
|
||||
@filter{ @$attr } = (undef) x @$attr if @$attr;
|
||||
|
||||
my @arr = grep { $si || $_ !~ m/^\./ } sort keys %{$h};
|
||||
@arr = grep { !ref($h->{$_}) } @arr if(!$isReading);
|
||||
if($attr) {
|
||||
@arr = grep { $attr eq $_ } @arr;
|
||||
}
|
||||
my @arr = grep { $si || $_ !~ m/^\./
|
||||
and $isReading || !ref($h->{$_})
|
||||
and !%filter || exists $filter{$_}
|
||||
} sort keys %{$h};
|
||||
|
||||
for(my $i2=0; $i2 < @arr; $i2++) {
|
||||
my $k = $arr[$i2];
|
||||
@ -55,8 +56,7 @@ JsonList2_dumpHash($$$$$$)
|
||||
$ret .= "," if($i2 < int(@arr)-1);
|
||||
$ret .= "\n" if(int(@arr)>1);
|
||||
}
|
||||
return if($attr && !$ret);
|
||||
push(@{$arrp}, " \"$name\": {".(int(@arr)>1 ? "\n" : "")."$ret }");
|
||||
push(@{$arrp}, " \"$name\": {".(int(@arr)>1 ? "\n" : "")."$ret }") if $ret;
|
||||
}
|
||||
|
||||
#####################################
|
||||
@ -68,14 +68,13 @@ CommandJsonList2($$)
|
||||
my $ret;
|
||||
my $cnt=0;
|
||||
my $si = AttrVal("global", "showInternalValues", 0);
|
||||
my $attr;
|
||||
my @attr;
|
||||
|
||||
$cl->{contenttype} = "application/json; charset=utf-8" if($cl);
|
||||
|
||||
if($param) {
|
||||
my @arg = split(" ", $param);
|
||||
$attr = $arg[1];
|
||||
@d = devspec2array($arg[0],$cl);
|
||||
@attr = split(" ", $param);
|
||||
@d = devspec2array(shift(@attr),$cl);
|
||||
|
||||
} else {
|
||||
@d = devspec2array(".*", $cl); # Needed for Authorization
|
||||
@ -96,13 +95,13 @@ CommandJsonList2($$)
|
||||
next if(!$h || !$n);
|
||||
|
||||
my @r;
|
||||
if(!$attr) {
|
||||
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);
|
||||
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);
|
||||
@ -130,7 +129,7 @@ CommandJsonList2($$)
|
||||
<a name="JsonList2"></a>
|
||||
<h3>JsonList2</h3>
|
||||
<ul>
|
||||
<code>jsonlist [<devspec>] [<value>]</code>
|
||||
<code>jsonlist [<devspec>] [<value1> <value2> ...]</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
|
||||
@ -139,7 +138,7 @@ CommandJsonList2($$)
|
||||
</ul>
|
||||
Returns an JSON tree of the internal values, readings and attributes of the
|
||||
requested definitions.<br>
|
||||
If value is specified, then output only the corresponding internal (like DEF,
|
||||
If valueX 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
|
||||
@ -153,7 +152,7 @@ CommandJsonList2($$)
|
||||
<a name="JsonList2"></a>
|
||||
<h3>JsonList2</h3>
|
||||
<ul>
|
||||
<code>jsonlist [<devspec>]</code>
|
||||
<code>jsonlist [<devspec>] [<value1> <value2> ...]</code>
|
||||
<br><br>
|
||||
Dieses Befehl sollte in der FHEMWEB oder telnet Eingabezeile ausgeführt
|
||||
werden, kann aber auch direkt über HTTP abgerufen werden über
|
||||
@ -163,7 +162,7 @@ CommandJsonList2($$)
|
||||
Es liefert die JSON Darstellung der internen Variablen, Readings und
|
||||
Attribute zurück.<br>
|
||||
|
||||
Wenn value angegeben ist, dann wird nur der entsprechende Internal (DEF,
|
||||
Wenn valueX 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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user