diff --git a/fhem/FHEM/10_MQTT2_DEVICE.pm b/fhem/FHEM/10_MQTT2_DEVICE.pm index e1b36a27e..5f73fff50 100644 --- a/fhem/FHEM/10_MQTT2_DEVICE.pm +++ b/fhem/FHEM/10_MQTT2_DEVICE.pm @@ -739,8 +739,6 @@ MQTT2_DEVICE_nlData($) my (%img,%h,%n2n); my $fo=""; - #my $pref = "https://koenkk.github.io/zigbee2mqtt/images/devices/"; - my $pref = "https://www.zigbee2mqtt.io/images/devices/"; # Needed for the image links my $dv = ReadingsVal($d, ".devices", ReadingsVal($d, "devices", "")); @@ -756,14 +754,13 @@ MQTT2_DEVICE_nlData($) my $h = json2nameValue($dv); my $dm; foreach my $key (sort keys %{$h}) { - $dm = urlEncode($h->{$key}).".jpg" + $dm = $h->{$key} if($key =~ m/^\d+_definition_model$/); - if($key =~ m/^\d+_ieee_address$/ && $dm && $dm !~ m,%2F,) { + if($key =~ m/^\d+_ieee_address$/ && $dm) { $img{$h->{$key}} = $dm; $dm = ""; } } - } # Name translation @@ -778,6 +775,30 @@ MQTT2_DEVICE_nlData($) } } + sub + getImg($$$) + { + my ($imgName, $suffix, $fileName) = @_; + + #my $pref = "https://koenkk.github.io/zigbee2mqtt/images/devices"; + my $pref = "https://www.zigbee2mqtt.io/images/devices/"; + my $url = $pref . urlEncode($imgName) . $suffix; + + Log 3, "MQTT2_DEVICE: trying $url"; + my $data = GetFileFromURL($url); + if($data && $data !~ m/$fileName")) { + Log 3, "Got data, writing $fileName, length: ".length($data); + binmode(FH); + print FH $data; + close(FH); + return 1; + } else { + Log 3, "No result"; + return 0; + } + } + + my $fPref = "$attr{global}{modpath}/www/deviceimages/mqtt2"; my $div = ($FW_userAgent =~ m/WebKit/ ? " " : " "); my $gv = ReadingsVal($d, ".graphviz", ReadingsVal($d, "graphviz", "")); $gv =~ s/\\n/\n/g; #126970 @@ -793,25 +814,33 @@ MQTT2_DEVICE_nlData($) if($v =~ m/{(.*)\|(.*)\|(.*)\|(.*)}/) { my ($x1,$x2,$x3,$x4) = ($1,$2,$3,$4); $nv = $n2n{$x1} if($n2n{$x1}); - if($img{$n}) { - my $fn = $attr{global}{modpath}."/www/deviceimages/mqtt2/" - . urlDecode($img{$n}); - if(!-f $fn) { # Cache the picture - my $url = "$pref/$img{$n}"; - Log 3, "MQTT2_DEVICE: downloading $url to $fn"; - my $data = GetFileFromURL($url); - if($data && open(FH,">$fn")) { - binmode(FH); - $data = "" if($data =~ m/$fJpg")) { # empty file: dont try it again + close(FH); + } + } + $h{$n}{img} = "$FW_ME/deviceimages/mqtt2/$fn" if($fn); } + if($img{$n} && $n2n{$x1} && !AttrVal($n2n{$x1}, "imageLink", "")) { CommandAttr(undef, "$nv imageLink $h{$n}{img}"); }