2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-22 08:11:44 +00:00

59_Twilight.pm: may mix some uninitialized messages

git-svn-id: https://svn.fhem.de/fhem/trunk@22971 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Beta-User 2020-10-15 05:36:27 +00:00
parent 380703d69e
commit 9a3e2be9e0

View File

@ -235,25 +235,22 @@ sub Twilight_Notify {
if($found) { if($found) {
my $extWeather = ReadingsNum($hash->{helper}{extWeather}{Device}, $hash->{helper}{extWeather}{Reading},-1); my $extWeather = ReadingsNum($hash->{helper}{extWeather}{Device}, $hash->{helper}{extWeather}{Reading},-1);
my $last = ReadingsNum($name, "cloudCover", -1); my $last = ReadingsNum($name, "cloudCover", -1);
#here we have to split up for extended forecast handling...
return if abs ($last - $extWeather) < 6; return if abs ($last - $extWeather) < 6;
my ($cond, $condText) = [-1,"not known"]; #my ($cond, $condText) = [-1,"not known"];
my $dispatch = defined $hash->{helper}{extWeather} && defined $hash->{helper}{extWeather}{dispatch} ? 1 : 0; my $dispatch = defined $hash->{helper}{extWeather} && defined $hash->{helper}{extWeather}{dispatch} ? 1 : 0;
$cond = ReadingsNum($hash->{helper}{extWeather}{Device}, $hash->{helper}{extWeather}{dispatch}{cond_code},-2) if $dispatch;
$condText = ReadingsVal($hash->{helper}{extWeather}{Device}, $hash->{helper}{extWeather}{dispatch}{cond_text},"unknown") if $dispatch;
readingsBeginUpdate( $hash ); #$cond = ReadingsNum($hash->{helper}{extWeather}{Device}, $hash->{helper}{extWeather}{dispatch}{cond_code},-2) if $dispatch;
readingsBulkUpdate( $hash, "cloudCover", $extWeather ); #$condText = ReadingsVal($hash->{helper}{extWeather}{Device}, $hash->{helper}{extWeather}{dispatch}{cond_text},"unknown") if $dispatch;
readingsBulkUpdate( $hash, "condition_code", $cond ) if $dispatch;
readingsBulkUpdate( $hash, "condition_txt", $condText ) if $dispatch;
readingsEndUpdate( $hash, defined( $hash->{LOCAL} ? 0 : 1 ) );
Twilight_getWeatherHorizon( $hash, $extWeather ); my $weather_horizon = Twilight_getWeatherHorizon( $hash, $extWeather, 1);
#add $sr_weather_horizon and $ss_weather_horizon here, then we will have to do some more Twilight_calc...
#my $horizon = $hash->{HORIZON}; my ($sr, $ss) = Twilight_calc( $hash, $weather_horizon, "7" ); ##these are numbers
#my ( $name, $deg ) = split( ":", $horizon );
my ($sr, $ss) = Twilight_calc( $hash, $hash->{WEATHER_HORIZON}, "7" ); ##these are numbers
my $now = time(); my $now = time();
#$hash->{SR_TEST} = $sr; #$hash->{SR_TEST} = $sr;
#$hash->{SS_TEST} = $ss; #$hash->{SS_TEST} = $ss;
@ -266,8 +263,13 @@ sub Twilight_Notify {
#renew dates and timers?, fire events? #renew dates and timers?, fire events?
my $nextevent = ReadingsVal($name,"nextEvent","none"); my $nextevent = ReadingsVal($name,"nextEvent","none");
readingsBeginUpdate($hash);
my $nextEventTime = FmtTime( $sr ); my $nextEventTime = FmtTime( $sr );
readingsBeginUpdate( $hash );
readingsBulkUpdate( $hash, "cloudCover", $extWeather );
#readingsBulkUpdate( $hash, "condition_code", $cond ) if $dispatch;
#readingsBulkUpdate( $hash, "condition_txt", $condText ) if $dispatch;
if ($now < $sr ) { if ($now < $sr ) {
$hash->{TW}{sr_weather}{TIME} = $sr; $hash->{TW}{sr_weather}{TIME} = $sr;
Twilight_RemoveInternalTimer( "sr_weather", $hash ); Twilight_RemoveInternalTimer( "sr_weather", $hash );
@ -650,7 +652,7 @@ sub Twilight_Midnight {
my $hash = Twilight_GetHashIndirekt( $myHash, ( caller(0) )[3] ); my $hash = Twilight_GetHashIndirekt( $myHash, ( caller(0) )[3] );
return if ( !defined($hash) ); return if ( !defined($hash) );
return Twilight_HandleWeatherData( $hash, "Mid", $firstrun ); return Twilight_HandleWeatherData( $hash, "Mid", $firstrun, ReadingsNum($hash->{NAME},"cloudCover",0) );
} }
################################################################################ ################################################################################
@ -670,7 +672,7 @@ sub Twilight_HandleWeatherData {
my $hash = shift; my $hash = shift;
my $mode = shift; my $mode = shift;
my $swip = shift // return; my $swip = shift // return;
my $cloudCover = shift; my $cloudCover = shift // ReadingsNum($hash->{NAME},"cloudCover",0);
$hash->{SWIP} = $swip; $hash->{SWIP} = $swip;
@ -737,17 +739,19 @@ sub Twilight_sunposTimerSet {
sub Twilight_getWeatherHorizon { sub Twilight_getWeatherHorizon {
my $hash = shift; my $hash = shift;
my $result = shift // return; my $result = shift // return;
my $setInternal = shift // 1;
return if !looks_like_number($result) || $result < 0 || $result > 100; return if !looks_like_number($result) || $result < 0 || $result > 100;
$hash->{WEATHER_CORRECTION} = $result / 12.5; my $weather_horizon = $result / 12.5;
$hash->{WEATHER_HORIZON} = $hash->{WEATHER_CORRECTION} + $hash->{INDOOR_HORIZON}; $hash->{WEATHER_CORRECTION} = $weather_horizon if $setInternal;
$weather_horizon += $hash->{INDOOR_HORIZON};
my $doy = strftime("%j",localtime); my $doy = strftime("%j",localtime);
my $declination = 0.4095*sin(0.016906*($doy-80.086)); my $declination = 0.4095*sin(0.016906*($doy-80.086));
if($hash->{WEATHER_HORIZON} > (89-$hash->{helper}{'.LATITUDE'}+$declination) ){
$hash->{WEATHER_HORIZON} = 89-$hash->{helper}{'.LATITUDE'}+$declination;
};
return; $weather_horizon = min( 89-$hash->{helper}{'.LATITUDE'}+$declination, $weather_horizon );
$hash->{WEATHER_HORIZON} = $weather_horizon if $setInternal;
return $weather_horizon;
} }
################################################################################ ################################################################################