2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

10_MQTT2_DEVICE.pm: show neighbor map for graphviz (Forum #91394)

git-svn-id: https://svn.fhem.de/fhem/trunk@18004 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2018-12-19 13:27:57 +00:00
parent 82f5fa2123
commit 466dc53e13
2 changed files with 69 additions and 3 deletions

View File

@ -18,6 +18,7 @@ MQTT2_DEVICE_Initialize($)
$hash->{AttrFn} = "MQTT2_DEVICE_Attr";
$hash->{ParseFn} = "MQTT2_DEVICE_Parse";
$hash->{RenameFn} = "MQTT2_DEVICE_Rename";
$hash->{FW_detailFn} = "MQTT2_DEVICE_fhemwebFn";
no warnings 'qw';
my @attrList = qw(
@ -86,7 +87,7 @@ MQTT2_DEVICE_Parse($$)
}
my $autocreate;
if($msg =~ m/^autocreate:(.*)/) {
if($msg =~ m/^autocreate:(.*)$/s) {
$msg = $1;
$autocreate = 1;
}
@ -451,6 +452,72 @@ MQTT2_DEVICE_Undef($$)
return undef;
}
#####################################
# Reuse the ZWDongle map for graphvis visualisation. Forum #91394
sub
MQTT2_DEVICE_fhemwebFn($$$$)
{
my ($FW_wname, $d, $room, $pageHash) = @_; # pageHash is set for summaryFn.
return if(!ReadingsVal($d, ".graphviz", ReadingsVal($d, "graphviz", "")));
my $js = "$FW_ME/pgm2/zwave_neighborlist.js";
return
"<div id='ZWDongleNr'><a id='zw_snm' href='#'>Show neighbor map</a></div>".
"<div id='ZWDongleNrSVG'></div>".
"<script type='text/javascript' src='$js'></script>".
'<script type="text/javascript">'.<<"JSEND"
\$(document).ready(function() {
\$("div#ZWDongleNr a#zw_snm")
.click(function(e){
e.preventDefault();
zw_nl('MQTT2_DEVICE_nlData("$d")');
});
});
</script>
JSEND
}
sub
MQTT2_DEVICE_nlData($)
{
my ($d) = @_;
my %h;
my $fo="";
my $gv = ReadingsVal($d, ".graphviz", ReadingsVal($d, "graphviz", ""));
for my $l (split(/[\r\n]/, $gv)) {
if($l =~ m/^\s*"([^"]+)"\s*\[label="([^"]+)"\]/) {
my ($n,$v) = ($1,$2);
$v =~ s/[{}]//;
$v =~ s/\|/<br>/g;
my $nv = $n;
$nv =~ s/^0x0*//;
$h{$n}{txt} = $nv;
$h{$n}{title} = $v;
$fo = $n if(!$fo);
my @a;
$h{$n}{neighbors} = \@a;
} elsif($l =~ m/^\s*"([^"]+)"\s*->\s*"([^"]+)"/) {
push @{$h{$1}{neighbors}}, $2;
}
}
my @ret;
for my $k (keys %h) {
my $n = $h{$k}{neighbors};
push @ret, '"'.$k.'":{'.
'"class":"zwBox col_link col_oddrow",'.
'"txt":"'.$h{$k}{txt}.'",'.
'"title":"'.$h{$k}{title}.'",'.
'"pos":[],'.
'"neighbors":['. (@{$n} ? ('"'.join('","',@{$n}).'"'):'').']}';
}
return '{"firstObj":"'.$fo.'","el":{'.join(",",@ret).'} }';
}
#####################################
# Utility functions for the AttrTemplates
sub

View File

@ -28,6 +28,7 @@ zw_nl(fhemFn)
FW_cmd(FW_root+"?cmd={"+fhemFn+"}&XHR=1", function(r){
var xpos=20, ypos=20, fnRet = JSON.parse(r);
$("#zw_save").toggle(fnRet.saveFn ? true : false);
var cnt=0;
for(var elName in fnRet.el) {
@ -56,8 +57,6 @@ zw_nl(fhemFn)
$('#ZWDongleNr a#zw_al').click(function(){ zw_al(fnRet, width, height); });
$('#ZWDongleNr a#zw_save').click(function(){
if(!fnRet.saveFn)
return;
for(var eName in fnRet.el) {
var el = fnRet.el[eName];
if(el.pos[0] != el.x || el.pos[1] != el.y) {