From a94030f9f4603230298d7292e3dfa685119505d2 Mon Sep 17 00:00:00 2001 From: Lippie81 <46738685+Lippie81@users.noreply.github.com> Date: Tue, 5 Mar 2019 20:24:24 +0100 Subject: [PATCH 1/7] Update WeatherAsHtml - alle WeatherAsHtml-functionen auf $d, $items, $i gleichgestellt - Abfrage in WeatherAsHtmlH, ob *fc(i)_low_c vorhanden, wenn nicht Verwendung von *fc(i)_temperature - Erweiterung der Beispiels um Anzahl und daily/hourly-Angabe --- 59_Weather.pm | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/59_Weather.pm b/59_Weather.pm index c62d721..fccecab 100755 --- a/59_Weather.pm +++ b/59_Weather.pm @@ -764,10 +764,10 @@ sub WeatherAsHtmlV($;$$) { return $ret; } -sub WeatherAsHtml($;$) { - my ( $d, $i ) = @_; +sub WeatherAsHtml($;$$) { + my ( $d, $items, $i ) = @_; - WeatherAsHtmlV( $d, $i ); + WeatherAsHtmlV( $d, $items, $i ); } sub WeatherAsHtmlH($;$$) { @@ -832,8 +832,13 @@ sub WeatherAsHtmlH($;$$) { ReadingsVal( $d, "humidity", "" ) ); for ( my $i = 1 ; $i < $items ; $i++ ) { - $ret .= sprintf( 'min %s°C', - ReadingsVal( $d, "${fc}${i}_low_c", " - " ) ); + if(defined($h->{READINGS}->{"${fc}${i}_low_c"}) and $h->{READINGS}->{"${fc}${i}_low_c"}){ + $ret .= sprintf( 'min %s°C', + ReadingsVal( $d, "${fc}${i}_low_c", " - " ) ); + }else{ + $ret .= sprintf( ' %s°C', + ReadingsVal( $d, "${fc}${i}_temperature", " - " ) ); + } } $ret .= ''; @@ -841,22 +846,24 @@ sub WeatherAsHtmlH($;$$) { $ret .= sprintf( '%s', ReadingsVal( $d, "wind_condition", "" ) ); for ( my $i = 1 ; $i < $items ; $i++ ) { - $ret .= sprintf( 'max %s°C', - ReadingsVal( $d, "${fc}${i}_high_c", " - " ) ); + if(defined($h->{READINGS}->{"${fc}${i}_high_c"}) and $h->{READINGS}->{"${fc}${i}_high_c"}){ + $ret .= sprintf( 'max %s°C', + ReadingsVal( $d, "${fc}${i}_high_c", " - " ) ); + } } $ret .= ""; return $ret; } -sub WeatherAsHtmlD($;$) { - my ( $d, $i ) = @_; +sub WeatherAsHtmlD($;$$) { + my ( $d, $items, $i ) = @_; if ($FW_ss) { - WeatherAsHtmlV( $d, $i ); + WeatherAsHtmlV( $d, $items, $i ); } else { - WeatherAsHtmlH( $d, $i ); + WeatherAsHtmlH( $d, $items, $i ); } } @@ -957,7 +964,7 @@ sub WeatherAsHtmlD($;$) { to limit the numer of icons to display.

Example:
-      define MyWeatherWeblink weblink htmlCode { WeatherAsHtmlH("MyWeather") }
+      define MyWeatherWeblink weblink htmlCode { WeatherAsHtmlH("MyWeather",10,"h") }
     
@@ -1130,7 +1137,7 @@ sub WeatherAsHtmlD($;$) { Wird der dritte Parameter verwendet muss auch der zweite Parameter für die Anzahl der darzustellenden Icons gesetzt werden.

Beispiel:
-      define MyWeatherWeblink weblink htmlCode { WeatherAsHtmlH("MyWeather") }
+      define MyWeatherWeblink weblink htmlCode { WeatherAsHtmlH("MyWeather",10,"h") }
     
From 31256f1a17b71c8b4ebf928fe1e63522dc636949 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Tue, 5 Mar 2019 21:01:23 +0100 Subject: [PATCH 2/7] little change --- 59_Weather.pm | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/59_Weather.pm b/59_Weather.pm index fccecab..e9ce097 100755 --- a/59_Weather.pm +++ b/59_Weather.pm @@ -832,25 +832,28 @@ sub WeatherAsHtmlH($;$$) { ReadingsVal( $d, "humidity", "" ) ); for ( my $i = 1 ; $i < $items ; $i++ ) { - if(defined($h->{READINGS}->{"${fc}${i}_low_c"}) and $h->{READINGS}->{"${fc}${i}_low_c"}){ + if(defined($h->{READINGS}->{"${fc}${i}_low_c"}) and $h->{READINGS}->{"${fc}${i}_low_c"}){ $ret .= sprintf( 'min %s°C', ReadingsVal( $d, "${fc}${i}_low_c", " - " ) ); - }else{ - $ret .= sprintf( ' %s°C', - ReadingsVal( $d, "${fc}${i}_temperature", " - " ) ); - } + } + else { + $ret .= sprintf( ' %s°C', + ReadingsVal( $d, "${fc}${i}_temperature", " - " ) ); + } } + $ret .= ''; # wind | max $ret .= sprintf( '%s', ReadingsVal( $d, "wind_condition", "" ) ); for ( my $i = 1 ; $i < $items ; $i++ ) { - if(defined($h->{READINGS}->{"${fc}${i}_high_c"}) and $h->{READINGS}->{"${fc}${i}_high_c"}){ + if(defined($h->{READINGS}->{"${fc}${i}_high_c"}) and $h->{READINGS}->{"${fc}${i}_high_c"}){ $ret .= sprintf( 'max %s°C', - ReadingsVal( $d, "${fc}${i}_high_c", " - " ) ); + ReadingsVal( $d, "${fc}${i}_high_c", " - " ) ); } } + $ret .= ""; return $ret; From ff1b906e33e0536cb1774547ed8deef45b31c1f0 Mon Sep 17 00:00:00 2001 From: Lippie81 <46738685+Lippie81@users.noreply.github.com> Date: Thu, 7 Mar 2019 22:34:49 +0100 Subject: [PATCH 3/7] Update 59_Weather.pm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Aktualisierung des Änderungsvorschlags wie besprochen: - WeatherAsHtml() haben jetzt alle die gleiche Schnittstelle ($d, $f , $items)und sind damit abwärtskompatibel entsprechend Doku (ebenfalls angepasst) Zur Absicherung der optionalen Parameter in WeatherAsHtml(): Filter auf die erlaubten Zeichen und setzen eines defaultwertes, falls der Parameter leer ist. Eine Abfrage auf defined() ist nicht notwendig, habe alle möglichen Eingabekombinationen abgeprüft. In WeatherAsHtmlH($;$$) wird, wie vereinbart, _low_c und _high_c nur angezeigt, wenn die Readings vorhanden sind, ansonsten wird _temperature verwendet. Gleiches habe ich in WeatherAsHtmlV($;$$) angepasst. Die Änderungen laufen bei mir mit DarkSkyAPI und OpenWeatherMapAPI einwandfrei. Aussehen habe ich ebenfalls gecheckt. Beste Grüße Lippie --- 59_Weather.pm | 73 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 22 deletions(-) diff --git a/59_Weather.pm b/59_Weather.pm index e9ce097..8827f20 100755 --- a/59_Weather.pm +++ b/59_Weather.pm @@ -709,10 +709,13 @@ sub WeatherIconIMGTag($) { ##################################### sub WeatherAsHtmlV($;$$) { - my ( $d, $items, $f ) = @_; + my ( $d, $f, $items ) = @_; - $d = "" if ( !$d ); - $items = 6 if ( !$items ); + $f =~ tr/dh/./cd; + $f = "h" if ( !$f || length($f) > 1); + $items =~ tr/0-9/./cd; + $items = 6 if ( !$items ); + return "$d is not a Weather instance
" if ( !$defs{$d} || $defs{$d}->{TYPE} ne "Weather" ); @@ -749,15 +752,28 @@ sub WeatherAsHtmlV($;$$) { ); for ( my $i = 1 ; $i < $items ; $i++ ) { - $ret .= sprintf( -'%s%s: %s
min %s°C max %s°C', - $width, - WeatherIconIMGTag( ReadingsVal( $d, "${fc}${i}_icon", "" ) ), - ReadingsVal( $d, "${fc}${i}_day_of_week", "" ), - ReadingsVal( $d, "${fc}${i}_condition", "" ), - ReadingsVal( $d, "${fc}${i}_low_c", " - " ), - ReadingsVal( $d, "${fc}${i}_high_c", " - " ) - ); + if(defined($h->{READINGS}->{"${fc}${i}_low_c"}) and $h->{READINGS}->{"${fc}${i}_low_c"}){ + $ret .= sprintf( + '%s%s: %s
min %s°C max %s°C
%s', + $width, + WeatherIconIMGTag( ReadingsVal( $d, "${fc}${i}_icon", "" ) ), + ReadingsVal( $d, "${fc}${i}_day_of_week", "" ),
%s + ReadingsVal( $d, "${fc}${i}_condition", "" ), + ReadingsVal( $d, "${fc}${i}_low_c", " - " ), + ReadingsVal( $d, "${fc}${i}_high_c", " - " ) + ReadingsVal( $d, "${fc}${i}_wind_condition", " - " ) + ); + }else{ + $ret .= sprintf( + '%s%s: %s
%s°C
%s', + $width, + WeatherIconIMGTag( ReadingsVal( $d, "${fc}${i}_icon", "" ) ), + ReadingsVal( $d, "${fc}${i}_day_of_week", "" ), + ReadingsVal( $d, "${fc}${i}_condition", "" ), + ReadingsVal( $d, "${fc}${i}_temperature", " - " ) + ReadingsVal( $d, "${fc}${i}_wind_condition", " - " ) + ); + } } $ret .= ""; @@ -765,16 +781,24 @@ sub WeatherAsHtmlV($;$$) { } sub WeatherAsHtml($;$$) { - my ( $d, $items, $i ) = @_; + my ( $d, $f, $items ) = @_; - WeatherAsHtmlV( $d, $items, $i ); + $f =~ tr/dh/./cd; + $f = "h" if ( !$f || length($f) > 1); + $items =~ tr/0-9/./cd; + $items = 6 if ( !$items ); + + WeatherAsHtmlV( $d, $f, $items ); } sub WeatherAsHtmlH($;$$) { - my ( $d, $items, $f ) = @_; + my ( $d, $f, $items ) = @_; - $d = "" if ( !$d ); - $items = 6 if ( !$items ); + $f =~ tr/dh/./cd; + $f = "h" if ( !$f || length($f) > 1); + $items =~ tr/0-9/./cd; + $items = 6 if ( !$items ); + return "$d is not a Weather instance
" if ( !$defs{$d} || $defs{$d}->{TYPE} ne "Weather" ); @@ -860,13 +884,18 @@ sub WeatherAsHtmlH($;$$) { } sub WeatherAsHtmlD($;$$) { - my ( $d, $items, $i ) = @_; + my ( $d, $f, $items ) = @_; + + $f =~ tr/dh/./cd; + $f = "h" if ( !$f || length($f) > 1); + $items =~ tr/0-9/./cd; + $items = 6 if ( !$items ); if ($FW_ss) { - WeatherAsHtmlV( $d, $items, $i ); + WeatherAsHtmlV( $d, $f , $items); } else { - WeatherAsHtmlH( $d, $items, $i ); + WeatherAsHtmlH( $d, $f , $items); } } @@ -967,7 +996,7 @@ sub WeatherAsHtmlD($;$$) { to limit the numer of icons to display.

Example:
-      define MyWeatherWeblink weblink htmlCode { WeatherAsHtmlH("MyWeather",10,"h") }
+      define MyWeatherWeblink weblink htmlCode { WeatherAsHtmlH("MyWeather","h",10) }
     
@@ -1140,7 +1169,7 @@ sub WeatherAsHtmlD($;$$) { Wird der dritte Parameter verwendet muss auch der zweite Parameter für die Anzahl der darzustellenden Icons gesetzt werden.

Beispiel:
-      define MyWeatherWeblink weblink htmlCode { WeatherAsHtmlH("MyWeather",10,"h") }
+      define MyWeatherWeblink weblink htmlCode { WeatherAsHtmlH("MyWeather","h",10) }
     
From 13941827d6a392a4ed4e7566108e16f42cdfa9a1 Mon Sep 17 00:00:00 2001 From: Lippie81 <46738685+Lippie81@users.noreply.github.com> Date: Tue, 12 Mar 2019 06:46:11 +0100 Subject: [PATCH 4/7] Update 59_Weather.pm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bugfix: 761: ReadingsVal( $d, "${fc}${i}_day_of_week", "" ),
%s =>Das
%s gehört da nicht hin. In Zeile 763 und 773 fehlt ein Komma als Zeilenabschluss. --- 59_Weather.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/59_Weather.pm b/59_Weather.pm index 8827f20..f9a8457 100755 --- a/59_Weather.pm +++ b/59_Weather.pm @@ -757,10 +757,10 @@ sub WeatherAsHtmlV($;$$) { '%s%s: %s
min %s°C max %s°C
%s', $width, WeatherIconIMGTag( ReadingsVal( $d, "${fc}${i}_icon", "" ) ), - ReadingsVal( $d, "${fc}${i}_day_of_week", "" ),
%s + ReadingsVal( $d, "${fc}${i}_day_of_week", "" ), ReadingsVal( $d, "${fc}${i}_condition", "" ), ReadingsVal( $d, "${fc}${i}_low_c", " - " ), - ReadingsVal( $d, "${fc}${i}_high_c", " - " ) + ReadingsVal( $d, "${fc}${i}_high_c", " - " ), ReadingsVal( $d, "${fc}${i}_wind_condition", " - " ) ); }else{ @@ -770,7 +770,7 @@ sub WeatherAsHtmlV($;$$) { WeatherIconIMGTag( ReadingsVal( $d, "${fc}${i}_icon", "" ) ), ReadingsVal( $d, "${fc}${i}_day_of_week", "" ), ReadingsVal( $d, "${fc}${i}_condition", "" ), - ReadingsVal( $d, "${fc}${i}_temperature", " - " ) + ReadingsVal( $d, "${fc}${i}_temperature", " - " ), ReadingsVal( $d, "${fc}${i}_wind_condition", " - " ) ); } From 1c2d2939316f6ad7b505df6cf5d09b95c9cc1300 Mon Sep 17 00:00:00 2001 From: Lippie81 <46738685+Lippie81@users.noreply.github.com> Date: Tue, 12 Mar 2019 21:07:58 +0100 Subject: [PATCH 5/7] Update 59_Weather.pm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Paramater 2 und 3 werden automatisch dem zugehörigen internen Parameter Anzahl oder daily/hourly zugeordnet. Damit ist die Reihenfolge beim Aufruf frei wählbar und beide Parameter können beim Aufruf beliebig weggelassen werden. --- 59_Weather.pm | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/59_Weather.pm b/59_Weather.pm index f9a8457..1de02f9 100755 --- a/59_Weather.pm +++ b/59_Weather.pm @@ -709,7 +709,11 @@ sub WeatherIconIMGTag($) { ##################################### sub WeatherAsHtmlV($;$$) { - my ( $d, $f, $items ) = @_; + my ( $d, $op1, $op2 ) = @_; + my $items = $op2; + my $f = $op1; + if($op1 =~ /[0-9]/g){ $items = $op1; } + if($op2 =~ /[dh]/g){ $f = $op2; } $f =~ tr/dh/./cd; $f = "h" if ( !$f || length($f) > 1); @@ -781,7 +785,11 @@ sub WeatherAsHtmlV($;$$) { } sub WeatherAsHtml($;$$) { - my ( $d, $f, $items ) = @_; + my ( $d, $op1, $op2 ) = @_; + my $items = $op2; + my $f = $op1; + if($op1 =~ /[0-9]/g){ $items = $op1; } + if($op2 =~ /[dh]/g){ $f = $op2; } $f =~ tr/dh/./cd; $f = "h" if ( !$f || length($f) > 1); @@ -792,12 +800,11 @@ sub WeatherAsHtml($;$$) { } sub WeatherAsHtmlH($;$$) { - my ( $d, $f, $items ) = @_; - - $f =~ tr/dh/./cd; - $f = "h" if ( !$f || length($f) > 1); - $items =~ tr/0-9/./cd; - $items = 6 if ( !$items ); + my ( $d, $op1, $op2 ) = @_; + my $items = $op2; + my $f = $op1; + if($op1 =~ /[0-9]/g){ $items = $op1; } + if($op2 =~ /[dh]/g){ $f = $op2; } return "$d is not a Weather instance
" if ( !$defs{$d} || $defs{$d}->{TYPE} ne "Weather" ); @@ -884,7 +891,11 @@ sub WeatherAsHtmlH($;$$) { } sub WeatherAsHtmlD($;$$) { - my ( $d, $f, $items ) = @_; + my ( $d, $op1, $op2 ) = @_; + my $items = $op2; + my $f = $op1; + if($op1 =~ /[0-9]/g){ $items = $op1; } + if($op2 =~ /[dh]/g){ $f = $op2; } $f =~ tr/dh/./cd; $f = "h" if ( !$f || length($f) > 1); From 7e930295c8d5b8fa95aef8011aa1c645f1e6beaa Mon Sep 17 00:00:00 2001 From: Lippie81 <46738685+Lippie81@users.noreply.github.com> Date: Wed, 13 Mar 2019 07:00:45 +0100 Subject: [PATCH 6/7] Update 59_Weather.pm Bugfix zum letzten merge meines patches: in sub WeatherAsHtmlH($;$$) fehlte: $f =~ tr/dh/./cd; $f = "h" if ( !$f || length($f) > 1); $items =~ tr/0-9/./cd; $items = 6 if ( !$items ); --- 59_Weather.pm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/59_Weather.pm b/59_Weather.pm index 1de02f9..8602204 100755 --- a/59_Weather.pm +++ b/59_Weather.pm @@ -806,6 +806,11 @@ sub WeatherAsHtmlH($;$$) { if($op1 =~ /[0-9]/g){ $items = $op1; } if($op2 =~ /[dh]/g){ $f = $op2; } + $f =~ tr/dh/./cd; + $f = "h" if ( !$f || length($f) > 1); + $items =~ tr/0-9/./cd; + $items = 6 if ( !$items ); + return "$d is not a Weather instance
" if ( !$defs{$d} || $defs{$d}->{TYPE} ne "Weather" ); From c4e6100ad2bd1aa1a05da93ee3f75652d9e161d5 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Thu, 14 Mar 2019 08:43:14 +0100 Subject: [PATCH 7/7] add contributors --- 59_Weather.pm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/59_Weather.pm b/59_Weather.pm index 8602204..e167789 100755 --- a/59_Weather.pm +++ b/59_Weather.pm @@ -5,6 +5,11 @@ # Copyright by Dr. Boris Neubert # e-mail: omega at online dot de # +# Contributors: +# - Marko Oldenburg (CoolTux) +# - Lippie +# +# # This file is part of fhem. # # Fhem is free software: you can redistribute it and/or modify