testing #29

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

View File

@ -329,7 +329,7 @@ sub Weather_ReturnWithError {
return; return;
} }
sub Weather_DeleteReadings { sub Weather_DeleteForecastReadings {
my $hash = shift; my $hash = shift;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
@ -350,6 +350,23 @@ sub Weather_DeleteReadings {
return; return;
} }
sub Weather_DeleteAlertsReadings {
my $hash = shift;
my $alertsLimit = shift // 0;
my $name = $hash->{NAME};
my $alertsConfig = Weather_ForcastConfig($hash);
my $alertsLimitNoAlerts = 0;
$alertsLimit = $alertsLimitNoAlerts
if ( !$alertsConfig->{alerts} );
CommandDeleteReading( undef,
$name . ' ' . 'warn_([' . $alertsLimit . '-9]|[0-9]{2})_.*' );
return;
}
sub Weather_RetrieveCallbackFn { sub Weather_RetrieveCallbackFn {
my $name = shift; my $name = shift;
@ -550,7 +567,6 @@ sub Weather_WriteReadings {
{ {
my $i = 0; my $i = 0;
foreach my $warn ( @{ $dataRef->{alerts} } ) { foreach my $warn ( @{ $dataRef->{alerts} } ) {
$i++;
my $w = "warn_" . $i . "_"; my $w = "warn_" . $i . "_";
while ( my ( $r, $v ) = each %{$warn} ) { while ( my ( $r, $v ) = each %{$warn} ) {
@ -559,7 +575,18 @@ sub Weather_WriteReadings {
&& ref( $dataRef->{$r} ) ne 'ARRAY' ); && ref( $dataRef->{$r} ) ne 'ARRAY' );
} }
$i++;
} }
Weather_DeleteAlertsReadings( $hash,
scalar( @{ $dataRef->{alerts} } ) );
readingsBulkUpdate( $hash, 'warnCount',
scalar( @{ $dataRef->{alerts} } ) );
}
else {
Weather_DeleteAlertsReadings($hash);
readingsBulkUpdate( $hash, 'warnCount',
scalar( @{ $dataRef->{alerts} } ) );
} }
### state ### state
@ -817,13 +844,13 @@ sub Weather_Attr {
$hash->{fhem}->{api}->setForecast(); $hash->{fhem}->{api}->setForecast();
} }
InternalTimer( gettimeofday() + 1, \&Weather_DeleteReadings, InternalTimer( gettimeofday() + 0.5,
$hash ); \&Weather_DeleteForecastReadings, $hash );
} }
when ('forecastLimit') { when ('forecastLimit') {
InternalTimer( gettimeofday() + 1, \&Weather_DeleteReadings, InternalTimer( gettimeofday() + 0.5,
$hash ); \&Weather_DeleteForecastReadings, $hash );
} }
when ('alerts') { when ('alerts') {
@ -833,6 +860,9 @@ sub Weather_Attr {
elsif ( $cmd eq 'del' ) { elsif ( $cmd eq 'del' ) {
$hash->{fhem}->{api}->setAlerts(); $hash->{fhem}->{api}->setAlerts();
} }
InternalTimer( gettimeofday() + 0.5,
\&Weather_DeleteAlertsReadings, $hash );
} }
} }

View File

@ -157,6 +157,7 @@ my %codes = (
602 => 13, 602 => 13,
611 => 46, 611 => 46,
612 => 46, 612 => 46,
613 => 46,
615 => 5, 615 => 5,
616 => 5, 616 => 5,
620 => 14, 620 => 14,
@ -358,7 +359,7 @@ sub _CreateExcludeString {
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;
@ -486,7 +487,9 @@ sub _ProcessingRetrieveData {
sprintf( "%.1f", sprintf( "%.1f",
$data->{current}->{visibility} ) + 0.5 $data->{current}->{visibility} ) + 0.5
), ),
'uvi' => $data->{current}->{uvi}, 'uvi' => $data->{current}->{uvi},
'timezone' => $data->{timezone},
'timezone_offset' => $data->{timezone_offset},
}; };
if ( ref( $data->{hourly} ) eq "ARRAY" if ( ref( $data->{hourly} ) eq "ARRAY"
@ -503,15 +506,13 @@ sub _ProcessingRetrieveData {
'pubDate' => strftimeWrapper( 'pubDate' => strftimeWrapper(
"%a, %e %b %Y %H:%M", "%a, %e %b %Y %H:%M",
localtime( localtime(
( $data->{hourly}->[$i]->{dt} ) $data->{hourly}->[$i]->{dt}
- 3600
) )
), ),
'day_of_week' => strftime( 'day_of_week' => strftime(
"%a, %H:%M", "%a, %H:%M",
localtime( localtime(
( $data->{hourly}->[$i]->{dt} ) $data->{hourly}->[$i]->{dt}
- 3600
) )
), ),
'temperature' => int( 'temperature' => int(
@ -609,42 +610,31 @@ sub _ProcessingRetrieveData {
'pubDate' => strftimeWrapper( 'pubDate' => strftimeWrapper(
"%a, %e %b %Y %H:%M", "%a, %e %b %Y %H:%M",
localtime( localtime(
( $data->{daily}->[$i]->{dt} ) $data->{daily}->[$i]->{dt}
- 3600
) )
), ),
'day_of_week' => strftime( 'day_of_week' => strftime(
"%a, %H:%M", "%a, %H:%M",
localtime( localtime(
( $data->{daily}->[$i]->{dt} ) $data->{daily}->[$i]->{dt}
- 3600
) )
), ),
'sunrise' => strftime( 'sunrise' => strftime(
"%H:%M", "%H:%M",
localtime( localtime(
( $data->{daily}->[$i]->{sunrise}
$data->{daily}->[$i]
->{sunrise}
) - 3600
) )
), ),
'sunset' => strftime( 'sunset' => strftime(
"%a, %H:%M", "%a, %H:%M",
localtime( localtime(
( $data->{daily}->[$i]->{sunset}
$data->{daily}->[$i]
->{sunset}
) - 3600
) )
), ),
'moonrise' => strftime( 'moonrise' => strftime(
"%a, %H:%M", "%a, %H:%M",
localtime( localtime(
( $data->{daily}->[$i]->{moonrise}
$data->{daily}->[$i]
->{moonrise}
) - 3600
) )
), ),
'moon_phase' => 'moon_phase' =>
@ -652,10 +642,7 @@ sub _ProcessingRetrieveData {
'moonset' => strftime( 'moonset' => strftime(
"%a, %H:%M", "%a, %H:%M",
localtime( localtime(
( $data->{daily}->[$i]->{moonset}
$data->{daily}->[$i]
->{moonset}
) - 3600
) )
), ),
'temperature' => int( 'temperature' => int(