From ccddc5f936c4aa850de2440be06dda2f8829c67a Mon Sep 17 00:00:00 2001 From: jpawlowski Date: Sun, 9 Dec 2018 18:45:44 +0000 Subject: [PATCH] 70_LaMetric2: allow to set either message or icon to null git-svn-id: https://svn.fhem.de/fhem/trunk@17941 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/70_LaMetric2.pm | 56 +++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/fhem/FHEM/70_LaMetric2.pm b/fhem/FHEM/70_LaMetric2.pm index be2a5e83b..68c497061 100644 --- a/fhem/FHEM/70_LaMetric2.pm +++ b/fhem/FHEM/70_LaMetric2.pm @@ -267,7 +267,7 @@ sub LaMetric2_Define($$) { $hash->{HOST} = $host; $hash->{".API_KEY"} = $apikey; - $hash->{VERSION} = "2.2.0"; + $hash->{VERSION} = "2.2.1"; $hash->{INTERVAL} = $interval && looks_like_number($interval) ? $interval : 60; $hash->{PORT} = $port && looks_like_number($port) ? $port : 4343; @@ -1582,8 +1582,7 @@ sub LaMetric2_SetNotification { $h->{msg} ? $h->{msg} : ( $h->{text} ? $h->{text} : join ' ', @$a ) ); - - Debug "2: " . Dumper . @$a; + $values{message} = "" if ( $values{message} eq "none" ); # chart frame if ( $h->{chart} ) { @@ -1876,8 +1875,9 @@ sub LaMetric2_SetNotification { return "Usage: $name msg [ option1= option2='' ... ]" - unless ( ( defined( $values{message} ) && $values{message} ne "" ) - || $values{title} ne "" + unless ( $values{title} ne "" + || ( defined( $values{message} ) && $values{message} ne "" ) + || ( defined( $values{icon} ) && $values{icon} ne "" ) || defined( $values{chart} ) || defined( $values{goal} ) || defined( $values{metric} ) ); @@ -1960,29 +1960,45 @@ sub LaMetric2_SetNotification { readingsBulkUpdate( $hash, "lastNotificationTitle", "" ); } - if ( defined( $values{message} ) && $values{message} ne "" ) { - foreach my $line ( split /\\n/, $values{message} ) { - $line = trim($line); - next if ( !$line || $line eq "" ); - - my $ico = $values{icon}; - - if ( $notification{model}{frames} ) { - $ico = "" unless ( $h->{forceicon} ); - - #TODO define icon inline per frame. - # Must be compatible with FHEM-msg command - } + if ( defined( $values{message} ) ) { + # empty frame + if ( $values{message} eq "" ) { push @{ $notification{model}{frames} }, ( { - icon => $ico, - text => $line, + icon => $values{icon}, + text => "", index => $index++, } ); } + + # regular frames + else { + foreach my $line ( split /\\n/, $values{message} ) { + $line = trim($line); + next if ( !$line || $line eq "" ); + + my $ico = $values{icon}; + + if ( $notification{model}{frames} ) { + $ico = "" unless ( $h->{forceicon} || $line eq "" ); + + #TODO define icon inline per frame. + # Must be compatible with FHEM-msg command + } + + push @{ $notification{model}{frames} }, + ( + { + icon => $ico, + text => $line, + index => $index++, + } + ); + } + } readingsBulkUpdate( $hash, "lastMessage", $values{message} ); }