fix write Hash then ref current not present

This commit is contained in:
Marko Oldenburg 2019-01-09 12:17:10 +01:00
parent 209cde6abb
commit 49a292cc50
3 changed files with 410 additions and 293 deletions

View File

@ -369,9 +369,11 @@ sub Weather_WriteReadings($$) {
# current # current
if ( ref( $dataRef->{current} ) eq 'HASH' ) {
while( my ($r,$v) = each %{$dataRef->{current}} ) { while( my ($r,$v) = each %{$dataRef->{current}} ) {
readingsBulkUpdate($hash, $r, $v); readingsBulkUpdate($hash, $r, $v);
} }
readingsBulkUpdate($hash, 'icon', $iconlist[$dataRef->{current}{code}]); readingsBulkUpdate($hash, 'icon', $iconlist[$dataRef->{current}{code}]);
if ( defined($dataRef->{current}{wind_direction}) if ( defined($dataRef->{current}{wind_direction})
and defined($dataRef->{current}{wind_speed} ) ) and defined($dataRef->{current}{wind_speed} ) )
@ -379,6 +381,7 @@ sub Weather_WriteReadings($$) {
my $wdir= degrees_to_direction($dataRef->{current}{wind_direction}, @directions_txt_i18n); my $wdir= degrees_to_direction($dataRef->{current}{wind_direction}, @directions_txt_i18n);
readingsBulkUpdate($hash, 'wind_condition', 'Wind: ' . $wdir . ' ' . $dataRef->{current}{wind_speed} . ' km/h'); readingsBulkUpdate($hash, 'wind_condition', 'Wind: ' . $wdir . ' ' . $dataRef->{current}{wind_speed} . ' km/h');
} }
}
# forecast # forecast
if ( ref( $dataRef->{forcast} ) eq 'HASH' ) { if ( ref( $dataRef->{forcast} ) eq 'HASH' ) {
@ -413,6 +416,7 @@ sub Weather_WriteReadings($$) {
} }
} }
} }
my $val= 'T:' . $dataRef->{current}{temperature} . '°C' my $val= 'T:' . $dataRef->{current}{temperature} . '°C'
.' ' . substr($status_items_txt_i18n{1}, 0, 1) . ':' . $dataRef->{current}{humidity} . '%' .' ' . substr($status_items_txt_i18n{1}, 0, 1) . ':' . $dataRef->{current}{humidity} . '%'
.' ' . substr($status_items_txt_i18n{0}, 0, 1) . ':' . $dataRef->{current}{wind} . 'km/h' .' ' . substr($status_items_txt_i18n{0}, 0, 1) . ':' . $dataRef->{current}{wind} . 'km/h'

View File

@ -126,12 +126,15 @@ sub _RetrieveDataFromDarkSky($) {
or $self->{key} eq 'none' or $self->{key} eq 'none'
or $missingModul ) or $missingModul )
{ {
_RetrieveDataFinished( $paramRef, _RetrieveDataFinished(
$paramRef,
'The given location is invalid. (wrong latitude or longitude?) put both as an attribute in the global device or set define option location=[LAT],[LONG]', 'The given location is invalid. (wrong latitude or longitude?) put both as an attribute in the global device or set define option location=[LAT],[LONG]',
undef ) undef
if ( $self->{lat} eq 'error' or $self->{long} eq 'error' ); ) if ( $self->{lat} eq 'error' or $self->{long} eq 'error' );
_RetrieveDataFinished( $paramRef, 'No given api key. (define myWeather Weather apikey=[KEY])', undef ) _RetrieveDataFinished( $paramRef,
'No given api key. (define myWeather Weather apikey=[KEY])',
undef )
if ( $self->{key} eq 'none' ); if ( $self->{key} eq 'none' );
_RetrieveDataFinished( $paramRef, _RetrieveDataFinished( $paramRef,
@ -158,8 +161,7 @@ sub _RetrieveDataFinished($$$) {
if ( !$err ) { if ( !$err ) {
$self->{cached}->{status} = 'ok'; $self->{cached}->{status} = 'ok';
$self->{cached}->{validity} = 'up-to-date', $self->{cached}->{validity} = 'up-to-date', $self->{fetchTime} = time();
$self->{fetchTime} = time();
_ProcessingRetrieveData( $self, $response ); _ProcessingRetrieveData( $self, $response );
} }
else { else {
@ -172,29 +174,37 @@ sub _RetrieveDataFinished($$$) {
sub _ProcessingRetrieveData($$) { sub _ProcessingRetrieveData($$) {
my ( $self, $response ) = @_; my ( $self, $response ) = @_;
if ( $self->{cached}->{status} eq 'ok' and defined($response) ) if ( $self->{cached}->{status} eq 'ok' and defined($response) ) {
{
my $data = eval { decode_json($response) }; my $data = eval { decode_json($response) };
if ($@) { if ($@) {
_ErrorHandling( $self, 'DarkSky Weather decode JSON err ' . $@ ); _ErrorHandling( $self, 'DarkSky Weather decode JSON err ' . $@ );
} }
elsif ( defined( $data->{code} ) and defined( $data->{error} ) ) { elsif ( defined( $data->{code} ) and defined( $data->{error} ) ) {
_ErrorHandling( $self, 'Code: ' . $data->{code} . ' Error: ' . $data->{error} ); _ErrorHandling( $self,
'Code: ' . $data->{code} . ' Error: ' . $data->{error} );
} }
else { else {
# print Dumper $data; ## für Debugging # 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}->{timezone} = $data->{timezone};
$self->{cached}->{license} = $data->{flags}->{'meteoalarm-license'}; $self->{cached}->{license} = $data->{flags}->{'meteoalarm-license'};
$self->{cached}->{current} = { $self->{cached}->{current} = {
'temperature' => int(sprintf("%.1f",$data->{currently}->{temperature}) + 0.5), 'temperature' => int(
'temp_c' => int(sprintf("%.1f",$data->{currently}->{temperature}) + 0.5), sprintf( "%.1f", $data->{currently}->{temperature} ) + 0.5
'dewPoint' => int(sprintf("%.1f",$data->{currently}->{dewPoint}) + 0.5), ),
'temp_c' => int(
sprintf( "%.1f", $data->{currently}->{temperature} ) + 0.5
),
'dewPoint' => int(
sprintf( "%.1f", $data->{currently}->{dewPoint} ) + 0.5
),
'humidity' => $data->{currently}->{humidity} * 100, 'humidity' => $data->{currently}->{humidity} * 100,
'condition' => 'condition' => encode_utf8( $data->{currently}->{summary} ),
encode_utf8( $data->{currently}->{summary} ),
'pressure' => $data->{currently}->{pressure}, 'pressure' => $data->{currently}->{pressure},
'wind' => $data->{currently}->{windSpeed}, 'wind' => $data->{currently}->{windSpeed},
'wind_speed' => $data->{currently}->{windSpeed}, 'wind_speed' => $data->{currently}->{windSpeed},
@ -210,12 +220,13 @@ sub _ProcessingRetrieveData($$) {
"%a,%e %b %Y %H:%M %p", "%a,%e %b %Y %H:%M %p",
localtime( $data->{currently}->{'time'} ) localtime( $data->{currently}->{'time'} )
), ),
'precipProbability' => 'precipProbability' => $data->{currently}->{precipProbability},
$data->{currently}->{precipProbability}, 'apparentTemperature' => int(
'apparentTemperature' => sprintf(
int(sprintf("%.1f",$data->{currently}->{apparentTemperature}) + 0.5), "%.1f", $data->{currently}->{apparentTemperature}
'precipIntensity' => ) + 0.5
$data->{currently}->{precipIntensity}, ),
'precipIntensity' => $data->{currently}->{precipIntensity},
}; };
my $i = 0; my $i = 0;
@ -223,7 +234,8 @@ sub _ProcessingRetrieveData($$) {
and scalar( @{ $data->{daily}->{data} } ) > 0 ) and scalar( @{ $data->{daily}->{data} } ) > 0 )
{ {
foreach ( @{ $data->{daily}->{data} } ) { foreach ( @{ $data->{daily}->{data} } ) {
push (@{$self->{cached}->{forcast}->{daily}}, push(
@{ $self->{cached}->{forcast}->{daily} },
{ {
'date' => strftime( 'date' => strftime(
"%a, %d.%m.%Y", "%a, %d.%m.%Y",
@ -233,81 +245,122 @@ sub _ProcessingRetrieveData($$) {
"%a", "%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), 'low_c' => int(
'high_c' => sprintf( "%.1f",
int(sprintf("%.1f",$data->{daily}->{data}[$i]{temperatureHigh}) + 0.5), $data->{daily}->{data}[$i]{temperatureLow} )
'tempMin' => + 0.5
int(sprintf("%.1f",$data->{daily}->{data}[$i]{temperatureMin}) + 0.5), ),
'high_c' => int(
sprintf( "%.1f",
$data->{daily}->{data}[$i]{temperatureHigh}
) + 0.5
),
'tempMin' => int(
sprintf( "%.1f",
$data->{daily}->{data}[$i]{temperatureMin} )
+ 0.5
),
'tempMinTime' => strftime( 'tempMinTime' => strftime(
"%a,%e %b %Y %H:%M %p", "%a,%e %b %Y %H:%M %p",
localtime( localtime(
$data->{daily}->{data}[$i]{temperatureMinTime} $data->{daily}
->{data}[$i]{temperatureMinTime}
) )
), ),
'tempMax' => 'tempMax' => int(
int(sprintf("%.1f",$data->{daily}->{data}[$i]{temperatureMax}) + 0.5), sprintf( "%.1f",
$data->{daily}->{data}[$i]{temperatureMax} )
+ 0.5
),
'tempMaxTime' => strftime( 'tempMaxTime' => strftime(
"%a,%e %b %Y %H:%M %p", "%a,%e %b %Y %H:%M %p",
localtime( localtime(
$data->{daily}->{data}[$i]{temperatureMaxTime} $data->{daily}
->{data}[$i]{temperatureMaxTime}
) )
), ),
'tempLow' => 'tempLow' => int(
int(sprintf("%.1f",$data->{daily}->{data}[$i]{temperatureLow}) + 0.5), sprintf( "%.1f",
$data->{daily}->{data}[$i]{temperatureLow} )
+ 0.5
),
'tempLowTime' => strftime( 'tempLowTime' => strftime(
"%a,%e %b %Y %H:%M %p", "%a,%e %b %Y %H:%M %p",
localtime( localtime(
$data->{daily}->{data}[$i]{temperatureLowTime} $data->{daily}
->{data}[$i]{temperatureLowTime}
) )
), ),
'tempHigh' => 'tempHigh' => int(
int(sprintf("%.1f",$data->{daily}->{data}[$i]{temperatureHigh}) + 0.5), sprintf( "%.1f",
$data->{daily}->{data}[$i]{temperatureHigh}
) + 0.5
),
'tempHighTime' => strftime( 'tempHighTime' => strftime(
"%a,%e %b %Y %H:%M %p", "%a,%e %b %Y %H:%M %p",
localtime( localtime(
$data->{daily}->{data}[$i]{temperatureHighTime} $data->{daily}
->{data}[$i]{temperatureHighTime}
) )
), ),
'apparentTempLow' => 'apparentTempLow' => int(
int(sprintf("%.1f",$data->{daily}->{data}[$i]{apparentTemperatureLow}) + 0.5), sprintf( "%.1f",
$data->{daily}
->{data}[$i]{apparentTemperatureLow} ) +
0.5
),
'apparentTempLowTime' => strftime( 'apparentTempLowTime' => strftime(
"%a,%e %b %Y %H:%M %p", "%a,%e %b %Y %H:%M %p",
localtime( localtime(
$data->{daily}->{data}[$i] $data->{daily}
{apparentTemperatureLowTime} ->{data}[$i]{apparentTemperatureLowTime}
) )
), ),
'apparentTempHigh' => 'apparentTempHigh' => int(
int(sprintf("%.1f",$data->{daily}->{data}[$i]{apparentTemperatureHigh}) + 0.5), sprintf( "%.1f",
$data->{daily}
->{data}[$i]{apparentTemperatureHigh} ) +
0.5
),
'apparentTempHighTime' => strftime( 'apparentTempHighTime' => strftime(
"%a,%e %b %Y %H:%M %p", "%a,%e %b %Y %H:%M %p",
localtime( localtime(
$data->{daily}->{data}[$i] $data->{daily}
{apparentTemperatureHighTime} ->{data}[$i]{apparentTemperatureHighTime}
) )
), ),
'apparenttempMin' => 'apparenttempMin' => int(
int(sprintf("%.1f",$data->{daily}->{data}[$i]{apparentTemperatureMin}) + 0.5), sprintf( "%.1f",
$data->{daily}
->{data}[$i]{apparentTemperatureMin} ) +
0.5
),
'apparenttempMinTime' => strftime( 'apparenttempMinTime' => strftime(
"%a,%e %b %Y %H:%M %p", "%a,%e %b %Y %H:%M %p",
localtime( localtime(
$data->{daily}->{data}[$i] $data->{daily}
{apparentTemperatureMinTime} ->{data}[$i]{apparentTemperatureMinTime}
) )
), ),
'apparenttempMax' => 'apparenttempMax' => int(
int(sprintf("%.1f",$data->{daily}->{data}[$i]{apparentTemperatureMax}) + 0.5), sprintf( "%.1f",
$data->{daily}
->{data}[$i]{apparentTemperatureMax} ) +
0.5
),
'apparenttempMaxTime' => strftime( 'apparenttempMaxTime' => strftime(
"%a,%e %b %Y %H:%M %p", "%a,%e %b %Y %H:%M %p",
localtime( localtime(
$data->{daily}->{data}[$i] $data->{daily}
{apparentTemperatureMaxTime} ->{data}[$i]{apparentTemperatureMaxTime}
) )
), ),
'code' => $codes{ $data->{daily}->{data}[$i]{icon} }, 'code' =>
$codes{ $data->{daily}->{data}[$i]{icon} },
'iconAPI' => $data->{daily}->{data}[$i]{icon}, 'iconAPI' => $data->{daily}->{data}[$i]{icon},
'condition' => 'condition' => encode_utf8(
encode_utf8( $data->{daily}->{data}[$i]{summary} ), $data->{daily}->{data}[$i]{summary}
),
'ozone' => $data->{daily}->{data}[$i]{ozone}, 'ozone' => $data->{daily}->{data}[$i]{ozone},
'uvIndex' => $data->{daily}->{data}[$i]{uvIndex}, 'uvIndex' => $data->{daily}->{data}[$i]{uvIndex},
'uvIndexTime' => strftime( 'uvIndexTime' => strftime(
@ -323,19 +376,23 @@ sub _ProcessingRetrieveData($$) {
'precipIntensityMaxTime' => strftime( 'precipIntensityMaxTime' => strftime(
"%a,%e %b %Y %H:%M %p", "%a,%e %b %Y %H:%M %p",
localtime( localtime(
$data->{daily}->{data}[$i] $data->{daily}
{precipIntensityMaxTime} ->{data}[$i]{precipIntensityMaxTime}
) )
), ),
'dewPoint' => $data->{daily}->{data}[$i]{dewPoint}, 'dewPoint' => $data->{daily}->{data}[$i]{dewPoint},
'humidity' => $data->{daily}->{data}[$i]{humidity} * 100, 'humidity' => $data->{daily}->{data}[$i]{humidity}
'cloudCover' => $data->{daily}->{data}[$i]{cloudCover}, * 100,
'precipType' => $data->{daily}->{data}[$i]{precipType}, 'cloudCover' =>
$data->{daily}->{data}[$i]{cloudCover},
'precipType' =>
$data->{daily}->{data}[$i]{precipType},
'wind_direction' => 'wind_direction' =>
$data->{daily}->{data}[$i]{windBearing}, $data->{daily}->{data}[$i]{windBearing},
'wind' => $data->{daily}->{data}[$i]{windSpeed}, 'wind' => $data->{daily}->{data}[$i]{windSpeed},
'wind_speed' => $data->{daily}->{data}[$i]{windSpeed}, 'wind_speed' =>
$data->{daily}->{data}[$i]{windSpeed},
'windGust' => $data->{daily}->{data}[$i]{windGust}, 'windGust' => $data->{daily}->{data}[$i]{windGust},
'windGustTime' => strftime( 'windGustTime' => strftime(
"%a,%e %b %Y %H:%M %p", "%a,%e %b %Y %H:%M %p",
@ -343,7 +400,8 @@ sub _ProcessingRetrieveData($$) {
$data->{daily}->{data}[$i]{windGustTime} $data->{daily}->{data}[$i]{windGustTime}
) )
), ),
'moonPhase' => $data->{daily}->{data}[$i]{moonPhase}, 'moonPhase' =>
$data->{daily}->{data}[$i]{moonPhase},
'sunsetTime' => strftime( 'sunsetTime' => strftime(
"%a,%e %b %Y %H:%M %p", "%a,%e %b %Y %H:%M %p",
localtime( localtime(
@ -360,8 +418,11 @@ sub _ProcessingRetrieveData($$) {
'precipProbability' => 'precipProbability' =>
$data->{daily}->{data}[$i]{precipProbability}, $data->{daily}->{data}[$i]{precipProbability},
'pressure' => $data->{daily}->{data}[$i]{pressure}, 'pressure' => $data->{daily}->{data}[$i]{pressure},
'visibility' => $data->{daily}->{data}[$i]{visibility}, 'visibility' =>
}); $data->{daily}->{data}[$i]{visibility},
}
);
$i++; $i++;
} }
} }
@ -382,7 +443,8 @@ sub _CallWeatherCallbackFn($) {
sub _ErrorHandling($$) { sub _ErrorHandling($$) {
my ( $self, $err ) = @_; my ( $self, $err ) = @_;
$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}->{status} = $err; $self->{cached}->{status} = $err;
$self->{cached}->{validity} = 'stale'; $self->{cached}->{validity} = 'stale';
} }
@ -394,7 +456,8 @@ sub _CreateForcastRef($) {
{ {
lat => $self->{lat}, lat => $self->{lat},
long => $self->{long}, long => $self->{long},
apiMaintainer => 'Leon Gaultier (<a href=https://forum.fhem.de/index.php?action=profile;u=13684>CoolTux</a>)', apiMaintainer =>
'Leon Gaultier (<a href=https://forum.fhem.de/index.php?action=profile;u=13684>CoolTux</a>)',
} }
); );

View File

@ -53,9 +53,35 @@ use constant URL => 'https://api.openweathermap.org/data/2.5/';
## URL . 'forcast?' for forcast data ## URL . 'forcast?' for forcast data
my %codes = ( my %codes = (
200 => 45, 201 => 45, 202 => 45, 210 => 4, 211 => 4, 212 => 3, 221 => 4, 230 => 45, 231 => 45, 232 => 45, 200 => 45,
300 => 9, 301 => 9, 302 => 9, 310 => 9, 311 => 9, 312 => 9, 313 => 9, 314 => 9, 321 => 9, 201 => 45,
500 => 35, 501 => 35, 502 => 35, 503 => 35, 504 => 35, 511 => 35, 520 => 35, 521 => 35, 522 => 35, 531 => 35, 202 => 45,
210 => 4,
211 => 4,
212 => 3,
221 => 4,
230 => 45,
231 => 45,
232 => 45,
300 => 9,
301 => 9,
302 => 9,
310 => 9,
311 => 9,
312 => 9,
313 => 9,
314 => 9,
321 => 9,
500 => 35,
501 => 35,
502 => 35,
503 => 35,
504 => 35,
511 => 35,
520 => 35,
521 => 35,
522 => 35,
531 => 35,
); );
sub new { sub new {
@ -127,12 +153,15 @@ sub _RetrieveDataFromOpenWeatherMap($) {
or $self->{key} eq 'none' or $self->{key} eq 'none'
or $missingModul ) or $missingModul )
{ {
_RetrieveDataFinished( $paramRef, _RetrieveDataFinished(
$paramRef,
'The given location is invalid. (wrong latitude or longitude?) put both as an attribute in the global device or set define option location=[LAT],[LONG]', 'The given location is invalid. (wrong latitude or longitude?) put both as an attribute in the global device or set define option location=[LAT],[LONG]',
undef ) undef
if ( $self->{lat} eq 'error' or $self->{long} eq 'error' ); ) if ( $self->{lat} eq 'error' or $self->{long} eq 'error' );
_RetrieveDataFinished( $paramRef, 'No given api key. (define myWeather Weather apikey=[KEY])', undef ) _RetrieveDataFinished( $paramRef,
'No given api key. (define myWeather Weather apikey=[KEY])',
undef )
if ( $self->{key} eq 'none' ); if ( $self->{key} eq 'none' );
_RetrieveDataFinished( $paramRef, _RetrieveDataFinished( $paramRef,
@ -142,14 +171,11 @@ sub _RetrieveDataFromOpenWeatherMap($) {
else { else {
$paramRef->{url} = $paramRef->{url} =
URL URL
. $paramRef->{endpoint} . '?' . $paramRef->{endpoint} . '?' . 'lat='
. 'lat=' . $self->{lat} . '&' . 'lon='
. $self->{lat} . '&'
. 'lon='
. $self->{long} . '&' . $self->{long} . '&'
. 'APPID=' . 'APPID='
. $self->{key} . '&' . $self->{key} . '&' . 'lang='
. 'lang='
. $self->{lang}; . $self->{lang};
main::HttpUtils_NonblockingGet($paramRef); main::HttpUtils_NonblockingGet($paramRef);
@ -162,8 +188,7 @@ sub _RetrieveDataFinished($$$) {
if ( !$err ) { if ( !$err ) {
$self->{cached}->{status} = 'ok'; $self->{cached}->{status} = 'ok';
$self->{cached}->{validity} = 'up-to-date', $self->{cached}->{validity} = 'up-to-date', $self->{fetchTime} = time();
$self->{fetchTime} = time();
_ProcessingRetrieveData( $self, $response ); _ProcessingRetrieveData( $self, $response );
} }
else { else {
@ -178,13 +203,14 @@ sub _RetrieveDataFinished($$$) {
sub _ProcessingRetrieveData($$) { sub _ProcessingRetrieveData($$) {
my ( $self, $response ) = @_; my ( $self, $response ) = @_;
if ( $self->{cached}->{status} eq 'ok' and defined($response) ) if ( $self->{cached}->{status} eq 'ok' and defined($response) ) {
{
my $data = eval { decode_json($response) }; my $data = eval { decode_json($response) };
# print 'Dumper1: ' . Dumper $data; # print 'Dumper1: ' . Dumper $data;
if ($@) { if ($@) {
_ErrorHandling( $self, 'OpenWeatherMap Weather decode JSON err ' . $@ ); _ErrorHandling( $self,
'OpenWeatherMap Weather decode JSON err ' . $@ );
} }
elsif ( defined( $data->{cod} ) and defined( $data->{message} ) ) { elsif ( defined( $data->{cod} ) and defined( $data->{message} ) ) {
print 'Dumper2: ' . Dumper $data; print 'Dumper2: ' . Dumper $data;
@ -194,41 +220,63 @@ sub _ProcessingRetrieveData($$) {
# print Dumper $data; ## für Debugging # print Dumper $data; ## für Debugging
return if ( $self->{endpoint} eq 'forcast' ); return if ( $self->{endpoint} eq 'forcast' );
$self->{cached}->{current_date_time} = strftime(
$self->{cached}->{current_date_time} = strftime("%a,%e %b %Y %H:%M %p",localtime( $self->{fetchTime} )), "%a,%e %b %Y %H:%M %p",
localtime( $self->{fetchTime} )
),
$self->{cached}->{country} = $data->{sys}->{country}; $self->{cached}->{country} = $data->{sys}->{country};
$self->{cached}->{city} = $data->{name}; $self->{cached}->{city} = $data->{name};
$self->{cached}->{current} = { $self->{cached}->{current} = {
'temperature' => int(sprintf("%.1f",($data->{main}->{temp} - 273.15 )) + 0.5), 'temperature' => int(
'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), ),
'high_c' => int(sprintf("%.1f",($data->{main}->{temp_max} - 273.15 )) + 0.5), 'temp_c' => int(
'tempLow' => int(sprintf("%.1f",($data->{main}->{temp_min} - 273.15 )) + 0.5), sprintf( "%.1f", ( $data->{main}->{temp} - 273.15 ) ) + 0.5
'tempHigh' => int(sprintf("%.1f",($data->{main}->{temp_max} - 273.15 )) + 0.5), ),
'low_c' => int(
sprintf( "%.1f", ( $data->{main}->{temp_min} - 273.15 ) ) +
0.5
),
'high_c' => int(
sprintf( "%.1f", ( $data->{main}->{temp_max} - 273.15 ) ) +
0.5
),
'tempLow' => int(
sprintf( "%.1f", ( $data->{main}->{temp_min} - 273.15 ) ) +
0.5
),
'tempHigh' => int(
sprintf( "%.1f", ( $data->{main}->{temp_max} - 273.15 ) ) +
0.5
),
'humidity' => $data->{main}->{humidity}, 'humidity' => $data->{main}->{humidity},
'condition' => 'condition' => encode_utf8( $data->{weather}[0]{description} ),
encode_utf8( $data->{weather}[0]{description} ),
'pressure' => $data->{main}->{pressure}, 'pressure' => $data->{main}->{pressure},
'wind' => $data->{wind}->{speed}, 'wind' => $data->{wind}->{speed},
'wind_speed' => $data->{wind}->{speed}, 'wind_speed' => $data->{wind}->{speed},
'wind_direction' => $data->{wind}->{deg}, 'wind_direction' => $data->{wind}->{deg},
'cloudCover' => $data->{clouds}->{all}, 'cloudCover' => $data->{clouds}->{all},
'visibility' => $data->{visibility}, 'visibility' => $data->{visibility},
# 'code' => $codes{ $data->{weather}[0]{icon} }, # 'code' => $codes{ $data->{weather}[0]{icon} },
'iconAPI' => $data->{weather}[0]{icon}, 'iconAPI' => $data->{weather}[0]{icon},
'sunsetTime' => strftime("%a,%e %b %Y %H:%M %p",localtime($data->{sys}->{sunset})), 'sunsetTime' => strftime(
'sunriseTime' => strftime("%a,%e %b %Y %H:%M %p",localtime($data->{sys}->{sunrise})),
'pubDate' => strftime(
"%a,%e %b %Y %H:%M %p", "%a,%e %b %Y %H:%M %p",
localtime( $data->{dt} ) localtime( $data->{sys}->{sunset} )
), ),
} if ( $self->{endpoint} eq 'weather' ); 'sunriseTime' => strftime(
"%a,%e %b %Y %H:%M %p",
localtime( $data->{sys}->{sunrise} )
),
'pubDate' =>
strftime( "%a,%e %b %Y %H:%M %p", localtime( $data->{dt} ) ),
}
if ( $self->{endpoint} eq 'weather' );
} }
} }
# $self->{cached} = $forcastRef; Vorsicht _RetrieveDataFromOpenWeatherMap($self)
if ( $self->{endpoint} eq 'weather' );
_RetrieveDataFromOpenWeatherMap($self) if ( $self->{endpoint} eq 'weather' );
$self->{endpoint} = 'none' if ( $self->{endpoint} eq 'forcast' ); $self->{endpoint} = 'none' if ( $self->{endpoint} eq 'forcast' );
_CallWeatherCallbackFn($self); _CallWeatherCallbackFn($self);
@ -244,7 +292,8 @@ sub _CallWeatherCallbackFn($) {
sub _ErrorHandling($$) { sub _ErrorHandling($$) {
my ( $self, $err ) = @_; my ( $self, $err ) = @_;
$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}->{status} = $err; $self->{cached}->{status} = $err;
$self->{cached}->{validity} = 'stale'; $self->{cached}->{validity} = 'stale';
} }
@ -256,7 +305,8 @@ sub _CreateForcastRef($) {
{ {
lat => $self->{lat}, lat => $self->{lat},
long => $self->{long}, long => $self->{long},
apiMaintainer => 'Leon Gaultier (<a href=https://forum.fhem.de/index.php?action=profile;u=13684>CoolTux</a>)', apiMaintainer =>
'Leon Gaultier (<a href=https://forum.fhem.de/index.php?action=profile;u=13684>CoolTux</a>)',
} }
); );