testing #29

Merged
marko merged 73 commits from testing into main 2023-01-07 12:49:01 +00:00
2 changed files with 210 additions and 215 deletions
Showing only changes of commit 8ec9dae902 - Show all commits

View File

@ -31,14 +31,13 @@ package main;
use strict; use strict;
use warnings; use warnings;
use Time::HiRes qw(gettimeofday); use Time::HiRes qw(gettimeofday);
use experimental qw /switch/; use experimental qw /switch/;
use Readonly; use Readonly;
use FHEM::Meta; use FHEM::Meta;
use vars qw($FW_ss); use vars qw($FW_ss);
# use Data::Dumper; # for Debug only # use Data::Dumper; # for Debug only
my %pressure_trend_txt_en = ( 0 => "steady", 1 => "rising", 2 => "falling" ); my %pressure_trend_txt_en = ( 0 => "steady", 1 => "rising", 2 => "falling" );
@ -277,19 +276,19 @@ sub Weather_DebugCodes {
sub Weather_Initialize { sub Weather_Initialize {
my $hash = shift; my $hash = shift;
$hash->{DefFn} = \&Weather_Define; $hash->{DefFn} = \&Weather_Define;
$hash->{UndefFn} = \&Weather_Undef; $hash->{UndefFn} = \&Weather_Undef;
$hash->{GetFn} = \&Weather_Get; $hash->{GetFn} = \&Weather_Get;
$hash->{SetFn} = \&Weather_Set; $hash->{SetFn} = \&Weather_Set;
$hash->{AttrFn} = \&Weather_Attr; $hash->{AttrFn} = \&Weather_Attr;
$hash->{AttrList} = $hash->{AttrList} =
'disable:0,1 ' 'disable:0,1 '
. 'forecast:multiple-strict,hourly,daily ' . 'forecast:multiple-strict,hourly,daily '
. 'forecastLimit ' . 'forecastLimit '
. 'alerts:0,1 ' . 'alerts:0,1 '
. $readingFnAttributes; . $readingFnAttributes;
$hash->{NotifyFn} = \&Weather_Notify; $hash->{NotifyFn} = \&Weather_Notify;
$hash->{parseParams} = 1; $hash->{parseParams} = 1;
return FHEM::Meta::InitMod( __FILE__, $hash ); return FHEM::Meta::InitMod( __FILE__, $hash );
} }
@ -353,11 +352,10 @@ sub Weather_WriteReadings {
my $hash = shift; my $hash = shift;
my $dataRef = shift; my $dataRef = shift;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $hourly = ( AttrVal( $name, 'forecast', '' ) =~ m{hourly}xms ? 1: 0 ); my $hourly = ( AttrVal( $name, 'forecast', '' ) =~ m{hourly}xms ? 1 : 0 );
my $daily = ( AttrVal( $name, 'forecast', '' ) =~ m{daily}xms ? 1 : 0 ); my $daily = ( AttrVal( $name, 'forecast', '' ) =~ m{daily}xms ? 1 : 0 );
my $alerts = ( AttrVal( $name, 'forecast', '' ) =~ m{alerts}xms ? 1 : 0 ); my $alerts = ( AttrVal( $name, 'forecast', '' ) =~ m{alerts}xms ? 1 : 0 );
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
@ -400,17 +398,15 @@ sub Weather_WriteReadings {
### forecast ### forecast
if ( ref( $dataRef->{forecast} ) eq 'HASH' if ( ref( $dataRef->{forecast} ) eq 'HASH'
&& ($hourly || $daily) ) && ( $hourly || $daily ) )
{ {
## hourly ## hourly
if ( if ( defined( $dataRef->{forecast}->{hourly} )
defined( $dataRef->{forecast}->{hourly} )
&& ref( $dataRef->{forecast}->{hourly} ) eq 'ARRAY' && ref( $dataRef->{forecast}->{hourly} ) eq 'ARRAY'
&& scalar( @{ $dataRef->{forecast}->{hourly} } ) > 0 && scalar( @{ $dataRef->{forecast}->{hourly} } ) > 0
&& $hourly && $hourly )
)
{ {
my $i = 0; my $i = 0;
my $limit = AttrVal( $name, 'forecastLimit', -1 ); my $limit = AttrVal( $name, 'forecastLimit', -1 );
foreach my $fc ( @{ $dataRef->{forecast}->{hourly} } ) { foreach my $fc ( @{ $dataRef->{forecast}->{hourly} } ) {
$i++; $i++;
@ -429,7 +425,7 @@ sub Weather_WriteReadings {
if ( if (
defined( defined(
$dataRef->{forecast}->{hourly}[ $i - 1 ]{wind_direction} $dataRef->{forecast}->{hourly}[ $i - 1 ]{wind_direction}
) )
&& $dataRef->{forecast}->{hourly}[ $i - 1 ]{wind_direction} && $dataRef->{forecast}->{hourly}[ $i - 1 ]{wind_direction}
&& defined( && defined(
@ -458,14 +454,12 @@ sub Weather_WriteReadings {
} }
## daily ## daily
if ( if ( defined( $dataRef->{forecast}->{daily} )
defined( $dataRef->{forecast}->{daily} )
&& ref( $dataRef->{forecast}->{daily} ) eq 'ARRAY' && ref( $dataRef->{forecast}->{daily} ) eq 'ARRAY'
&& scalar( @{ $dataRef->{forecast}->{daily} } ) > 0 && scalar( @{ $dataRef->{forecast}->{daily} } ) > 0
&& $daily && $daily )
)
{ {
my $i = 0; my $i = 0;
my $limit = AttrVal( $name, 'forecastLimit', -1 ); my $limit = AttrVal( $name, 'forecastLimit', -1 );
foreach my $fc ( @{ $dataRef->{forecast}->{daily} } ) { foreach my $fc ( @{ $dataRef->{forecast}->{daily} } ) {
$i++; $i++;
@ -484,7 +478,7 @@ sub Weather_WriteReadings {
if ( if (
defined( defined(
$dataRef->{forecast}->{daily}[ $i - 1 ]{wind_direction} $dataRef->{forecast}->{daily}[ $i - 1 ]{wind_direction}
) )
&& $dataRef->{forecast}->{daily}[ $i - 1 ]{wind_direction} && $dataRef->{forecast}->{daily}[ $i - 1 ]{wind_direction}
&& defined( && defined(
@ -513,9 +507,9 @@ sub Weather_WriteReadings {
} }
if ( ref( $dataRef->{alerts} ) eq 'HASH' if ( ref( $dataRef->{alerts} ) eq 'HASH'
&& $alerts ) && $alerts )
{ {
while ( my ( $r, $v ) = each %{ $dataRef->{alerts} } ) { while ( my ( $r, $v ) = each %{ $dataRef->{alerts} } ) {
readingsBulkUpdate( $hash, $r, $v ) readingsBulkUpdate( $hash, $r, $v )
if ( ref( $dataRef->{$r} ) ne 'HASH' if ( ref( $dataRef->{$r} ) ne 'HASH'
&& ref( $dataRef->{$r} ) ne 'ARRAY' ); && ref( $dataRef->{$r} ) ne 'ARRAY' );
@ -568,7 +562,7 @@ sub Weather_Get {
my $hash = shift // return; my $hash = shift // return;
my $aRef = shift // return; my $aRef = shift // return;
my $name = shift @$aRef // return; my $name = shift @$aRef // return;
my $reading = shift @$aRef // return; my $reading = shift @$aRef // return;
my $value; my $value;
@ -597,37 +591,36 @@ sub Weather_Set {
// return qq{"set $name" needs at least one argument}; // return qq{"set $name" needs at least one argument};
# usage check # usage check
if ( scalar(@{$aRef}) == 0 if ( scalar( @{$aRef} ) == 0
&& $cmd eq 'update' ) && $cmd eq 'update' )
{ {
Weather_DisarmTimer($hash); Weather_DisarmTimer($hash);
Weather_GetUpdate($hash); Weather_GetUpdate($hash);
return; return;
} }
elsif ( scalar(@{$aRef}) == 1 elsif ( scalar( @{$aRef} ) == 1
&& $cmd eq "newLocation" ) && $cmd eq "newLocation" )
{ {
if ( $hash->{API} eq 'DarkSkyAPI' if ( $hash->{API} eq 'DarkSkyAPI'
|| $hash->{API} eq 'OpenWeatherMapAPI' || $hash->{API} eq 'OpenWeatherMapAPI'
|| $hash->{API} eq 'wundergroundAPI' || $hash->{API} eq 'wundergroundAPI' )
)
{ {
my ($lat,$long); my ( $lat, $long );
($lat,$long) = split(',',$aRef->[0]) ( $lat, $long ) = split( ',', $aRef->[0] )
if ( defined($aRef->[0]) && $aRef->[0] ); if ( defined( $aRef->[0] ) && $aRef->[0] );
($lat,$long) = split(',',$hash->{fhem}->{LOCATION}) ( $lat, $long ) = split( ',', $hash->{fhem}->{LOCATION} )
unless ( defined($lat) unless ( defined($lat)
&& defined($long) && defined($long)
&& $lat =~ m{(-?\d+(\.\d+)?)}xms && $lat =~ m{(-?\d+(\.\d+)?)}xms
&& $long =~ m{(-?\d+(\.\d+)?)}xms ); && $long =~ m{(-?\d+(\.\d+)?)}xms );
$hash->{fhem}->{api}->setLocation($lat,$long); $hash->{fhem}->{api}->setLocation( $lat, $long );
Weather_DisarmTimer($hash); Weather_DisarmTimer($hash);
Weather_GetUpdate($hash); Weather_GetUpdate($hash);
return; return;
} }
else { return 'this API is not ' . $aRef->[0] .' supported' } else { return 'this API is not ' . $aRef->[0] . ' supported' }
} }
else { else {
return "Unknown argument $cmd, choose one of update:noArg newLocation"; return "Unknown argument $cmd, choose one of update:noArg newLocation";
@ -636,8 +629,8 @@ sub Weather_Set {
################################### ###################################
sub Weather_RearmTimer { sub Weather_RearmTimer {
my $hash = shift; my $hash = shift;
my $t = shift; my $t = shift;
Log3( $hash, 4, "Weather $hash->{NAME}: Rearm new Timer" ); Log3( $hash, 4, "Weather $hash->{NAME}: Rearm new Timer" );
InternalTimer( $t, "Weather_GetUpdate", $hash, 0 ); InternalTimer( $t, "Weather_GetUpdate", $hash, 0 );
@ -654,11 +647,11 @@ sub Weather_DisarmTimer {
} }
sub Weather_Notify { sub Weather_Notify {
my $hash = shift; my $hash = shift;
my $dev = shift; my $dev = shift;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $type = $hash->{TYPE}; my $type = $hash->{TYPE};
return if ( $dev->{NAME} ne "global" ); return if ( $dev->{NAME} ne "global" );
return if ( !grep { /^INITIALIZED|REREADCFG$/ } @{ $dev->{CHANGED} } ); return if ( !grep { /^INITIALIZED|REREADCFG$/ } @{ $dev->{CHANGED} } );
@ -685,10 +678,9 @@ sub Weather_Notify {
##################################### #####################################
sub Weather_Define { sub Weather_Define {
my $hash = shift // return; my $hash = shift // return;
my $aRef = shift // return; my $aRef = shift // return;
my $hRef = shift // undef; my $hRef = shift // undef;
return $@ unless ( FHEM::Meta::SetInternals($hash) ); return $@ unless ( FHEM::Meta::SetInternals($hash) );
use version 0.60; our $VERSION = FHEM::Meta::Get( $hash, 'version' ); use version 0.60; our $VERSION = FHEM::Meta::Get( $hash, 'version' );
@ -700,11 +692,11 @@ sub Weather_Define {
return $usage unless ( scalar @{$aRef} == 2 ); return $usage unless ( scalar @{$aRef} == 2 );
my $name = $aRef->[0]; my $name = $aRef->[0];
my $location = $hRef->{location} // undef; my $location = $hRef->{location} // undef;
my $apikey = $hRef->{apikey} // undef; my $apikey = $hRef->{apikey} // undef;
my $lang = $hRef->{lang} // undef; my $lang = $hRef->{lang} // undef;
my $interval = $hRef->{interval} // 3600; my $interval = $hRef->{interval} // 3600;
my $API = $hRef->{API} // "DarkSkyAPI,cachemaxage:600"; my $API = $hRef->{API} // "DarkSkyAPI,cachemaxage:600";
# evaluate API options # evaluate API options
my ( $api, $apioptions ) = split( ',', $API, 2 ); my ( $api, $apioptions ) = split( ',', $API, 2 );
@ -726,15 +718,15 @@ sub Weather_Define {
? $lang ? $lang
: lc( AttrVal( 'global', 'language', 'de' ) ) : lc( AttrVal( 'global', 'language', 'de' ) )
); );
$hash->{API} = $api; $hash->{API} = $api;
$hash->{MODEL} = $api; $hash->{MODEL} = $api;
$hash->{APIKEY} = $apikey; $hash->{APIKEY} = $apikey;
$hash->{APIOPTIONS} = $apioptions; $hash->{APIOPTIONS} = $apioptions;
$hash->{VERSION} = version->parse($VERSION)->normal; $hash->{VERSION} = version->parse($VERSION)->normal;
$hash->{fhem}->{allowCache} = 1; $hash->{fhem}->{allowCache} = 1;
readingsSingleUpdate($hash,'current_date_time',TimeNow(),0); readingsSingleUpdate( $hash, 'current_date_time', TimeNow(), 0 );
readingsSingleUpdate($hash,'current_date_time','none',0); readingsSingleUpdate( $hash, 'current_date_time', 'none', 0 );
readingsSingleUpdate( $hash, 'state', 'Initialized', 1 ); readingsSingleUpdate( $hash, 'state', 'Initialized', 1 );
Weather_LanguageInitialize( $hash->{LANG} ); Weather_LanguageInitialize( $hash->{LANG} );
@ -747,8 +739,8 @@ sub Weather_Define {
location => $hash->{fhem}->{LOCATION}, location => $hash->{fhem}->{LOCATION},
apioptions => $hash->{APIOPTIONS}, apioptions => $hash->{APIOPTIONS},
language => $hash->{LANG}, language => $hash->{LANG},
forecast => AttrVal($name,'forecast',''), forecast => AttrVal( $name, 'forecast', '' ),
alerts => AttrVal($name,'alerts',0) alerts => AttrVal( $name, 'alerts', 0 )
} }
); );
@ -760,8 +752,8 @@ sub Weather_Define {
##################################### #####################################
sub Weather_Undef { sub Weather_Undef {
my $hash = shift; my $hash = shift;
my $arg = shift; my $arg = shift;
RemoveInternalTimer($hash); RemoveInternalTimer($hash);
return; return;
@ -774,7 +766,7 @@ sub Weather_Attr {
given ($attrName) { given ($attrName) {
when ('forecast') { when ('forecast') {
if ( $cmd eq 'set' ) { if ( $cmd eq 'set' ) {
$hash->{fhem}->{api}->setForecast($attrVal) $hash->{fhem}->{api}->setForecast($attrVal);
} }
$hash->{fhem}->{api}->setForecast(); $hash->{fhem}->{api}->setForecast();
@ -802,11 +794,11 @@ Readonly my $ICONSCALE => 0.5;
##################################### #####################################
sub WeatherIconIMGTag { sub WeatherIconIMGTag {
my $icon = shift; my $icon = shift;
my $width = int( $ICONSCALE * $ICONWIDTH ); my $width = int( $ICONSCALE * $ICONWIDTH );
my $url = FW_IconURL("weather/$icon"); my $url = FW_IconURL("weather/$icon");
my $style = " width=$width"; my $style = " width=$width";
return "<img src=\"$url\"$style alt=\"$icon\">"; return "<img src=\"$url\"$style alt=\"$icon\">";
} }
@ -827,8 +819,8 @@ sub WeatherAsHtmlV {
my $fc; my $fc;
if ( if (
defined($f) defined($f)
&& ( $f eq 'h' && ( $f eq 'h'
|| $f eq 'd' ) || $f eq 'd' )
) )
{ {
$fc = ( $f eq 'd' ? 'fc' : 'hfc' ); $fc = ( $f eq 'd' ? 'fc' : 'hfc' );
@ -911,8 +903,8 @@ sub WeatherAsHtmlH {
my $fc; my $fc;
if ( if (
defined($f) defined($f)
&& ( $f eq 'h' && ( $f eq 'h'
|| $f eq 'd' ) || $f eq 'd' )
) )
{ {
$fc = ( $f eq 'd' ? 'fc' : 'hfc' ); $fc = ( $f eq 'd' ? 'fc' : 'hfc' );
@ -1014,7 +1006,7 @@ sub WeatherCheckOptions {
if ( defined($op1) && $op1 && $op1 =~ m{[0-9]}xms ) { $items = $op1; } if ( defined($op1) && $op1 && $op1 =~ m{[0-9]}xms ) { $items = $op1; }
if ( defined($op2) && $op2 && $op2 =~ m{[dh]}xms ) { $f = $op2; } if ( defined($op2) && $op2 && $op2 =~ m{[dh]}xms ) { $f = $op2; }
$f =~ tr/dh/./cd if ( defined $f && $f ); $f =~ tr/dh/./cd if ( defined $f && $f );
$items =~ tr/0-9/./cd if ( defined($items) && $items ); $items =~ tr/0-9/./cd if ( defined($items) && $items );
$items = 6 if ( !$items ); $items = 6 if ( !$items );

View File

@ -205,9 +205,10 @@ sub new {
: 900 : 900
); );
$self->{apiversion} = ($apioptions->{version} ? $apioptions->{version} : '2.5'); $self->{apiversion} =
( $apioptions->{version} ? $apioptions->{version} : '2.5' );
$self->{cached} = _CreateForecastRef($self); $self->{cached} = _CreateForecastRef($self);
bless $self, $class; bless $self, $class;
return $self; return $self;
@ -231,18 +232,18 @@ sub _parseApiOptions {
} }
sub setAlerts { sub setAlerts {
my $self = shift; my $self = shift;
my $alerts = shift // 0; my $alerts = shift // 0;
$self->{alerts} = $alerts; $self->{alerts} = $alerts;
return; return;
} }
sub setForecast { sub setForecast {
my $self = shift; my $self = shift;
my $forecast = shift // ''; my $forecast = shift // '';
$self->{forecast} = $forecast; $self->{forecast} = $forecast;
return; return;
} }
@ -261,9 +262,9 @@ sub setRetrieveData {
} }
sub setLocation { sub setLocation {
my $self = shift; my $self = shift;
my $lat = shift; my $lat = shift;
my $long = shift; my $long = shift;
$self->{lat} = $lat; $self->{lat} = $lat;
$self->{long} = $long; $self->{long} = $long;
@ -339,10 +340,12 @@ sub _RetrieveDataFromOpenWeatherMap {
. $self->{lat} . '&' . 'lon=' . $self->{lat} . '&' . 'lon='
. $self->{long} . '&' . $self->{long} . '&'
. 'APPID=' . 'APPID='
. $self->{key} . '&' . 'units=' . $self->{key} . '&'
. 'units='
. 'metric' . '&' . 'lang=' . 'metric' . '&' . 'lang='
. $self->{lang} . '&' . 'exclude=' . $self->{lang} . '&'
. _createExcludeString($self->{forecast},$self->{alerts}); . 'exclude='
. _createExcludeString( $self->{forecast}, $self->{alerts} );
::HttpUtils_NonblockingGet($paramRef); ::HttpUtils_NonblockingGet($paramRef);
} }
@ -351,17 +354,17 @@ sub _RetrieveDataFromOpenWeatherMap {
} }
sub _createExcludeString { sub _createExcludeString {
my $forecast = shift; my $forecast = shift;
my $alerts = shift; my $alerts = shift;
my @exclude = qw/alerts minutely hourly daily/; my @exclude = qw/alerts minutely hourly daily/;
my @forecast = split(',',$forecast); my @forecast = split( ',', $forecast );
my @alerts = ( $alerts ? ',alerts' : '' ); my @alerts = ( $alerts ? ',alerts' : '' );
my %in_forecast = map {$_ => 1} @forecast,@alerts; my %in_forecast = map { $_ => 1 } @forecast, @alerts;
my @diff = grep {not $in_forecast{$_}} @exclude; my @diff = grep { not $in_forecast{$_} } @exclude;
return join(',',@alerts); return join( ',', @alerts );
} }
sub _RetrieveDataFinished { sub _RetrieveDataFinished {
@ -410,8 +413,8 @@ sub _ProcessingRetrieveData {
} }
else { else {
### Debug ### Debug
# print '!!! DEBUG !!! - Endpoint: ' . $self->{endpoint} . "\n"; # print '!!! DEBUG !!! - Endpoint: ' . $self->{endpoint} . "\n";
# print '!!! DEBUG !!! - Response: ' . Dumper $data; # print '!!! DEBUG !!! - Response: ' . Dumper $data;
###### Ab hier wird die ResponseHash Referenze für die Rückgabe zusammen gestellt ###### Ab hier wird die ResponseHash Referenze für die Rückgabe zusammen gestellt
$self->{cached}->{current_date_time} = $self->{cached}->{current_date_time} =
strftimeWrapper( "%a, %e %b %Y %H:%M", strftimeWrapper( "%a, %e %b %Y %H:%M",
@ -424,32 +427,30 @@ sub _ProcessingRetrieveData {
$self->{cached}->{license}{text} = 'none'; $self->{cached}->{license}{text} = 'none';
$self->{cached}->{current} = { $self->{cached}->{current} = {
'temperature' => int( 'temperature' => int(
sprintf( "%.1f", sprintf( "%.1f", $data->{main}->{temp} ) + 0.5
$data->{main}->{temp}) + 0.5
), ),
'temp_c' => int( 'temp_c' => int(
sprintf( "%.1f", sprintf( "%.1f", $data->{main}->{temp} ) + 0.5
$data->{main}->{temp}) + 0.5
), ),
'low_c' => int( 'low_c' => int(
sprintf( "%.1f", sprintf( "%.1f", $data->{main}->{temp_min} ) +
$data->{main}->{temp_min}) + 0.5 0.5
), ),
'high_c' => int( 'high_c' => int(
sprintf( "%.1f", sprintf( "%.1f", $data->{main}->{temp_max} ) +
$data->{main}->{temp_max}) + 0.5 0.5
), ),
'tempLow' => int( 'tempLow' => int(
sprintf( "%.1f", sprintf( "%.1f", $data->{main}->{temp_min} ) +
$data->{main}->{temp_min}) + 0.5 0.5
), ),
'tempHigh' => int( 'tempHigh' => int(
sprintf( "%.1f", sprintf( "%.1f", $data->{main}->{temp_max} ) +
$data->{main}->{temp_max}) + 0.5 0.5
), ),
'tempFeelsLike_c' => int( 'tempFeelsLike_c' => int(
sprintf( "%.1f", sprintf( "%.1f", $data->{main}->{feels_like} )
$data->{main}->{feels_like}) + 0.5 + 0.5
), ),
'humidity' => $data->{main}->{humidity}, 'humidity' => $data->{main}->{humidity},
'condition' => encode_utf8( 'condition' => encode_utf8(
@ -488,8 +489,8 @@ sub _ProcessingRetrieveData {
"%a, %e %b %Y %H:%M", "%a, %e %b %Y %H:%M",
localtime( $data->{dt} ) localtime( $data->{dt} )
), ),
'visibility' => int( sprintf( 'visibility' => int(
"%.1f", $data->{visibility} ) + 0.5 sprintf( "%.1f", $data->{visibility} ) + 0.5
), ),
}; };
@ -549,14 +550,12 @@ sub _ProcessingRetrieveData {
) + 0.5 ) + 0.5
), ),
'dew_point' => int( 'dew_point' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{hourly}->[$i]
$data->{hourly}->[$i]->{dew_point} ->{dew_point} ) + 0.5
) + 0.5
), ),
'humidity' => 'humidity' =>
$data->{hourly}->[$i] $data->{hourly}->[$i]->{humidity},
->{humidity},
'condition' => encode_utf8( 'condition' => encode_utf8(
$data->{hourly}->[$i]->{weather} $data->{hourly}->[$i]->{weather}
->[0]->{description} ->[0]->{description}
@ -594,8 +593,7 @@ sub _ProcessingRetrieveData {
) + 0.5 ) + 0.5
), ),
'cloudCover' => 'cloudCover' =>
$data->{hourly}->[$i] $data->{hourly}->[$i]->{clouds},
->{clouds},
'code' => $codes{ 'code' => $codes{
$data->{hourly}->[$i]->{weather} $data->{hourly}->[$i]->{weather}
->[0]->{id} ->[0]->{id}
@ -604,14 +602,14 @@ sub _ProcessingRetrieveData {
$data->{hourly}->[$i]->{weather}->[0] $data->{hourly}->[$i]->{weather}->[0]
->{icon}, ->{icon},
'rain1h' => 'rain1h' =>
$data->{hourly}->[$i]->{rain}->{'1h'}, $data->{hourly}->[$i]->{rain}->{'1h'},
'snow1h' => 'snow1h' =>
$data->{hourly}->[$i]->{snow}->{'1h'}, $data->{hourly}->[$i]->{snow}->{'1h'},
'uvi' => 'uvi' => $data->{hourly}->[$i]->{uvi},
$data->{hourly}->[$i]->{uvi}, 'visibility' => int(
'visibility' => int( sprintf( sprintf( "%.1f",
"%.1f", $data->{hourly}->[$i]->{visibility} ) $data->{hourly}->[$i]
+ 0.5 ->{visibility} ) + 0.5
), ),
}, },
); );
@ -669,8 +667,8 @@ sub _ProcessingRetrieveData {
) - 3600 ) - 3600
) )
), ),
'moon_phase' => $data->{daily}->[$i] 'moon_phase' =>
->{moon_phase}, $data->{daily}->[$i]->{moon_phase},
'moonset' => strftime( 'moonset' => strftime(
"%a, %H:%M", "%a, %H:%M",
localtime( localtime(
@ -681,88 +679,75 @@ sub _ProcessingRetrieveData {
) )
), ),
'temperature' => int( 'temperature' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]->{temp}
$data->{daily}->[$i]->{temp}->{day} ->{day} ) + 0.5
) + 0.5
), ),
'temperature_morn' => int( 'temperature_morn' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]->{temp}
$data->{daily}->[$i]->{temp}->{morn} ->{morn} ) + 0.5
) + 0.5
), ),
'temperature_eve' => int( 'temperature_eve' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]->{temp}
$data->{daily}->[$i]->{temp}->{eve} ->{eve} ) + 0.5
) + 0.5
), ),
'temperature_night' => int( 'temperature_night' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]->{temp}
$data->{daily}->[$i]->{temp}->{night} ->{night} ) + 0.5
) + 0.5
), ),
'tempFeelsLike_morn' => int( 'tempFeelsLike_morn' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]
$data->{daily}->[$i]->{feels_like}->{morn} ->{feels_like}->{morn} ) + 0.5
) + 0.5
), ),
'tempFeelsLike_eve' => int( 'tempFeelsLike_eve' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]
$data->{daily}->[$i]->{feels_like}->{eve} ->{feels_like}->{eve} ) + 0.5
) + 0.5
), ),
'tempFeelsLike_night' => int( 'tempFeelsLike_night' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]
$data->{daily}->[$i]->{feels_like}->{night} ->{feels_like}->{night} ) +
) + 0.5 0.5
), ),
'tempFeelsLike_day' => int( 'tempFeelsLike_day' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]
$data->{daily}->[$i]->{feels_like}->{day} ->{feels_like}->{day} ) + 0.5
) + 0.5
), ),
'temp_c' => int( 'temp_c' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]->{temp}
$data->{daily}->[$i]->{temp}->{day} ->{day} ) + 0.5
) + 0.5
), ),
'low_c' => int( 'low_c' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]->{temp}
$data->{daily}->[$i]->{temp}->{min} ->{min} ) + 0.5
) + 0.5
), ),
'high_c' => int( 'high_c' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]->{temp}
$data->{daily}->[$i]->{temp}->{max} ->{max} ) + 0.5
) + 0.5
), ),
'tempLow' => int( 'tempLow' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]->{temp}
$data->{daily}->[$i]->{temp}->{min} ->{min} ) + 0.5
) + 0.5
), ),
'tempHigh' => int( 'tempHigh' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]->{temp}
$data->{daily}->[$i]->{temp}->{max} ->{max} ) + 0.5
) + 0.5
), ),
'dew_point' => int( 'dew_point' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]
$data->{daily}->[$i]->{dew_point} ->{dew_point} ) + 0.5
) + 0.5
), ),
'humidity' => 'humidity' =>
$data->{daily}->[$i]->{humidity}, $data->{daily}->[$i]->{humidity},
@ -770,8 +755,13 @@ sub _ProcessingRetrieveData {
$data->{daily}->[$i]->{weather} $data->{daily}->[$i]->{weather}
->[0]->{description} ->[0]->{description}
), ),
'code' => $codes{ $data->{daily}->[$i]->{weather}->[0]->{id} }, 'code' => $codes{
'iconAPI' => $data->{daily}->[$i]->{weather}->[0]->{icon}, $data->{daily}->[$i]->{weather}
->[0]->{id}
},
'iconAPI' =>
$data->{daily}->[$i]->{weather}->[0]
->{icon},
'pressure' => int( 'pressure' => int(
sprintf( "%.1f", sprintf( "%.1f",
$data->{daily}->[$i]->{pressure} $data->{daily}->[$i]->{pressure}
@ -843,29 +833,42 @@ sub _ProcessingRetrieveData {
push( push(
@{ $self->{cached}->{alerts} }, @{ $self->{cached}->{alerts} },
{ {
'warn_'.$i.'_End' => strftimeWrapper( 'warn_'
. $i
. '_End' => strftimeWrapper(
"%a, %e %b %Y %H:%M", "%a, %e %b %Y %H:%M",
localtime( localtime(
( $data->{alerts}->[$i]->{end} ) (
- 3600 $data->{alerts}->[$i]->{end}
) - 3600
) )
), ),
'warn_'.$i.'_Start' => strftimeWrapper( 'warn_'
. $i
. '_Start' => strftimeWrapper(
"%a, %e %b %Y %H:%M", "%a, %e %b %Y %H:%M",
localtime( localtime(
( $data->{alerts}->[$i]->{start} ) (
- 3600 $data->{alerts}->[$i]
->{start}
) - 3600
) )
), ),
'warn_'.$i.'_Description' => encode_utf8( 'warn_'
. $i
. '_Description' => encode_utf8(
$data->{alerts}->[$i]->{description} $data->{alerts}->[$i]->{description}
), ),
'warn_'.$i.'_SenderName' => encode_utf8( 'warn_'
. $i
. '_SenderName' => encode_utf8(
$data->{alerts}->[$i]->{sender_name} $data->{alerts}->[$i]->{sender_name}
), ),
'warn_'.$i.'_Event' => encode_utf8( 'warn_'
. $i
. '_Event' => encode_utf8(
$data->{alerts}->[$i]->{event} $data->{alerts}->[$i]->{event}
), ),
}, },
); );