From 4d697abbac8eec33e543f91f40a91e132426a69b Mon Sep 17 00:00:00 2001
From: rudolfkoenig <>
Date: Wed, 14 Dec 2016 13:04:42 +0000
Subject: [PATCH] 01_FHEMWEB.pm & co: Dump "Probably associated with" in the
raw definition (Forum #60599)
git-svn-id: https://svn.fhem.de/fhem/trunk@12772 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/CHANGED | 1 +
fhem/FHEM/01_FHEMWEB.pm | 14 ++----------
fhem/docs/commandref_frame.html | 6 +++--
fhem/docs/commandref_frame_DE.html | 6 +++--
fhem/fhem.pl | 34 +++++++++++++++++++++++++----
fhem/www/pgm2/fhemweb.js | 35 +++++++++++++++++++-----------
6 files changed, 63 insertions(+), 33 deletions(-)
diff --git a/fhem/CHANGED b/fhem/CHANGED
index 4aab767f6..7b3f80253 100644
--- a/fhem/CHANGED
+++ b/fhem/CHANGED
@@ -1,5 +1,6 @@
# 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.
+ - feature: 01_FHEMWEB: Dump "Probably associated with" in Raw definition
- bugfix: 93_DbRep: added balance diff to diffValue, balance diff to next
period if value is 0 between two periods with values
are set
diff --git a/fhem/FHEM/01_FHEMWEB.pm b/fhem/FHEM/01_FHEMWEB.pm
index f5db0c3e0..f749b052c 100755
--- a/fhem/FHEM/01_FHEMWEB.pm
+++ b/fhem/FHEM/01_FHEMWEB.pm
@@ -1260,17 +1260,7 @@ FW_doDetail($)
FW_pO FW_detailSelect($d, "attr", $attrList);
FW_makeTable("Attributes", $d, $attr{$d}, "deleteattr");
- ## dependent objects
- my @dob; # dependent objects - triggered by current device
- foreach my $dn (sort keys %defs) {
- next if(!$dn || $dn eq $d);
- my $dh = $defs{$dn};
- if(($dh->{DEF} && $dh->{DEF} =~ m/\b$d\b/) ||
- ($h->{DEF} && $h->{DEF} =~ m/\b$dn\b/)) {
- push(@dob, $dn);
- }
- }
- FW_makeTableFromArray("Probably associated with", "assoc", @dob,);
+ FW_makeTableFromArray("Probably associated with", "assoc", getPawList($d));
FW_pO "";
@@ -1278,7 +1268,7 @@ FW_doDetail($)
FW_pH "cmd=style iconFor $d", "Select icon", undef, "detLink iconFor";
FW_pH "cmd=style showDSI $d", "Extend devStateIcon", undef, "detLink showDSI";
- FW_pH "cmd=rawDef $d", "Raw defintion", undef, "detLink rawDef";
+ FW_pH "cmd=rawDef $d", "Raw definition", undef, "detLink rawDef";
FW_pH "cmd=delete $d", "Delete this device ($d)", undef, "detLink delDev"
if($d ne "global");
my $sfx = AttrVal("global", "language", "EN");
diff --git a/fhem/docs/commandref_frame.html b/fhem/docs/commandref_frame.html
index 24da576c7..d62fb35dc 100644
--- a/fhem/docs/commandref_frame.html
+++ b/fhem/docs/commandref_frame.html
@@ -888,7 +888,7 @@ The following local attributes are used by a wider range of devices:
list [devspec] [value]
or
- list -r devspec
+ list {-r|-R} devspec
Output a list of all definitions, all notify settings and all at
entries. This is one of the few commands which return a string in a
@@ -950,7 +950,9 @@ The following local attributes are used by a wider range of devices:
[...]
With the -r (raw) option output the device definition in a format suitable
- for inclusion in fhem.cfg and fhem.state.
+ for inclusion in fhem.cfg and fhem.state. -R returns the definition of the
+ device itself, together with the definition of probably associated devices.
+ Note: the algorithm to select associated devices is known to be imperfect.
diff --git a/fhem/docs/commandref_frame_DE.html b/fhem/docs/commandref_frame_DE.html
index ac9151e7b..d9b416a72 100644
--- a/fhem/docs/commandref_frame_DE.html
+++ b/fhem/docs/commandref_frame_DE.html
@@ -937,7 +937,7 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
list [devspec] [value]
oder
- list -r devspec
+ list {-r|-R} devspec
Auflistung aller "definitions", "notify" und
"at"-Definitionen. Dies ist eines der wenigen Befehle, die im
@@ -999,7 +999,9 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
[...]
Mit der -r (raw) Option werden die Daten in einem für fhem.cfg bzw.
- fhem.state passenden format generiert.
+ fhem.state passenden Format generiert. -R liefert diese Daten auch für
+ alle von diesem Gerät vermutlich benögten Geräte.
+ Achtung: die Bestimmung dieser Liste ist ungenau.
diff --git a/fhem/fhem.pl b/fhem/fhem.pl
index 0ad34f4c5..6960c5ec5 100755
--- a/fhem/fhem.pl
+++ b/fhem/fhem.pl
@@ -114,6 +114,7 @@ sub fhemTzOffset($);
sub getAllAttr($);
sub getAllGets($);
sub getAllSets($);
+sub getPawList($);
sub getUniqueId();
sub latin1ToUtf8($);
sub myrename($$$);
@@ -2187,9 +2188,17 @@ CommandList($$)
my ($cl, $param) = @_;
my $str = "";
- if($param =~ m/^-r *(.*)$/) {
- my @list = devspec2array($1 ? $1 : ".*", $cl);
- foreach my $d (sort @list) {
+ if($param =~ m/^-r *(.*)$/i) {
+ my @list;
+ my $arg = $1;
+ if($param =~ m/^-R/) {
+ return "-R needs a valid device as argument" if(!$arg);
+ push @list, $arg;
+ push @list, getPawList($arg);
+ } else {
+ @list = devspec2array($arg ? $arg : ".*", $cl);
+ }
+ foreach my $d (@list) {
return "No device named $d found" if(!defined($defs{$d}));
$str .= "\n" if($str);
my @a = GetDefAndAttr($d);
@@ -4802,7 +4811,7 @@ parseParams($;$)
$value =~ s/^.(.*).$/$1/;
}
- #collext all parts until opening { and closing } are matched
+ #collect all parts until opening { and closing } are matched
if( $value =~ m/^{/ ) { # } for match
my $count = 0;
for my $i (0..length($value)-1) {
@@ -4835,5 +4844,22 @@ parseParams($;$)
return(\@a, \%h);
}
+# get "Porbably Associated With" list for a devicename
+sub
+getPawList($)
+{
+ my ($d) = @_;
+ my $h = $defs{$d};
+ my @dob;
+ foreach my $dn (sort keys %defs) {
+ next if(!$dn || $dn eq $d);
+ my $dh = $defs{$dn};
+ if(($dh->{DEF} && $dh->{DEF} =~ m/\b$d\b/) ||
+ ($h->{DEF} && $h->{DEF} =~ m/\b$dn\b/)) {
+ push(@dob, $dn);
+ }
+ }
+ return @dob;
+}
1;
diff --git a/fhem/www/pgm2/fhemweb.js b/fhem/www/pgm2/fhemweb.js
index dc74d82aa..c21fef61c 100644
--- a/fhem/www/pgm2/fhemweb.js
+++ b/fhem/www/pgm2/fhemweb.js
@@ -602,23 +602,32 @@ FW_rawDef()
$("#content").append('