fix no visibility is available

This commit is contained in:
Marko Oldenburg 2020-04-25 08:49:56 +02:00
parent 1764f7ee7d
commit cb3f5c1ecb

View File

@ -36,7 +36,6 @@ package OpenWeatherMapAPI;
use strict; use strict;
use warnings; use warnings;
use FHEM::Meta; use FHEM::Meta;
use Data::Dumper;
FHEM::Meta::Load(__PACKAGE__); FHEM::Meta::Load(__PACKAGE__);
use version 0.50; our $VERSION = $main::packages{OpenWeatherMapAPI}{META}{version}; use version 0.50; our $VERSION = $main::packages{OpenWeatherMapAPI}{META}{version};
@ -48,6 +47,8 @@ use warnings;
use POSIX; use POSIX;
use HttpUtils; use HttpUtils;
# use Data::Dumper;
# try to use JSON::MaybeXS wrapper # try to use JSON::MaybeXS wrapper
# for chance of better performance + open code # for chance of better performance + open code
eval { eval {
@ -424,8 +425,6 @@ sub _ProcessingRetrieveData {
), ),
'wind_direction' => $data->{wind}->{deg}, 'wind_direction' => $data->{wind}->{deg},
'cloudCover' => $data->{clouds}->{all}, 'cloudCover' => $data->{clouds}->{all},
'visibility' =>
int( sprintf( "%.1f", $data->{visibility} ) + 0.5 ),
'code' => $codes{ $data->{weather}->[0]->{id} }, 'code' => $codes{ $data->{weather}->[0]->{id} },
'iconAPI' => $data->{weather}->[0]->{icon}, 'iconAPI' => $data->{weather}->[0]->{icon},
'sunsetTime' => strftimeWrapper( 'sunsetTime' => strftimeWrapper(
@ -438,12 +437,12 @@ sub _ProcessingRetrieveData {
), ),
'pubDate' => strftimeWrapper( 'pubDate' => strftimeWrapper(
"%a, %e %b %Y %H:%M", "%a, %e %b %Y %H:%M",
( exists $data->{dt} localtime( $data->{dt} )
? localtime( $data->{dt} )
: localtime( time )
)
), ),
}; };
$self->{cached}->{current}->{'visibility'} = int(sprintf( "%.1f", $data->{visibility} ) + 0.5)
if ( exists $data->{visibility} );
} }
if ( $self->{endpoint} eq 'forecast' ) { if ( $self->{endpoint} eq 'forecast' ) {
@ -660,7 +659,7 @@ sub strftimeWrapper {
"abstract": "Wetter API für OpenWeatherMap" "abstract": "Wetter API für OpenWeatherMap"
} }
}, },
"version": "v1.0.1", "version": "v1.0.2",
"author": [ "author": [
"Marko Oldenburg <leongaultier@gmail.com>" "Marko Oldenburg <leongaultier@gmail.com>"
], ],