From 776b78c0c66aa07567240d34de243ca661cc3993 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Tue, 20 Dec 2022 18:04:45 +0100 Subject: [PATCH] change code for better def modify --- 59_Weather.pm | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/59_Weather.pm b/59_Weather.pm index 2f0fc4f..5f52059 100755 --- a/59_Weather.pm +++ b/59_Weather.pm @@ -728,17 +728,22 @@ sub Weather_Notify { my $type = $hash->{TYPE}; return if ( $dev->{NAME} ne "global" ); - return if ( !grep { /^INITIALIZED|REREADCFG$/ } @{ $dev->{CHANGED} } ); - # return if($attr{$name} && $attr{$name}->{disable}); + # set forcast and alerts values to api object + if ( grep { /^MODIFIED.$name$/x } @{ $dev->{CHANGED} } ) { + $hash->{fhem}->{api}->setForecast( AttrVal( $name, 'forecast', '' ) ); + $hash->{fhem}->{api}->setAlerts( AttrVal( $name, 'alerts', 0 ) ); + + Weather_GetUpdate($hash); + } + + return if ( !grep { /^INITIALIZED|REREADCFG$/x } @{ $dev->{CHANGED} } ); # update weather after initialization or change of configuration # wait 10 to 29 seconds to avoid congestion due to concurrent activities Weather_DisarmTimer($hash); my $delay = 10 + int( rand(20) ); - #$delay= 3; # delay removed until further notice - Log3 $hash, 5, "Weather $name: FHEM initialization or rereadcfg triggered update, delay $delay seconds."; Weather_RearmTimer( $hash, gettimeofday() + $delay ); @@ -816,9 +821,6 @@ sub Weather_Define { } ); - Weather_GetUpdate($hash) - if ($init_done); - return; }