From b6a5efb341de15ca9d9e8af3c3823730cfbf08e3 Mon Sep 17 00:00:00 2001 From: LeonGaultier Date: Thu, 17 Jan 2019 21:25:55 +0000 Subject: [PATCH] DarkSkyAPI: fix reading values, add API Version git-svn-id: https://svn.fhem.de/fhem/trunk@18306 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/DarkSkyAPI.pm | 25 +++++++++++++------------ fhem/FHEM/OpenWeatherMapAPI.pm | 12 +++++++----- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 2834fa9a3..bf7a78ebe 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - bugfix: DarkSkyAPI: fix reading values, add API Version - bugfix: 82_LGTV_WebOS: add SkyOnline at set commands - feature: 49_SSCam: 8.5.0, SVS device has "snapCams" command to take snapshots of all cameras and optionally send them diff --git a/fhem/FHEM/DarkSkyAPI.pm b/fhem/FHEM/DarkSkyAPI.pm index c07b1dadd..0fe85597a 100644 --- a/fhem/FHEM/DarkSkyAPI.pm +++ b/fhem/FHEM/DarkSkyAPI.pm @@ -44,6 +44,7 @@ eval "use Encode qw(encode_utf8);1" or $missingModul .= "Encode "; # use Data::Dumper; # for Debug only ## API URL use constant URL => 'https://api.darksky.net/forecast/'; +use constant VERSION => '0.2.4'; my %codes = ( 'clear-day' => 32, @@ -250,7 +251,7 @@ sub _ProcessingRetrieveData($$) { "%a, %e %b %Y %H:%M", localtime( $data->{currently}->{'time'} ) ), - 'precipProbability' => $data->{currently}->{precipProbability}, + 'precipProbability' => $data->{currently}->{precipProbability} * 100, 'apparentTemperature' => int( sprintf( "%.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]{precipIntensity} = $data->{daily}->{data}->[$i]->{precipIntensity} if ( defined($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]{precipType} = $data->{daily}->{data}->[$i]->{precipType} if ( defined($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]{precipIntensityMax} = ( defined($data->{daily}->{data}->[$i]->{precipIntensityMax}) ? $data->{daily}->{data}->[$i]->{precipIntensityMax} : '-' ); + $self->{cached}->{forecast}->{daily}[$i]{precipIntensity} = ( defined($data->{daily}->{data}->[$i]->{precipIntensity}) ? $data->{daily}->{data}->[$i]->{precipIntensity} : '-' ); + $self->{cached}->{forecast}->{daily}[$i]{precipProbability} = ( defined($data->{daily}->{data}->[$i]->{precipProbability}) ? $data->{daily}->{data}->[$i]->{precipProbability} * 100 : '-' ); + $self->{cached}->{forecast}->{daily}[$i]{precipType} = ( defined($data->{daily}->{data}->[$i]->{precipType}) ? $data->{daily}->{data}->[$i]->{precipType} : '-' ); + $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++; } @@ -456,16 +457,12 @@ sub _ProcessingRetrieveData($$) { 'ozone' => $data->{hourly}->{data}->[$i]->{ozone}, 'uvIndex' => $data->{hourly}->{data}->[$i]->{uvIndex}, - 'precipIntensity' => - $data->{hourly}->{data}->[$i]->{precipIntensity}, 'dewPoint' => sprintf( "%.1f", $data->{hourly}->{data}->[$i]->{dewPoint} ), 'humidity' => $data->{hourly}->{data}->[$i]->{humidity} * 100, 'cloudCover' => $data->{hourly}->{data}->[$i]->{cloudCover} * 100, - 'precipType' => - $data->{hourly}->{data}->[$i]->{precipType}, 'wind_direction' => $data->{hourly}->{data}->[$i]->{windBearing}, 'wind' => int( @@ -483,8 +480,7 @@ sub _ProcessingRetrieveData($$) { ($data->{hourly}->{data}->[$i]->{windGust} * 3.6) ) + 0.5 ), - 'precipProbability' => - $data->{hourly}->{data}->[$i]->{precipProbability}, + 'pressure' => sprintf( "%.1f", $data->{hourly}->{data}->[$i]->{pressure} ), '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++; } } @@ -530,6 +530,7 @@ sub _CreateForecastRef($) { long => $self->{long}, apiMaintainer => 'Leon Gaultier (CoolTux)', + apiVersion => VERSION, } ); diff --git a/fhem/FHEM/OpenWeatherMapAPI.pm b/fhem/FHEM/OpenWeatherMapAPI.pm index cda87e799..68ead05f1 100644 --- a/fhem/FHEM/OpenWeatherMapAPI.pm +++ b/fhem/FHEM/OpenWeatherMapAPI.pm @@ -48,6 +48,7 @@ eval "use Encode qw(encode_utf8);1" or $missingModul .= "Encode "; # use Data::Dumper; # for Debug only ## API URL use constant URL => 'https://api.openweathermap.org/data/2.5/'; +use constant VERSION => '0.2.2'; ## URL . 'weather?' for current data ## URL . 'forecast?' for forecast data @@ -297,17 +298,17 @@ sub _ProcessingRetrieveData($$) { ), 'humidity' => $data->{main}->{humidity}, 'condition' => - encode_utf8( $data->{weather}->[0]->{description} ), + encode_utf8( $data->{weather}->[0]->{description} ), 'pressure' => - int( sprintf( "%.1f", $data->{main}->{pressure} ) + 0.5 ), + int( sprintf( "%.1f", $data->{main}->{pressure} ) + 0.5 ), 'wind' => - int( sprintf( "%.1f", ($data->{wind}->{speed} * 3.6) ) + 0.5 ), + int( sprintf( "%.1f", ($data->{wind}->{speed} * 3.6) ) + 0.5 ), '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}, 'cloudCover' => $data->{clouds}->{all}, 'visibility' => - int( sprintf( "%.1f", $data->{visibility} ) + 0.5 ), + int( sprintf( "%.1f", $data->{visibility} ) + 0.5 ), 'code' => $codes{ $data->{weather}->[0]->{id} }, 'iconAPI' => $data->{weather}->[0]->{icon}, 'sunsetTime' => strftime( @@ -485,6 +486,7 @@ sub _CreateForecastRef($) { long => $self->{long}, apiMaintainer => 'Leon Gaultier (CoolTux)', + apiVersion => VERSION, } );