fix readingupdate

This commit is contained in:
Marko Oldenburg
2019-01-17 22:22:44 +01:00
parent 5dbc93fa40
commit 566f7a0979
2 changed files with 20 additions and 17 deletions

View File

@@ -44,6 +44,7 @@ eval "use Encode qw(encode_utf8);1" or $missingModul .= "Encode ";
# use Data::Dumper; # for Debug only # use Data::Dumper; # for Debug only
## API URL ## API URL
use constant URL => 'https://api.darksky.net/forecast/'; use constant URL => 'https://api.darksky.net/forecast/';
use constant VERSION => '0.2.4';
my %codes = ( my %codes = (
'clear-day' => 32, 'clear-day' => 32,
@@ -250,7 +251,7 @@ sub _ProcessingRetrieveData($$) {
"%a, %e %b %Y %H:%M", "%a, %e %b %Y %H:%M",
localtime( $data->{currently}->{'time'} ) localtime( $data->{currently}->{'time'} )
), ),
'precipProbability' => $data->{currently}->{precipProbability}, 'precipProbability' => $data->{currently}->{precipProbability} * 100,
'apparentTemperature' => int( 'apparentTemperature' => int(
sprintf( sprintf(
"%.1f", $data->{currently}->{apparentTemperature} "%.1f", $data->{currently}->{apparentTemperature}
@@ -414,11 +415,11 @@ sub _ProcessingRetrieveData($$) {
} }
); );
$self->{cached}->{forecast}->{daily}[$i]{precipIntensityMax} = $data->{daily}->{data}->[$i]->{precipIntensityMax} if ( defined($data->{daily}->{data}->[$i]->{precipIntensityMax}) ); $self->{cached}->{forecast}->{daily}[$i]{precipIntensityMax} = ( defined($data->{daily}->{data}->[$i]->{precipIntensityMax}) ? $data->{daily}->{data}->[$i]->{precipIntensityMax} : '-' );
$self->{cached}->{forecast}->{daily}[$i]{precipIntensity} = $data->{daily}->{data}->[$i]->{precipIntensity} if ( defined($data->{daily}->{data}->[$i]->{precipIntensity}) ); $self->{cached}->{forecast}->{daily}[$i]{precipIntensity} = ( defined($data->{daily}->{data}->[$i]->{precipIntensity}) ? $data->{daily}->{data}->[$i]->{precipIntensity} : '-' );
$self->{cached}->{forecast}->{daily}[$i]{precipProbability} = $data->{daily}->{data}->[$i]->{precipProbability} if ( defined($data->{daily}->{data}->[$i]->{precipProbability}) ); $self->{cached}->{forecast}->{daily}[$i]{precipProbability} = ( defined($data->{daily}->{data}->[$i]->{precipProbability}) ? $data->{daily}->{data}->[$i]->{precipProbability} * 100 : '-' );
$self->{cached}->{forecast}->{daily}[$i]{precipType} = $data->{daily}->{data}->[$i]->{precipType} if ( defined($data->{daily}->{data}->[$i]->{precipType}) ); $self->{cached}->{forecast}->{daily}[$i]{precipType} = ( defined($data->{daily}->{data}->[$i]->{precipType}) ? $data->{daily}->{data}->[$i]->{precipType} : '-' );
$self->{cached}->{forecast}->{daily}[$i]{precipIntensityMaxTime} = strftime("%a, %e %b %Y %H:%M",localtime($data->{daily}->{data}->[$i]->{precipIntensityMaxTime}) ) if ( defined($data->{daily}->{data}->[$i]->{precipIntensityMaxTime}) ); $self->{cached}->{forecast}->{daily}[$i]{precipIntensityMaxTime} = ( defined($data->{daily}->{data}->[$i]->{precipIntensityMaxTime}) ? strftime("%a, %e %b %Y %H:%M",localtime($data->{daily}->{data}->[$i]->{precipIntensityMaxTime}) ) : '-' );
$i++; $i++;
} }
@@ -456,16 +457,12 @@ sub _ProcessingRetrieveData($$) {
'ozone' => $data->{hourly}->{data}->[$i]->{ozone}, 'ozone' => $data->{hourly}->{data}->[$i]->{ozone},
'uvIndex' => 'uvIndex' =>
$data->{hourly}->{data}->[$i]->{uvIndex}, $data->{hourly}->{data}->[$i]->{uvIndex},
'precipIntensity' =>
$data->{hourly}->{data}->[$i]->{precipIntensity},
'dewPoint' => sprintf( "%.1f", 'dewPoint' => sprintf( "%.1f",
$data->{hourly}->{data}->[$i]->{dewPoint} ), $data->{hourly}->{data}->[$i]->{dewPoint} ),
'humidity' => 'humidity' =>
$data->{hourly}->{data}->[$i]->{humidity} * 100, $data->{hourly}->{data}->[$i]->{humidity} * 100,
'cloudCover' => 'cloudCover' =>
$data->{hourly}->{data}->[$i]->{cloudCover} * 100, $data->{hourly}->{data}->[$i]->{cloudCover} * 100,
'precipType' =>
$data->{hourly}->{data}->[$i]->{precipType},
'wind_direction' => 'wind_direction' =>
$data->{hourly}->{data}->[$i]->{windBearing}, $data->{hourly}->{data}->[$i]->{windBearing},
'wind' => int( 'wind' => int(
@@ -483,8 +480,7 @@ sub _ProcessingRetrieveData($$) {
($data->{hourly}->{data}->[$i]->{windGust} * 3.6) ) ($data->{hourly}->{data}->[$i]->{windGust} * 3.6) )
+ 0.5 + 0.5
), ),
'precipProbability' =>
$data->{hourly}->{data}->[$i]->{precipProbability},
'pressure' => sprintf( "%.1f", 'pressure' => sprintf( "%.1f",
$data->{hourly}->{data}->[$i]->{pressure} ), $data->{hourly}->{data}->[$i]->{pressure} ),
'visibility' => sprintf( "%.1f", 'visibility' => sprintf( "%.1f",
@@ -492,6 +488,10 @@ sub _ProcessingRetrieveData($$) {
} }
); );
$self->{cached}->{forecast}->{hourly}[$i]{precipIntensity} = ( defined($data->{hourly}->{data}->[$i]->{precipIntensity}) ? $data->{hourly}->{data}->[$i]->{precipIntensity} : '-' );
$self->{cached}->{forecast}->{hourly}[$i]{precipProbability} = ( defined($data->{hourly}->{data}->[$i]->{precipProbability}) ? $data->{hourly}->{data}->[$i]->{precipProbability} * 100 : '-' );
$self->{cached}->{forecast}->{hourly}[$i]{precipType} = ( defined($data->{hourly}->{data}->[$i]->{precipType}) ? $data->{hourly}->{data}->[$i]->{precipType} : '-' );
$i++; $i++;
} }
} }
@@ -530,6 +530,7 @@ sub _CreateForecastRef($) {
long => $self->{long}, long => $self->{long},
apiMaintainer => apiMaintainer =>
'Leon Gaultier (<a href=https://forum.fhem.de/index.php?action=profile;u=13684>CoolTux</a>)', 'Leon Gaultier (<a href=https://forum.fhem.de/index.php?action=profile;u=13684>CoolTux</a>)',
apiVersion => VERSION,
} }
); );

View File

@@ -48,6 +48,7 @@ eval "use Encode qw(encode_utf8);1" or $missingModul .= "Encode ";
# use Data::Dumper; # for Debug only # use Data::Dumper; # for Debug only
## API URL ## API URL
use constant URL => 'https://api.openweathermap.org/data/2.5/'; use constant URL => 'https://api.openweathermap.org/data/2.5/';
use constant VERSION => '0.2.2';
## URL . 'weather?' for current data ## URL . 'weather?' for current data
## URL . 'forecast?' for forecast data ## URL . 'forecast?' for forecast data
@@ -297,17 +298,17 @@ sub _ProcessingRetrieveData($$) {
), ),
'humidity' => $data->{main}->{humidity}, 'humidity' => $data->{main}->{humidity},
'condition' => 'condition' =>
encode_utf8( $data->{weather}->[0]->{description} ), encode_utf8( $data->{weather}->[0]->{description} ),
'pressure' => 'pressure' =>
int( sprintf( "%.1f", $data->{main}->{pressure} ) + 0.5 ), int( sprintf( "%.1f", $data->{main}->{pressure} ) + 0.5 ),
'wind' => 'wind' =>
int( sprintf( "%.1f", ($data->{wind}->{speed} * 3.6) ) + 0.5 ), int( sprintf( "%.1f", ($data->{wind}->{speed} * 3.6) ) + 0.5 ),
'wind_speed' => 'wind_speed' =>
int( sprintf( "%.1f", ($data->{wind}->{speed} * 3.6) ) + 0.5 ), int( sprintf( "%.1f", ($data->{wind}->{speed} * 3.6) ) + 0.5 ),
'wind_direction' => $data->{wind}->{deg}, 'wind_direction' => $data->{wind}->{deg},
'cloudCover' => $data->{clouds}->{all}, 'cloudCover' => $data->{clouds}->{all},
'visibility' => 'visibility' =>
int( sprintf( "%.1f", $data->{visibility} ) + 0.5 ), 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' => strftime( 'sunsetTime' => strftime(
@@ -485,6 +486,7 @@ sub _CreateForecastRef($) {
long => $self->{long}, long => $self->{long},
apiMaintainer => apiMaintainer =>
'Leon Gaultier (<a href=https://forum.fhem.de/index.php?action=profile;u=13684>CoolTux</a>)', 'Leon Gaultier (<a href=https://forum.fhem.de/index.php?action=profile;u=13684>CoolTux</a>)',
apiVersion => VERSION,
} }
); );