From 728a7d71abffbeb79e43a04ed096c9e40f03404e Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Wed, 13 Mar 2013 18:42:59 +0000 Subject: [PATCH] - devStateIcon has an optional third parameter: command to execute - the first webCmd argument is no longer used by the state-icon, this can be implemented by the new devStateIcon parameter git-svn-id: https://svn.fhem.de/fhem/trunk@2908 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 5 ++- fhem/FHEM/01_FHEMWEB.pm | 80 ++++++++++++++++++++++------------------- 2 files changed, 47 insertions(+), 38 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 5d974e69f..7df05121e 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,7 +1,10 @@ # Add changes at the top of the list. - SVN - - change: 30_HUEDevice: allow autodetection of bridge with hue portal services + - change: FHEMWEB: the first webCmd argument is no longer used by the + state-icon, this can be implemented by the new devStateIcon + - change: 30_HUEDevice: allow autodetection of bridge with hue portal + services - feature: THRESHOLD Module by Damian - change: 30_HUEDevice: use new devStateIcon feature to show device color in room overview diff --git a/fhem/FHEM/01_FHEMWEB.pm b/fhem/FHEM/01_FHEMWEB.pm index 2e667fbbc..6ca23c723 100755 --- a/fhem/FHEM/01_FHEMWEB.pm +++ b/fhem/FHEM/01_FHEMWEB.pm @@ -366,7 +366,7 @@ FW_answerCall($) # if we do not have the icon, we convert the device state to the icon name if(!$iconPath) { - $icon = FW_dev2image($icon); + ($icon, undef, undef) = FW_dev2image($icon); $cacheable = 0; return 0 if(!$icon); $iconPath = FW_iconPath($icon); @@ -2267,15 +2267,25 @@ FW_dev2image($) my (undef, $rstate) = ReplaceEventMap($name, [undef, $state], 0); - my $icon; + my ($icon, $rlink); my $devStateIcon = AttrVal($name, "devStateIcon", undef); if(defined($devStateIcon)) { - return $devStateIcon if($devStateIcon =~ m/^{.*}$/); + if($devStateIcon =~ m/^{.*}$/) { + my ($html, $link) = eval $devStateIcon; + Log 1, "devStateIcon $name: $@" if($@); + return ($link, undef, 1) if(!$html); # only one value returned by the {} + return ($html, $link, 1); + } + my @list = split(" ", $devStateIcon); foreach my $l (@list) { - my ($re,$iconName) = split(":", $l); - if(defined($re) && $state =~ m/^$re$/) { - return FW_iconName($iconName); # Can be used to preserve text + my ($re, $iconName, $link) = split(":", $l, 3); + if($re && $state =~ m/^$re$/) { + if($iconName eq "") { + $rlink = $link; + last; + } + return ($iconName, $link, 0); # Can be used to preserve text } } } @@ -2285,14 +2295,14 @@ FW_dev2image($) $icon = FW_iconName("$name.$state") if(!$icon); # lamp.Aus.png $icon = FW_iconName("$name.$rstate") if(!$icon); # lamp.on.png $icon = FW_iconName($name) if(!$icon); # lamp.png - $icon = FW_iconName("$model.$state") if(!$icon && $model); # HM-OU-LED16.off.png - $icon = FW_iconName($model) if(!$icon && $model); # HM-OU-LED16.png + $icon = FW_iconName("$model.$state") if(!$icon && $model); # fs20st.off.png + $icon = FW_iconName($model) if(!$icon && $model); # fs20st.png $icon = FW_iconName("$type.$state") if(!$icon); # FS20.Aus.png $icon = FW_iconName("$type.$rstate") if(!$icon); # FS20.on.png $icon = FW_iconName($type) if(!$icon); # FS20.png $icon = FW_iconName($state) if(!$icon); # Aus.png $icon = FW_iconName($rstate) if(!$icon); # on.png - return $icon; + return ($icon, $rlink, 0); } sub @@ -2463,14 +2473,14 @@ FW_devState($$) { my ($d, $rf) = @_; - my ($hasOnOff, $cmdlist, $link); + my ($hasOnOff, $link); - my $webCmd = AttrVal($d, "webCmd", ""); + my $cmdList = AttrVal($d, "webCmd", ""); my $allSets = getAllSets($d); my $state = $defs{$d}{STATE}; $state = "" if(!defined($state)); - $hasOnOff = (!$webCmd && $allSets =~ m/\bon\b/ && $allSets =~ m/\boff\b/); + $hasOnOff = ($allSets =~ m/\bon\b/ && $allSets =~ m/\boff\b/); my $txt = $state; if(defined(AttrVal($d, "showtime", undef))) { my $v = $defs{$d}{READINGS}{state}{TIME}; @@ -2480,40 +2490,34 @@ FW_devState($$) $txt = ReadingsVal($d, "measured-temp", ""); $txt =~ s/ .*//; $txt .= "°C"; - $cmdlist = "desired-temp"; + $cmdList = "desired-temp" if(!$cmdList); + } elsif($allSets =~ m/\bdesiredTemperature:/) { $txt = ReadingsVal($d, "temperature", ""); $txt =~ s/ .*//; $txt .= "°C"; - $cmdlist = "desiredTemperature"; + $cmdList = "desiredTemperature" if(!$cmdList); + } else { - my $icon; - $icon = FW_dev2image($d); - if($icon) { - if($icon =~ m/^{.*}$/) { - $txt = AnalyzePerlCommand(undef, $icon); - } else { - $txt = FW_makeImage($icon, $txt); - } - } + my ($icon, $isHtml); + ($icon, $link, $isHtml) = FW_dev2image($d); + $txt = ($isHtml ? $icon : FW_makeImage($icon, $state)) if($icon); + $link = "cmd.$d=set $d $link" if($link); + } $txt = "