2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-03 10:46:53 +00:00

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
This commit is contained in:
rudolfkoenig 2016-12-14 13:04:42 +00:00
parent 1ad11015f7
commit 4d697abbac
6 changed files with 63 additions and 33 deletions

View File

@ -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

View File

@ -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 "</td></tr></table>";
@ -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");

View File

@ -888,7 +888,7 @@ The following local attributes are used by a wider range of devices:
<ul>
<code>list [devspec] [value]</code><br>
or<br>
<code>list -r devspec</code><br>
<code>list {-r|-R} devspec</code><br>
<br><br>
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:
[...]
</code></pre>
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.
</ul>
<a name="modify"></a>

View File

@ -937,7 +937,7 @@ Die folgenden lokalen Attribute werden von mehreren Ger&auml;ten verwendet:
<ul>
<code>list [devspec] [value]</code><br>
oder<br>
<code>list -r devspec</code><br>
<code>list {-r|-R} devspec</code><br>
<br><br>
Auflistung aller &quot;definitions&quot;, &quot;notify&quot; und
&quot;at&quot;-Definitionen. Dies ist eines der wenigen Befehle, die im
@ -999,7 +999,9 @@ Die folgenden lokalen Attribute werden von mehreren Ger&auml;ten verwendet:
[...]
</code></pre>
Mit der -r (raw) Option werden die Daten in einem f&uuml;r fhem.cfg bzw.
fhem.state passenden format generiert.
fhem.state passenden Format generiert. -R liefert diese Daten auch f&uuml;r
alle von diesem Ger&auml;t vermutlich ben&ouml;gten Ger&auml;te.
Achtung: die Bestimmung dieser Liste ist ungenau.
</ul>

View File

@ -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;

View File

@ -602,10 +602,15 @@ FW_rawDef()
$("#content").append('<div id="rawDef">'+
'<textarea id="td_longText" rows="25" cols="60" style="width:99%"/>'+
'<button>Execute commands</button>'+
' Dump "Probably associated with" too <input type="checkbox">'+
'</div></br>');
FW_cmd(FW_root+"?cmd=list -r "+dev+"&XHR=1", function(data) {
data = data.replace(/^define/, "defmod");
function
fillData(opt)
{
FW_cmd(FW_root+"?cmd=list "+opt+" "+dev+"&XHR=1", function(data) {
var re = new RegExp("^define", "gm");
data = data.replace(re, "defmod");
$("#rawDef textarea").val(data);
var off = $("#rawDef").position().top-20;
$('body, html').animate({scrollTop:off}, 500);
@ -619,6 +624,10 @@ FW_rawDef()
$("#rawDef button").hide();
});
});
}
fillData("-r");
$("#rawDef input").click(function(){fillData(this.checked ?"-R":"-r")});
$("#rawDef button").click(function(){
var data = $("#rawDef textarea").val();