fix error in empty Hash check
This commit is contained in:
		| @@ -379,7 +379,10 @@ sub Weather_WriteReadings($$) { | ||||
|          | ||||
|         readingsBulkUpdate($hash, 'icon',  $iconlist[$dataRef->{current}->{code}]); | ||||
|         if (  defined($dataRef->{current}->{wind_direction}) | ||||
|         and defined($dataRef->{current}->{wind_speed} ) ) | ||||
|           and $dataRef->{current}->{wind_direction} | ||||
|           and defined($dataRef->{current}->{wind_speed}) | ||||
|           and $dataRef->{current}->{wind_speed} | ||||
|           ) | ||||
|         { | ||||
|             my $wdir= degrees_to_direction($dataRef->{current}->{wind_direction}, @directions_txt_i18n); | ||||
|             readingsBulkUpdate($hash, 'wind_condition', 'Wind: ' . $wdir . ' ' . $dataRef->{current}->{wind_speed} . ' km/h'); | ||||
| @@ -389,7 +392,8 @@ sub Weather_WriteReadings($$) { | ||||
|     ### forecast | ||||
|     if ( ref( $dataRef->{forecast} ) eq 'HASH' ) { | ||||
|         ## hourly | ||||
|         if (  defined($dataRef->{forecast}->{hourly}) and ref( $dataRef->{forecast}->{hourly} ) eq 'ARRAY' | ||||
|         if (  defined($dataRef->{forecast}->{hourly}) | ||||
|           and ref( $dataRef->{forecast}->{hourly} ) eq 'ARRAY' | ||||
|           and scalar( @{ $dataRef->{forecast}->{hourly} } ) > 0 ) | ||||
|         { | ||||
|             my $i= 0; | ||||
| @@ -404,7 +408,10 @@ sub Weather_WriteReadings($$) { | ||||
|         #         readingsBulkUpdate($hash, $f . "day_of_week", $wdays_txt_i18n{$fc->{day}}); | ||||
|                 readingsBulkUpdate($hash, $f . 'icon',  $iconlist[$dataRef->{forecast}->{hourly}[$i-1]{code}]); | ||||
|                 if (  defined($dataRef->{forecast}->{hourly}[$i-1]{wind_direction}) | ||||
|                 and defined($dataRef->{forecast}->{hourly}[$i-1]{wind_speed}) ) | ||||
|                   and $dataRef->{forecast}->{hourly}[$i-1]{wind_direction} | ||||
|                   and defined($dataRef->{forecast}->{hourly}[$i-1]{wind_speed}) | ||||
|                   and $dataRef->{forecast}->{hourly}[$i-1]{wind_speed} | ||||
|                   ) | ||||
|                 { | ||||
|                     my $wdir= degrees_to_direction($dataRef->{forecast}->{hourly}[$i-1]{wind_direction}, @directions_txt_i18n); | ||||
|                     readingsBulkUpdate($hash, $f . 'wind_condition', 'Wind: ' . $wdir . ' ' . $dataRef->{forecast}->{hourly}[$i-1]{wind_speed} . ' km/h'); | ||||
| @@ -429,7 +436,10 @@ sub Weather_WriteReadings($$) { | ||||
|         #         readingsBulkUpdate($hash, $f . "day_of_week", $wdays_txt_i18n{$fc->{day}}); | ||||
|                 readingsBulkUpdate($hash, $f . 'icon',  $iconlist[$dataRef->{forecast}->{daily}[$i-1]{code}]); | ||||
|                 if (  defined($dataRef->{forecast}->{daily}[$i-1]{wind_direction}) | ||||
|                 and defined($dataRef->{forecast}->{daily}[$i-1]{wind_speed}) ) | ||||
|                   and $dataRef->{forecast}->{daily}[$i-1]{wind_direction} | ||||
|                   and defined($dataRef->{forecast}->{daily}[$i-1]{wind_speed}) | ||||
|                   and $dataRef->{forecast}->{daily}[$i-1]{wind_speed} | ||||
|                   ) | ||||
|                 { | ||||
|                     my $wdir= degrees_to_direction($dataRef->{forecast}->{daily}[$i-1]{wind_direction}, @directions_txt_i18n); | ||||
|                     readingsBulkUpdate($hash, $f . 'wind_condition', 'Wind: ' . $wdir . ' ' . $dataRef->{forecast}->{daily}[$i-1]{wind_speed} . ' km/h'); | ||||
| @@ -609,9 +619,9 @@ sub Weather_Define($$) { | ||||
|  | ||||
|   $hash->{NOTIFYDEV} = "global"; | ||||
|   $hash->{fhem}->{interfaces}= "temperature;humidity;wind"; | ||||
|   $hash->{LOCATION}     = ( defined($location) ? $location : AttrVal( 'global', 'latitude',  'error' ).','.AttrVal( 'global', 'longitude', 'error' ) ); | ||||
|   $hash->{LOCATION}     = ( (defined($location) and $location) ? $location : AttrVal( 'global', 'latitude',  'error' ).','.AttrVal( 'global', 'longitude', 'error' ) ); | ||||
|   $hash->{INTERVAL}     = $interval; | ||||
|   $hash->{LANG}         = ( defined($lang) ? $lang : lc(AttrVal('global','language','de')) ); | ||||
|   $hash->{LANG}         = ( (defined($lang) and $lang) ? $lang : lc(AttrVal('global','language','de')) ); | ||||
|   $hash->{API}          = $api; | ||||
|   $hash->{APIKEY}       = $apikey; | ||||
|   $hash->{APIOPTIONS}   = $apioptions; | ||||
|   | ||||
							
								
								
									
										154
									
								
								DarkSkyAPI.pm
									
									
									
									
									
								
							
							
						
						
									
										154
									
								
								DarkSkyAPI.pm
									
									
									
									
									
								
							| @@ -67,8 +67,18 @@ sub new { | ||||
|  | ||||
|     my $self = { | ||||
|         devName => $argsRef->{devName}, | ||||
|         key => ( defined( $argsRef->{apikey} ) ? $argsRef->{apikey} : 'none' ), | ||||
|         cachemaxage => ( (split(':',$argsRef->{apioptions}))[0] eq 'cachemaxage' ? (split(':',$argsRef->{apioptions}))[1] : 900 ), | ||||
|         key     => ( | ||||
|             ( defined( $argsRef->{apikey} ) and $argsRef->{apikey} ) | ||||
|             ? $argsRef->{apikey} | ||||
|             : 'none' | ||||
|         ), | ||||
|         cachemaxage => ( | ||||
|             ( defined( $argsRef->{apioptions} ) and $argsRef->{apioptions} ) | ||||
|             ? ( ( split( ':', $argsRef->{apioptions} ) )[0] eq 'cachemaxage' | ||||
|                 ? ( split( ':', $argsRef->{apioptions} ) )[1] | ||||
|                 : 900 ) | ||||
|             : 900 | ||||
|         ), | ||||
|         lang      => $argsRef->{language}, | ||||
|         lat       => ( split( ',', $argsRef->{location} ) )[0], | ||||
|         long      => ( split( ',', $argsRef->{location} ) )[1], | ||||
| @@ -174,25 +184,32 @@ sub _RetrieveDataFinished($$$) { | ||||
| sub _ProcessingRetrieveData($$) { | ||||
|     my ( $self, $response ) = @_; | ||||
|  | ||||
|     if ( $self->{cached}->{status} eq 'ok' and defined($response) ) { | ||||
|     if (    $self->{cached}->{status} eq 'ok' | ||||
|         and defined($response) | ||||
|         and $response ) | ||||
|     { | ||||
|         my $data = eval { decode_json($response) }; | ||||
|  | ||||
|         if ($@) { | ||||
|             _ErrorHandling( $self, 'DarkSky Weather decode JSON err ' . $@ ); | ||||
|         } | ||||
|         elsif ( defined( $data->{code} ) and defined( $data->{error} ) ) { | ||||
|         elsif ( defined( $data->{code} ) | ||||
|             and $data->{code} | ||||
|             and defined( $data->{error} ) | ||||
|             and $data->{error} ) | ||||
|         { | ||||
|             _ErrorHandling( $self, | ||||
|                 'Code: ' . $data->{code} . ' Error: ' . $data->{error} ); | ||||
|         } | ||||
|         else { | ||||
|             #             print Dumper $data;       ## für Debugging | ||||
|  | ||||
|             $self->{cached}->{current_date_time} = strftime( | ||||
|                 "%a,%e %b %Y %H:%M %p", | ||||
|                 localtime( $self->{fetchTime} ) | ||||
|               ); | ||||
|             $self->{cached}->{current_date_time} = | ||||
|               strftime( "%a,%e %b %Y %H:%M %p", | ||||
|                 localtime( $self->{fetchTime} ) ); | ||||
|             $self->{cached}->{timezone} = $data->{timezone}; | ||||
|             $self->{cached}->{license}{text} = $data->{flags}->{'meteoalarm-license'}; | ||||
|             $self->{cached}->{license}{text} = | ||||
|               $data->{flags}->{'meteoalarm-license'}; | ||||
|             $self->{cached}->{current} = { | ||||
|                 'temperature' => int( | ||||
|                     sprintf( "%.1f", $data->{currently}->{temperature} ) + 0.5 | ||||
| @@ -252,120 +269,120 @@ sub _ProcessingRetrieveData($$) { | ||||
|                         { | ||||
|                             'date' => strftime( | ||||
|                                 "%a, %d.%m.%Y", | ||||
|                                 localtime( $data->{daily}->{data}->[$i]->{'time'} ) | ||||
|                                 localtime( | ||||
|                                     $data->{daily}->{data}->[$i]->{'time'} | ||||
|                                 ) | ||||
|                             ), | ||||
|                             'day_of_week' => strftime( | ||||
|                                 "%a", | ||||
|                                 localtime( $data->{daily}->{data}->[$i]->{'time'} ) | ||||
|                                 localtime( | ||||
|                                     $data->{daily}->{data}->[$i]->{'time'} | ||||
|                                 ) | ||||
|                             ), | ||||
|                             'low_c' => int( | ||||
|                                 sprintf( "%.1f", | ||||
|                                     $data->{daily}->{data}->[$i]->{temperatureLow} ) | ||||
|                                   + 0.5 | ||||
|                                     $data->{daily}->{data}->[$i] | ||||
|                                       ->{temperatureLow} ) + 0.5 | ||||
|                             ), | ||||
|                             'high_c' => int( | ||||
|                                 sprintf( "%.1f", | ||||
|                                     $data->{daily}->{data}->[$i]->{temperatureHigh} | ||||
|                                 ) + 0.5 | ||||
|                                     $data->{daily}->{data}->[$i] | ||||
|                                       ->{temperatureHigh} ) + 0.5 | ||||
|                             ), | ||||
|                             'tempMin' => int( | ||||
|                                 sprintf( "%.1f", | ||||
|                                     $data->{daily}->{data}->[$i]->{temperatureMin} ) | ||||
|                                   + 0.5 | ||||
|                                     $data->{daily}->{data}->[$i] | ||||
|                                       ->{temperatureMin} ) + 0.5 | ||||
|                             ), | ||||
|                             'tempMinTime' => strftime( | ||||
|                                 "%a,%e %b %Y %H:%M %p", | ||||
|                                 localtime( | ||||
|                                     $data->{daily} | ||||
|                                       ->{data}->[$i]->{temperatureMinTime} | ||||
|                                     $data->{daily}->{data}->[$i] | ||||
|                                       ->{temperatureMinTime} | ||||
|                                 ) | ||||
|                             ), | ||||
|                             'tempMax' => int( | ||||
|                                 sprintf( "%.1f", | ||||
|                                     $data->{daily}->{data}->[$i]->{temperatureMax} ) | ||||
|                                   + 0.5 | ||||
|                                     $data->{daily}->{data}->[$i] | ||||
|                                       ->{temperatureMax} ) + 0.5 | ||||
|                             ), | ||||
|                             'tempMaxTime' => strftime( | ||||
|                                 "%a,%e %b %Y %H:%M %p", | ||||
|                                 localtime( | ||||
|                                     $data->{daily} | ||||
|                                       ->{data}->[$i]->{temperatureMaxTime} | ||||
|                                     $data->{daily}->{data}->[$i] | ||||
|                                       ->{temperatureMaxTime} | ||||
|                                 ) | ||||
|                             ), | ||||
|                             'tempLow' => int( | ||||
|                                 sprintf( "%.1f", | ||||
|                                     $data->{daily}->{data}->[$i]->{temperatureLow} ) | ||||
|                                   + 0.5 | ||||
|                                     $data->{daily}->{data}->[$i] | ||||
|                                       ->{temperatureLow} ) + 0.5 | ||||
|                             ), | ||||
|                             'tempLowTime' => strftime( | ||||
|                                 "%a,%e %b %Y %H:%M %p", | ||||
|                                 localtime( | ||||
|                                     $data->{daily} | ||||
|                                       ->{data}->[$i]->{temperatureLowTime} | ||||
|                                     $data->{daily}->{data}->[$i] | ||||
|                                       ->{temperatureLowTime} | ||||
|                                 ) | ||||
|                             ), | ||||
|                             'tempHigh' => int( | ||||
|                                 sprintf( "%.1f", | ||||
|                                     $data->{daily}->{data}->[$i]->{temperatureHigh} | ||||
|                                 ) + 0.5 | ||||
|                                     $data->{daily}->{data}->[$i] | ||||
|                                       ->{temperatureHigh} ) + 0.5 | ||||
|                             ), | ||||
|                             'tempHighTime' => strftime( | ||||
|                                 "%a,%e %b %Y %H:%M %p", | ||||
|                                 localtime( | ||||
|                                     $data->{daily} | ||||
|                                       ->{data}->[$i]->{temperatureHighTime} | ||||
|                                     $data->{daily}->{data}->[$i] | ||||
|                                       ->{temperatureHighTime} | ||||
|                                 ) | ||||
|                             ), | ||||
|                             'apparentTempLow' => int( | ||||
|                                 sprintf( "%.1f", | ||||
|                                     $data->{daily} | ||||
|                                       ->{data}->[$i]->{apparentTemperatureLow} ) + | ||||
|                                   0.5 | ||||
|                                     $data->{daily}->{data}->[$i] | ||||
|                                       ->{apparentTemperatureLow} ) + 0.5 | ||||
|                             ), | ||||
|                             'apparentTempLowTime' => strftime( | ||||
|                                 "%a,%e %b %Y %H:%M %p", | ||||
|                                 localtime( | ||||
|                                     $data->{daily} | ||||
|                                       ->{data}->[$i]->{apparentTemperatureLowTime} | ||||
|                                     $data->{daily}->{data}->[$i] | ||||
|                                       ->{apparentTemperatureLowTime} | ||||
|                                 ) | ||||
|                             ), | ||||
|                             'apparentTempHigh' => int( | ||||
|                                 sprintf( "%.1f", | ||||
|                                     $data->{daily} | ||||
|                                       ->{data}->[$i]->{apparentTemperatureHigh} ) + | ||||
|                                   0.5 | ||||
|                                     $data->{daily}->{data}->[$i] | ||||
|                                       ->{apparentTemperatureHigh} ) + 0.5 | ||||
|                             ), | ||||
|                             'apparentTempHighTime' => strftime( | ||||
|                                 "%a,%e %b %Y %H:%M %p", | ||||
|                                 localtime( | ||||
|                                     $data->{daily} | ||||
|                                       ->{data}->[$i]->{apparentTemperatureHighTime} | ||||
|                                     $data->{daily}->{data}->[$i] | ||||
|                                       ->{apparentTemperatureHighTime} | ||||
|                                 ) | ||||
|                             ), | ||||
|                             'apparenttempMin' => int( | ||||
|                                 sprintf( "%.1f", | ||||
|                                     $data->{daily} | ||||
|                                       ->{data}->[$i]->{apparentTemperatureMin} ) + | ||||
|                                   0.5 | ||||
|                                     $data->{daily}->{data}->[$i] | ||||
|                                       ->{apparentTemperatureMin} ) + 0.5 | ||||
|                             ), | ||||
|                             'apparenttempMinTime' => strftime( | ||||
|                                 "%a,%e %b %Y %H:%M %p", | ||||
|                                 localtime( | ||||
|                                     $data->{daily} | ||||
|                                       ->{data}->[$i]->{apparentTemperatureMinTime} | ||||
|                                     $data->{daily}->{data}->[$i] | ||||
|                                       ->{apparentTemperatureMinTime} | ||||
|                                 ) | ||||
|                             ), | ||||
|                             'apparenttempMax' => int( | ||||
|                                 sprintf( "%.1f", | ||||
|                                     $data->{daily} | ||||
|                                       ->{data}->[$i]->{apparentTemperatureMax} ) + | ||||
|                                   0.5 | ||||
|                                     $data->{daily}->{data}->[$i] | ||||
|                                       ->{apparentTemperatureMax} ) + 0.5 | ||||
|                             ), | ||||
|                             'apparenttempMaxTime' => strftime( | ||||
|                                 "%a,%e %b %Y %H:%M %p", | ||||
|                                 localtime( | ||||
|                                     $data->{daily} | ||||
|                                       ->{data}->[$i]->{apparentTemperatureMaxTime} | ||||
|                                     $data->{daily}->{data}->[$i] | ||||
|                                       ->{apparentTemperatureMaxTime} | ||||
|                                 ) | ||||
|                             ), | ||||
|                             'code' => | ||||
| @@ -375,7 +392,8 @@ sub _ProcessingRetrieveData($$) { | ||||
|                                 $data->{daily}->{data}->[$i]->{summary} | ||||
|                             ), | ||||
|                             'ozone' => $data->{daily}->{data}->[$i]->{ozone}, | ||||
|                             'uvIndex' => $data->{daily}->{data}->[$i]->{uvIndex}, | ||||
|                             'uvIndex' => | ||||
|                               $data->{daily}->{data}->[$i]->{uvIndex}, | ||||
|                             'uvIndexTime' => strftime( | ||||
|                                 "%a,%e %b %Y %H:%M %p", | ||||
|                                 localtime( | ||||
| @@ -385,21 +403,22 @@ sub _ProcessingRetrieveData($$) { | ||||
|                             'precipIntensity' => | ||||
|                               $data->{daily}->{data}->[$i]->{precipIntensity}, | ||||
|                             'precipIntensityMax' => | ||||
|                               $data->{daily}->{data}->[$i]->{precipIntensityMax}, | ||||
|                               $data->{daily}->{data}->[$i] | ||||
|                               ->{precipIntensityMax}, | ||||
|                             'precipIntensityMaxTime' => strftime( | ||||
|                                 "%a,%e %b %Y %H:%M %p", | ||||
|                                 localtime( | ||||
|                                     $data->{daily} | ||||
|                                       ->{data}->[$i]->{precipIntensityMaxTime} | ||||
|                                     $data->{daily}->{data}->[$i] | ||||
|                                       ->{precipIntensityMaxTime} | ||||
|                                 ) | ||||
|                             ), | ||||
|                             'dewPoint' => int( | ||||
|                                 sprintf( "%.1f", | ||||
|                                     $data->{daily}->{data}->[$i]->{dewPoint} | ||||
|                                     ) + 0.5 | ||||
|                                     $data->{daily}->{data}->[$i]->{dewPoint} ) | ||||
|                                   + 0.5 | ||||
|                             ), | ||||
|                             'humidity' => $data->{daily}->{data}->[$i]->{humidity} | ||||
|                               * 100, | ||||
|                             'humidity' => | ||||
|                               $data->{daily}->{data}->[$i]->{humidity} * 100, | ||||
|                             'cloudCover' => | ||||
|                               $data->{daily}->{data}->[$i]->{cloudCover} * 100, | ||||
|                             'precipType' => | ||||
| @@ -409,17 +428,18 @@ sub _ProcessingRetrieveData($$) { | ||||
|                               $data->{daily}->{data}->[$i]->{windBearing}, | ||||
|                             'wind' => int( | ||||
|                                 sprintf( "%.1f", | ||||
|                                     $data->{daily}->{data}->[$i]->{windSpeed} | ||||
|                                     ) + 0.5 | ||||
|                                     $data->{daily}->{data}->[$i]->{windSpeed} ) | ||||
|                                   + 0.5 | ||||
|                             ), | ||||
|                             'wind_speed' => int( | ||||
|                                 sprintf( "%.1f", | ||||
|                                     $data->{daily}->{data}->[$i]->{windSpeed} | ||||
|                                     ) + 0.5 | ||||
|                                     $data->{daily}->{data}->[$i]->{windSpeed} ) | ||||
|                                   + 0.5 | ||||
|                             ), | ||||
|                             'windGust' => int( | ||||
|                                 sprintf( "%.1f", | ||||
|                                     $data->{daily}->{data}->[$i]->{windGust}) + 0.5 | ||||
|                                     $data->{daily}->{data}->[$i]->{windGust} ) | ||||
|                                   + 0.5 | ||||
|                             ), | ||||
|                             'windGustTime' => strftime( | ||||
|                                 "%a,%e %b %Y %H:%M %p", | ||||
| @@ -446,11 +466,13 @@ sub _ProcessingRetrieveData($$) { | ||||
|                               $data->{daily}->{data}->[$i]->{precipProbability}, | ||||
|                             'pressure' => int( | ||||
|                                 sprintf( "%.1f", | ||||
|                                     $data->{daily}->{data}->[$i]->{pressure}) + 0.5 | ||||
|                                     $data->{daily}->{data}->[$i]->{pressure} ) | ||||
|                                   + 0.5 | ||||
|                             ), | ||||
|                             'visibility' => int( | ||||
|                                 sprintf( "%.1f", | ||||
|                                     $data->{daily}->{data}->[$i]->{visibility}) + 0.5 | ||||
|                                     $data->{daily}->{data}->[$i]->{visibility} ) | ||||
|                                   + 0.5 | ||||
|                             ), | ||||
|                         } | ||||
|                     ); | ||||
|   | ||||
| @@ -115,8 +115,18 @@ sub new { | ||||
|  | ||||
|     my $self = { | ||||
|         devName => $argsRef->{devName}, | ||||
|         key => ( defined( $argsRef->{apikey} ) ? $argsRef->{apikey} : 'none' ), | ||||
|         cachemaxage => ( (split(':',$argsRef->{apioptions}))[0] eq 'cachemaxage' ? (split(':',$argsRef->{apioptions}))[1] : 900 ), | ||||
|         key     => ( | ||||
|             ( defined( $argsRef->{apikey} ) and $argsRef->{apikey} ) | ||||
|             ? $argsRef->{apikey} | ||||
|             : 'none' | ||||
|         ), | ||||
|         cachemaxage => ( | ||||
|             ( defined( $argsRef->{apioptions} ) and $argsRef->{apioptions} ) | ||||
|             ? ( ( split( ':', $argsRef->{apioptions} ) )[0] eq 'cachemaxage' | ||||
|                 ? ( split( ':', $argsRef->{apioptions} ) )[1] | ||||
|                 : 900 ) | ||||
|             : 900 | ||||
|         ), | ||||
|         lang      => $argsRef->{language}, | ||||
|         lat       => ( split( ',', $argsRef->{location} ) )[0], | ||||
|         long      => ( split( ',', $argsRef->{location} ) )[1], | ||||
| @@ -161,8 +171,7 @@ sub _RetrieveDataFromOpenWeatherMap($) { | ||||
|  | ||||
|     # retrieve data from cache | ||||
|     if ( $self->{endpoint} eq 'none' ) { | ||||
|         if ( ( time() - $self->{fetchTime} ) < $self->{cachemaxage} ) | ||||
|         { | ||||
|         if ( ( time() - $self->{fetchTime} ) < $self->{cachemaxage} ) { | ||||
|             return _CallWeatherCallbackFn($self); | ||||
|         } | ||||
|     } | ||||
| @@ -229,23 +238,30 @@ sub _RetrieveDataFinished($$$) { | ||||
| sub _ProcessingRetrieveData($$) { | ||||
|     my ( $self, $response ) = @_; | ||||
|  | ||||
|     if ( $self->{cached}->{status} eq 'ok' and defined($response) ) { | ||||
|     if (    $self->{cached}->{status} eq 'ok' | ||||
|         and defined($response) | ||||
|         and $response ) | ||||
|     { | ||||
|         my $data = eval { decode_json($response) }; | ||||
|  | ||||
|         if ($@) { | ||||
|             _ErrorHandling( $self, | ||||
|                 'OpenWeatherMap Weather decode JSON err ' . $@ ); | ||||
|         } | ||||
|         elsif ( defined( $data->{cod} ) and $data->{cod} != 200 and defined( $data->{message} ) ) { | ||||
|         elsif ( defined( $data->{cod} ) | ||||
|             and $data->{cod} | ||||
|             and $data->{cod} != 200 | ||||
|             and defined( $data->{message} ) | ||||
|             and $data->{message} ) | ||||
|         { | ||||
|             _ErrorHandling( $self, $data->{cod} . ': ' . $data->{message} ); | ||||
|         } | ||||
|         else { | ||||
|  | ||||
|             ###### Ab hier wird die ResponseHash Referenze für die Rückgabe zusammen gestellt | ||||
|             $self->{cached}->{current_date_time} = strftime( | ||||
|                 "%a,%e %b %Y %H:%M %p", | ||||
|                 localtime( $self->{fetchTime} ) | ||||
|             ); | ||||
|             $self->{cached}->{current_date_time} = | ||||
|               strftime( "%a,%e %b %Y %H:%M %p", | ||||
|                 localtime( $self->{fetchTime} ) ); | ||||
|  | ||||
|             if ( $self->{endpoint} eq 'weather' ) { | ||||
|                 $self->{cached}->{country}       = $data->{sys}->{country}; | ||||
| @@ -253,42 +269,42 @@ sub _ProcessingRetrieveData($$) { | ||||
|                 $self->{cached}->{license}{text} = 'none'; | ||||
|                 $self->{cached}->{current}       = { | ||||
|                     'temperature' => int( | ||||
|                         sprintf( "%.1f", ( $data->{main}->{temp} - 273.15 ) | ||||
|                         ) + 0.5 | ||||
|                         sprintf( "%.1f", ( $data->{main}->{temp} - 273.15 ) ) + | ||||
|                           0.5 | ||||
|                     ), | ||||
|                     'temp_c' => int( | ||||
|                         sprintf( "%.1f", ( $data->{main}->{temp} - 273.15 ) | ||||
|                         ) + 0.5 | ||||
|                         sprintf( "%.1f", ( $data->{main}->{temp} - 273.15 ) ) + | ||||
|                           0.5 | ||||
|                     ), | ||||
|                     'low_c' => int( | ||||
|                         sprintf( "%.1f", ( $data->{main}->{temp_min} - 273.15 ) | ||||
|                         ) + 0.5 | ||||
|                         sprintf( "%.1f", | ||||
|                             ( $data->{main}->{temp_min} - 273.15 ) ) + 0.5 | ||||
|                     ), | ||||
|                     'high_c' => int( | ||||
|                         sprintf( "%.1f", ( $data->{main}->{temp_max} - 273.15 ) | ||||
|                         ) + 0.5 | ||||
|                         sprintf( "%.1f", | ||||
|                             ( $data->{main}->{temp_max} - 273.15 ) ) + 0.5 | ||||
|                     ), | ||||
|                     'tempLow' => int( | ||||
|                         sprintf( "%.1f", ( $data->{main}->{temp_min} - 273.15 ) | ||||
|                         ) + 0.5 | ||||
|                         sprintf( "%.1f", | ||||
|                             ( $data->{main}->{temp_min} - 273.15 ) ) + 0.5 | ||||
|                     ), | ||||
|                     'tempHigh' => int( | ||||
|                         sprintf( "%.1f", ( $data->{main}->{temp_max} - 273.15 )  | ||||
|                         ) + 0.5 | ||||
|                         sprintf( "%.1f", | ||||
|                             ( $data->{main}->{temp_max} - 273.15 ) ) + 0.5 | ||||
|                     ), | ||||
|                     'humidity' => $data->{main}->{humidity}, | ||||
|                     'condition'  => encode_utf8( $data->{weather}->[0]->{description} ), | ||||
|                     'pressure'   => int(sprintf( "%.1f", | ||||
|                             $data->{main}->{pressure}) + 0.5 | ||||
|                     ), | ||||
|                     'wind'       => int(sprintf( "%.1f", | ||||
|                             $data->{wind}->{speed}) + 0.5 ), | ||||
|                     'wind_speed' => int(sprintf( "%.1f", | ||||
|                             $data->{wind}->{speed}) + 0.5 ), | ||||
|                     'condition' => | ||||
|                       encode_utf8( $data->{weather}->[0]->{description} ), | ||||
|                     'pressure' => | ||||
|                       int( sprintf( "%.1f", $data->{main}->{pressure} ) + 0.5 ), | ||||
|                     'wind' => | ||||
|                       int( sprintf( "%.1f", $data->{wind}->{speed} ) + 0.5 ), | ||||
|                     'wind_speed' => | ||||
|                       int( sprintf( "%.1f", $data->{wind}->{speed} ) + 0.5 ), | ||||
|                     'wind_direction' => $data->{wind}->{deg}, | ||||
|                     'cloudCover'     => $data->{clouds}->{all}, | ||||
|                     'visibility'     => int(sprintf( "%.1f", | ||||
|                             $data->{visibility}) + 0.5 ), | ||||
|                     'visibility' => | ||||
|                       int( sprintf( "%.1f", $data->{visibility} ) + 0.5 ), | ||||
|                     'code'       => $codes{ $data->{weather}->[0]->{id} }, | ||||
|                     'iconAPI'    => $data->{weather}->[0]->{icon}, | ||||
|                     'sunsetTime' => strftime( | ||||
| @@ -299,8 +315,10 @@ sub _ProcessingRetrieveData($$) { | ||||
|                         "%a,%e %b %Y %H:%M %p", | ||||
|                         localtime( $data->{sys}->{sunrise} ) | ||||
|                     ), | ||||
|                     'pubDate' => | ||||
|                     strftime( "%a,%e %b %Y %H:%M %p", localtime( $data->{dt} ) ), | ||||
|                     'pubDate' => strftime( | ||||
|                         "%a,%e %b %Y %H:%M %p", | ||||
|                         localtime( $data->{dt} ) | ||||
|                     ), | ||||
|                 }; | ||||
|             } | ||||
|  | ||||
| @@ -317,48 +335,93 @@ sub _ProcessingRetrieveData($$) { | ||||
|                             @{ $self->{cached}->{forecast}->{hourly} }, | ||||
|                             { | ||||
|                                 'temperature' => int( | ||||
|                                     sprintf( "%.1f", ( $data->{list}->[$i]->{main}->{temp} - 273.15 ) | ||||
|                                     sprintf( | ||||
|                                         "%.1f", | ||||
|                                         ( | ||||
|                                             $data->{list}->[$i]->{main}->{temp} | ||||
|                                               - 273.15 | ||||
|                                         ) | ||||
|                                     ) + 0.5 | ||||
|                                 ), | ||||
|                                 'temp_c' => int( | ||||
|                                     sprintf( "%.1f", ( $data->{list}->[$i]->{main}->{temp} - 273.15 ) | ||||
|                                     sprintf( | ||||
|                                         "%.1f", | ||||
|                                         ( | ||||
|                                             $data->{list}->[$i]->{main}->{temp} | ||||
|                                               - 273.15 | ||||
|                                         ) | ||||
|                                     ) + 0.5 | ||||
|                                 ), | ||||
|                                 'low_c' => int( | ||||
|                                     sprintf( "%.1f", ( $data->{list}->[$i]->{main}->{temp_min} - 273.15 ) | ||||
|                                     sprintf( | ||||
|                                         "%.1f", | ||||
|                                         ( | ||||
|                                             $data->{list}->[$i]->{main} | ||||
|                                               ->{temp_min} - 273.15 | ||||
|                                         ) | ||||
|                                     ) + 0.5 | ||||
|                                 ), | ||||
|                                 'high_c' => int( | ||||
|                                     sprintf( "%.1f", ( $data->{list}->[$i]->{main}->{temp_max} - 273.15 ) | ||||
|                                     sprintf( | ||||
|                                         "%.1f", | ||||
|                                         ( | ||||
|                                             $data->{list}->[$i]->{main} | ||||
|                                               ->{temp_max} - 273.15 | ||||
|                                         ) | ||||
|                                     ) + 0.5 | ||||
|                                 ), | ||||
|                                 'tempLow' => int( | ||||
|                                     sprintf( "%.1f", ( $data->{list}->[$i]->{main}->{temp_min} - 273.15 ) | ||||
|                                     sprintf( | ||||
|                                         "%.1f", | ||||
|                                         ( | ||||
|                                             $data->{list}->[$i]->{main} | ||||
|                                               ->{temp_min} - 273.15 | ||||
|                                         ) | ||||
|                                     ) + 0.5 | ||||
|                                 ), | ||||
|                                 'tempHigh' => int( | ||||
|                                     sprintf( "%.1f", ( $data->{list}->[$i]->{main}->{temp_max} - 273.15 ) | ||||
|                                     sprintf( | ||||
|                                         "%.1f", | ||||
|                                         ( | ||||
|                                             $data->{list}->[$i]->{main} | ||||
|                                               ->{temp_max} - 273.15 | ||||
|                                         ) | ||||
|                                     ) + 0.5 | ||||
|                                 ), | ||||
|                                 'humidity'   => $data->{list}->[$i]->{main}->{humidity}, | ||||
|                                 'condition'  => encode_utf8( $data->{list}->[$i]->{weather}->[0]->{description} ), | ||||
|                                 'pressure'   => int(sprintf( "%.1f", | ||||
|                                         $data->{list}->[$i]->{main}->{pressure}) | ||||
|                                 'humidity' => | ||||
|                                   $data->{list}->[$i]->{main}->{humidity}, | ||||
|                                 'condition' => encode_utf8( | ||||
|                                     $data->{list}->[$i]->{weather}->[0] | ||||
|                                       ->{description} | ||||
|                                 ), | ||||
|                                 'pressure' => int( | ||||
|                                     sprintf( "%.1f", | ||||
|                                         $data->{list}->[$i]->{main}->{pressure} | ||||
|                                     ) + 0.5 | ||||
|                                 ), | ||||
|                                 'wind' => int( | ||||
|                                     sprintf( "%.1f", | ||||
|                                         $data->{list}->[$i]->{wind}->{speed} ) | ||||
|                                       + 0.5 | ||||
|                                 ), | ||||
|                                 'wind'       => int(sprintf( "%.1f", | ||||
|                                         $data->{list}->[$i]->{wind}->{speed} | ||||
|                                         )  + 0.5 | ||||
|                                 'wind_speed' => int( | ||||
|                                     sprintf( "%.1f", | ||||
|                                         $data->{list}->[$i]->{wind}->{speed} ) | ||||
|                                       + 0.5 | ||||
|                                 ), | ||||
|                                 'wind_speed' => int(sprintf( "%.1f", | ||||
|                                         $data->{list}->[$i]->{wind}->{speed} | ||||
|                                         )  + 0.5 | ||||
|                                 'cloudCover' => | ||||
|                                   $data->{list}->[$i]->{clouds}->{all}, | ||||
|                                 'code' => | ||||
|                                   $codes{ $data->{list}->[$i]->{weather}->[0] | ||||
|                                       ->{id} }, | ||||
|                                 'iconAPI' => | ||||
|                                   $data->{list}->[$i]->{weather}->[0]->{icon}, | ||||
|                                 'pubDate' => strftime( | ||||
|                                     "%a,%e %b %Y %H:%M %p", | ||||
|                                     localtime( | ||||
|                                         ( $data->{list}->[$i]->{dt} ) - 3600 | ||||
|                                     ) | ||||
|                                 ), | ||||
|                                 'cloudCover'     => $data->{list}->[$i]->{clouds}->{all}, | ||||
|                                 'code'           => $codes{ $data->{list}->[$i]->{weather}->[0]->{id} }, | ||||
|                                 'iconAPI'    => $data->{list}->[$i]->{weather}->[0]->{icon}, | ||||
|                                 'pubDate' => | ||||
|                                     strftime( "%a,%e %b %Y %H:%M %p", localtime( ($data->{list}->[$i]->{dt}) - 3600 ) ), | ||||
|                             }, | ||||
|                         ); | ||||
|  | ||||
| @@ -379,6 +442,7 @@ sub _ProcessingRetrieveData($$) { | ||||
|  | ||||
| sub _CallWeatherCallbackFn($) { | ||||
|     my $self = shift; | ||||
|  | ||||
|     #     print 'Dumperausgabe: ' . Dumper $self; | ||||
|     ### Aufruf der callbackFn | ||||
|     main::Weather_RetrieveCallbackFn( $self->{devName} ); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user