From 19f7056f571caf3346cb009d5355e4b81028afd7 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Sat, 12 Jan 2019 08:18:52 +0100 Subject: [PATCH] fix weblink bug by hourly forcast --- 59_Weather.pm | 24 ++++++++++++++---------- DarkSkyAPI.pm | 13 ++++++++++--- OpenWeatherMapAPI.pm | 13 ++++++++++--- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/59_Weather.pm b/59_Weather.pm index bfeadf2..ad26e02 100755 --- a/59_Weather.pm +++ b/59_Weather.pm @@ -680,6 +680,7 @@ sub WeatherAsHtmlV($;$) return "$d is not a Weather instance
" if(!$defs{$d} || $defs{$d}->{TYPE} ne "Weather"); + my $h = $defs{$d}; my $width= int(ICONSCALE*ICONWIDTH); my $ret = ''; @@ -690,13 +691,14 @@ sub WeatherAsHtmlV($;$) ReadingsVal($d, "temp_c", ""), ReadingsVal($d, "humidity", ""), ReadingsVal($d, "wind_condition", "")); + my $fc = ( (defined($h->{READINGS}->{fc1_day_of_week}) and $h->{READINGS}->{fc1_day_of_week}) ? 'fc' : 'hfc' ); for(my $i=1; $i<$items; $i++) { $ret .= sprintf('', $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", "")); + 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", "")); } $ret .= "
%s%s: %s
min %s°C max %s°C
"; @@ -718,6 +720,7 @@ sub WeatherAsHtmlH($;$) return "$d is not a Weather instance
" if(!$defs{$d} || $defs{$d}->{TYPE} ne "Weather"); + my $h = $defs{$d}; my $width= int(ICONSCALE*ICONWIDTH); @@ -725,33 +728,34 @@ sub WeatherAsHtmlH($;$) my $format= '
%s
%s
%s°C %s%%
%s
'; my $ret = ''; - + my $fc = ( (defined($h->{READINGS}->{fc1_day_of_week}) and $h->{READINGS}->{fc1_day_of_week}) ? 'fc' : 'hfc' ); + # icons $ret .= sprintf('', $width, WeatherIconIMGTag(ReadingsVal($d, "icon", ""))); for(my $i=1; $i<$items; $i++) { - $ret .= sprintf('', $width, WeatherIconIMGTag(ReadingsVal($d, "fc${i}_icon", ""))); + $ret .= sprintf('', $width, WeatherIconIMGTag(ReadingsVal($d, "${fc}${i}_icon", ""))); } $ret .= ''; # condition $ret .= sprintf('', ReadingsVal($d, "condition", "")); for(my $i=1; $i<$items; $i++) { - $ret .= sprintf('', ReadingsVal($d, "fc${i}_day_of_week", ""), - ReadingsVal($d, "fc${i}_condition", "")); + $ret .= sprintf('', ReadingsVal($d, "${fc}${i}_day_of_week", ""), + ReadingsVal($d, "${fc}${i}_condition", "")); } $ret .= ''; # temp/hum | min $ret .= sprintf('', ReadingsVal($d, "temp_c", ""), ReadingsVal($d, "humidity", "")); for(my $i=1; $i<$items; $i++) { - $ret .= sprintf('', ReadingsVal($d, "fc${i}_low_c", "")); + $ret .= sprintf('', ReadingsVal($d, "${fc}${i}_low_c", "")); } $ret .= ''; # wind | max $ret .= sprintf('', ReadingsVal($d, "wind_condition", "")); for(my $i=1; $i<$items; $i++) { - $ret .= sprintf('', ReadingsVal($d, "fc${i}_high_c", "")); + $ret .= sprintf('', ReadingsVal($d, "${fc}${i}_high_c", "")); } $ret .= "
%s%s%s
%s%s: %s%s: %s
%s°C %s%%min %s°Cmin %s°C
%smax %s°Cmax %s°C
"; diff --git a/DarkSkyAPI.pm b/DarkSkyAPI.pm index 8a133e7..a25f2ab 100644 --- a/DarkSkyAPI.pm +++ b/DarkSkyAPI.pm @@ -74,9 +74,11 @@ sub new { ), cachemaxage => ( ( defined( $argsRef->{apioptions} ) and $argsRef->{apioptions} ) - ? ( ( split( ':', $argsRef->{apioptions} ) )[0] eq 'cachemaxage' + ? ( + ( split( ':', $argsRef->{apioptions} ) )[0] eq 'cachemaxage' ? ( split( ':', $argsRef->{apioptions} ) )[1] - : 900 ) + : 900 + ) : 900 ), lang => $argsRef->{language}, @@ -273,7 +275,12 @@ sub _ProcessingRetrieveData($$) { $data->{daily}->{data}->[$i]->{'time'} ) ), - 'day_of_week' => strftime("%a",localtime($data->{daily}->{data}->[$i]->{'time'})), + 'day_of_week' => strftime( + "%a", + localtime( + $data->{daily}->{data}->[$i]->{'time'} + ) + ), 'low_c' => int( sprintf( "%.1f", $data->{daily}->{data}->[$i] diff --git a/OpenWeatherMapAPI.pm b/OpenWeatherMapAPI.pm index 67e43d9..7dd3371 100644 --- a/OpenWeatherMapAPI.pm +++ b/OpenWeatherMapAPI.pm @@ -122,9 +122,11 @@ sub new { ), cachemaxage => ( ( defined( $argsRef->{apioptions} ) and $argsRef->{apioptions} ) - ? ( ( split( ':', $argsRef->{apioptions} ) )[0] eq 'cachemaxage' + ? ( + ( split( ':', $argsRef->{apioptions} ) )[0] eq 'cachemaxage' ? ( split( ':', $argsRef->{apioptions} ) )[1] - : 900 ) + : 900 + ) : 900 ), lang => $argsRef->{language}, @@ -340,7 +342,12 @@ sub _ProcessingRetrieveData($$) { ( $data->{list}->[$i]->{dt} ) - 3600 ) ), - 'day_of_week' => strftime("%a",localtime(( $data->{list}->[$i]->{dt} ) - 3600)), + 'day_of_week' => strftime( + "%a", + localtime( + ( $data->{list}->[$i]->{dt} ) - 3600 + ) + ), 'temperature' => int( sprintf( "%.1f",