testing #29

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

View File

@ -377,10 +377,11 @@ sub Weather_ForcastConfig {
$forecastConfig{hourly} = $forecastConfig{hourly} =
( AttrVal( $name, 'forecast', '' ) =~ m{hourly}xms ? 1 : 0 ); ( AttrVal( $name, 'forecast', '' ) =~ m{hourly}xms ? 1 : 0 );
$forecastConfig{daily} = $forecastConfig{daily} =
( AttrVal( $name, 'forecast', '' ) =~ m{daily}xms ? 1 : 0 ); ( AttrVal( $name, 'forecast', '' ) =~ m{daily}xms ? 1 : 0 );
$forecastConfig{alerts} =
( AttrVal( $name, 'forecast', '' ) =~ m{alerts}xms ? 1 : 0 ); $forecastConfig{alerts} = AttrVal( $name, 'alerts', 0 );
return \%forecastConfig; return \%forecastConfig;
} }
@ -541,16 +542,27 @@ sub Weather_WriteReadings {
} }
} }
if ( ref( $dataRef->{alerts} ) eq 'HASH' ### alerts
if ( defined( $dataRef->{alerts} )
&& ref( $dataRef->{alerts} ) eq 'ARRAY'
&& scalar( @{ $dataRef->{alerts} } ) > 0
&& $forecastConfig->{alerts} ) && $forecastConfig->{alerts} )
{ {
while ( my ( $r, $v ) = each %{ $dataRef->{alerts} } ) { my $i = 0;
readingsBulkUpdate( $hash, $r, $v ) foreach my $warn ( @{ $dataRef->{alerts} } ) {
$i++;
my $w = "warn_" . $i . "_";
while ( my ( $r, $v ) = each %{$warn} ) {
readingsBulkUpdate( $hash, $w . $r, $v )
if ( ref( $dataRef->{$r} ) ne 'HASH' if ( ref( $dataRef->{$r} ) ne 'HASH'
&& ref( $dataRef->{$r} ) ne 'ARRAY' ); && ref( $dataRef->{$r} ) ne 'ARRAY' );
} }
}
} }
### state
my $val = 'T: ' my $val = 'T: '
. $dataRef->{current}->{temperature} . ' °C' . ' ' . $dataRef->{current}->{temperature} . ' °C' . ' '
. substr( $status_items_txt_i18n{1}, 0, 1 ) . ': ' . substr( $status_items_txt_i18n{1}, 0, 1 ) . ': '

View File

@ -7,6 +7,7 @@
# All rights reserved # All rights reserved
# #
# Special thanks goes to: # Special thanks goes to:
# - Harry (harryman) for many tests and patch that implements onecall API
# #
# #
# This script is free software; you can redistribute it and/or modify # This script is free software; you can redistribute it and/or modify
@ -304,9 +305,7 @@ sub _RetrieveDataFromOpenWeatherMap {
my $paramRef = { my $paramRef = {
timeout => 15, timeout => 15,
self => $self, self => $self,
endpoint => $self->{endpoint} eq 'none' ? 'weather' endpoint => $self->{endpoint} eq 'none' ? 'onecall' : 'none',
: $self->{endpoint} eq 'weather' ? 'onecall'
: 'weather',
callback => \&_RetrieveDataFinished, callback => \&_RetrieveDataFinished,
}; };
@ -424,21 +423,19 @@ sub _ProcessingRetrieveData {
when ('onecall') { when ('onecall') {
$self->{cached}->{current} = { $self->{cached}->{current} = {
'temperature' => int( 'temperature' => int(
sprintf( "%.1f", $data->{current}->{temp} ) + sprintf( "%.0f", $data->{current}->{temp} )
0.5
), ),
'temp_c' => int( 'temp_c' => int(
sprintf( "%.1f", $data->{current}->{temp} ) + sprintf( "%.0f", $data->{current}->{temp} )
0.5
), ),
'tempFeelsLike_c' => int( 'tempFeelsLike_c' => int(
sprintf( "%.1f", sprintf( "%.0f",
$data->{current}->{feels_like} ) + 0.5 $data->{current}->{feels_like} )
), ),
'dew_point' => int( 'dew_point' => int(
sprintf( sprintf(
"%.1f", $data->{current}->{dew_point} "%.0f", $data->{current}->{dew_point}
) + 0.5 )
), ),
'humidity' => $data->{current}->{humidity}, 'humidity' => $data->{current}->{humidity},
'condition' => encode_utf8( 'condition' => encode_utf8(
@ -518,36 +515,22 @@ sub _ProcessingRetrieveData {
) )
), ),
'temperature' => int( 'temperature' => int(
sprintf( sprintf( "%.0f",
"%.1f", $data->{hourly}->[$i]->{temp} )
(
$data->{hourly}->[$i]
->{temp}
)
) + 0.5
), ),
'temp_c' => int( 'temp_c' => int(
sprintf( sprintf( "%.0f",
"%.1f", $data->{hourly}->[$i]->{temp} )
(
$data->{hourly}->[$i]
->{temp}
)
) + 0.5
), ),
'tempFeelsLike' => int( 'tempFeelsLike' => int(
sprintf( sprintf( "%.0f",
"%.1f",
(
$data->{hourly}->[$i] $data->{hourly}->[$i]
->{feels_like} ->{feels_like} )
)
) + 0.5
), ),
'dew_point' => int( 'dew_point' => int(
sprintf( "%.1f", sprintf( "%.0f",
$data->{hourly}->[$i] $data->{hourly}->[$i]
->{dew_point} ) + 0.5 ->{dew_point} )
), ),
'humidity' => 'humidity' =>
$data->{hourly}->[$i]->{humidity}, $data->{hourly}->[$i]->{humidity},
@ -676,75 +659,74 @@ sub _ProcessingRetrieveData {
) )
), ),
'temperature' => int( 'temperature' => int(
sprintf( "%.1f", sprintf( "%.0f",
$data->{daily}->[$i]->{temp} $data->{daily}->[$i]->{temp}
->{day} ) + 0.5 ->{day} )
), ),
'temperature_morn' => int( 'temperature_morn' => int(
sprintf( "%.1f", sprintf( "%.0f",
$data->{daily}->[$i]->{temp} $data->{daily}->[$i]->{temp}
->{morn} ) + 0.5 ->{morn} )
), ),
'temperature_eve' => int( 'temperature_eve' => int(
sprintf( "%.1f", sprintf( "%.0f",
$data->{daily}->[$i]->{temp} $data->{daily}->[$i]->{temp}
->{eve} ) + 0.5 ->{eve} )
), ),
'temperature_night' => int( 'temperature_night' => int(
sprintf( "%.1f", sprintf( "%.0f",
$data->{daily}->[$i]->{temp} $data->{daily}->[$i]->{temp}
->{night} ) + 0.5 ->{night} )
), ),
'tempFeelsLike_morn' => int( 'tempFeelsLike_morn' => int(
sprintf( "%.1f", sprintf( "%.0f",
$data->{daily}->[$i] $data->{daily}->[$i]
->{feels_like}->{morn} ) + 0.5 ->{feels_like}->{morn} )
), ),
'tempFeelsLike_eve' => int( 'tempFeelsLike_eve' => int(
sprintf( "%.1f", sprintf( "%.0f",
$data->{daily}->[$i] $data->{daily}->[$i]
->{feels_like}->{eve} ) + 0.5 ->{feels_like}->{eve} )
), ),
'tempFeelsLike_night' => int( 'tempFeelsLike_night' => int(
sprintf( "%.1f", sprintf( "%.0f",
$data->{daily}->[$i] $data->{daily}->[$i]
->{feels_like}->{night} ) + ->{feels_like}->{night} )
0.5
), ),
'tempFeelsLike_day' => int( 'tempFeelsLike_day' => int(
sprintf( "%.1f", sprintf( "%.0f",
$data->{daily}->[$i] $data->{daily}->[$i]
->{feels_like}->{day} ) + 0.5 ->{feels_like}->{day} )
), ),
'temp_c' => int( 'temp_c' => int(
sprintf( "%.1f", sprintf( "%.0f",
$data->{daily}->[$i]->{temp} $data->{daily}->[$i]->{temp}
->{day} ) + 0.5 ->{day} )
), ),
'low_c' => int( 'low_c' => int(
sprintf( "%.1f", sprintf( "%.0f",
$data->{daily}->[$i]->{temp} $data->{daily}->[$i]->{temp}
->{min} ) + 0.5 ->{min} )
), ),
'high_c' => int( 'high_c' => int(
sprintf( "%.1f", sprintf( "%.0f",
$data->{daily}->[$i]->{temp} $data->{daily}->[$i]->{temp}
->{max} ) + 0.5 ->{max} )
), ),
'tempLow' => int( 'tempLow' => int(
sprintf( "%.1f", sprintf( "%.0f",
$data->{daily}->[$i]->{temp} $data->{daily}->[$i]->{temp}
->{min} ) + 0.5 ->{min} )
), ),
'tempHigh' => int( 'tempHigh' => int(
sprintf( "%.1f", sprintf( "%.0f",
$data->{daily}->[$i]->{temp} $data->{daily}->[$i]->{temp}
->{max} ) + 0.5 ->{max} )
), ),
'dew_point' => int( 'dew_point' => int(
sprintf( "%.1f", sprintf( "%.0f",
$data->{daily}->[$i] $data->{daily}->[$i]
->{dew_point} ) + 0.5 ->{dew_point} )
), ),
'humidity' => 'humidity' =>
$data->{daily}->[$i]->{humidity}, $data->{daily}->[$i]->{humidity},
@ -827,40 +809,30 @@ sub _ProcessingRetrieveData {
push( push(
@{ $self->{cached}->{alerts} }, @{ $self->{cached}->{alerts} },
{ {
'warn_' 'End' => strftimeWrapper(
. $i
. '_End' => strftimeWrapper(
"%a, %e %b %Y %H:%M", "%a, %e %b %Y %H:%M",
localtime( localtime(
( (
$data->{alerts}->[$i]->{end} $data->{alerts}->[$i]->{end}
) - 3600 )
) )
), ),
'warn_' 'Start' => strftimeWrapper(
. $i
. '_Start' => strftimeWrapper(
"%a, %e %b %Y %H:%M", "%a, %e %b %Y %H:%M",
localtime( localtime(
( (
$data->{alerts}->[$i] $data->{alerts}->[$i]
->{start} ->{start}
) - 3600 )
) )
), ),
'warn_' 'Description' => encode_utf8(
. $i
. '_Description' => encode_utf8(
$data->{alerts}->[$i]->{description} $data->{alerts}->[$i]->{description}
), ),
'warn_' 'SenderName' => encode_utf8(
. $i
. '_SenderName' => encode_utf8(
$data->{alerts}->[$i]->{sender_name} $data->{alerts}->[$i]->{sender_name}
), ),
'warn_' 'Event' => encode_utf8(
. $i
. '_Event' => encode_utf8(
$data->{alerts}->[$i]->{event} $data->{alerts}->[$i]->{event}
), ),
}, },