fix negativ integer value round

fix alerts integration
This commit is contained in:
2022-12-19 11:24:27 +01:00
parent 96ce411948
commit d82d4fa01d
2 changed files with 76 additions and 92 deletions

View File

@@ -377,10 +377,11 @@ sub Weather_ForcastConfig {
$forecastConfig{hourly} =
( AttrVal( $name, 'forecast', '' ) =~ m{hourly}xms ? 1 : 0 );
$forecastConfig{daily} =
( 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;
}
@@ -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} )
{
while ( my ( $r, $v ) = each %{ $dataRef->{alerts} } ) {
readingsBulkUpdate( $hash, $r, $v )
if ( ref( $dataRef->{$r} ) ne 'HASH'
&& ref( $dataRef->{$r} ) ne 'ARRAY' );
my $i = 0;
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'
&& ref( $dataRef->{$r} ) ne 'ARRAY' );
}
}
}
### state
my $val = 'T: '
. $dataRef->{current}->{temperature} . ' °C' . ' '
. substr( $status_items_txt_i18n{1}, 0, 1 ) . ': '

View File

@@ -7,6 +7,7 @@
# All rights reserved
#
# 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
@@ -304,9 +305,7 @@ sub _RetrieveDataFromOpenWeatherMap {
my $paramRef = {
timeout => 15,
self => $self,
endpoint => $self->{endpoint} eq 'none' ? 'weather'
: $self->{endpoint} eq 'weather' ? 'onecall'
: 'weather',
endpoint => $self->{endpoint} eq 'none' ? 'onecall' : 'none',
callback => \&_RetrieveDataFinished,
};
@@ -424,21 +423,19 @@ sub _ProcessingRetrieveData {
when ('onecall') {
$self->{cached}->{current} = {
'temperature' => int(
sprintf( "%.1f", $data->{current}->{temp} ) +
0.5
sprintf( "%.0f", $data->{current}->{temp} )
),
'temp_c' => int(
sprintf( "%.1f", $data->{current}->{temp} ) +
0.5
sprintf( "%.0f", $data->{current}->{temp} )
),
'tempFeelsLike_c' => int(
sprintf( "%.1f",
$data->{current}->{feels_like} ) + 0.5
sprintf( "%.0f",
$data->{current}->{feels_like} )
),
'dew_point' => int(
sprintf(
"%.1f", $data->{current}->{dew_point}
) + 0.5
"%.0f", $data->{current}->{dew_point}
)
),
'humidity' => $data->{current}->{humidity},