From 785f9d07b497312fccdac071cd04de0256ad44a0 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Thu, 5 Jan 2023 08:18:05 +0100 Subject: [PATCH] add hook example add support for onecall endpoint with api version 2.5 --- FHEM/59_Weather.pm | 16 ++++++--- controls_Weather.txt | 8 ++--- hooks/pre-commit | 41 ++++++++++++++++++++++ lib/FHEM/APIs/Weather/OpenWeatherMapAPI.pm | 7 ++-- 4 files changed, 62 insertions(+), 10 deletions(-) create mode 100755 hooks/pre-commit diff --git a/FHEM/59_Weather.pm b/FHEM/59_Weather.pm index 1f956e7..d87bb5f 100755 --- a/FHEM/59_Weather.pm +++ b/FHEM/59_Weather.pm @@ -1204,7 +1204,10 @@ sub Weather_CheckOptions { apioptionscachemaxage:<cachemaxage>
duration in seconds to retrieve the forecast from the cache instead from the API version:<version> API version which should be used. - 2.5 by default, 3.0 is still possible but only with an additional subscription + 2.5 by default, 3.0 is still possible but only with an additional subscription + endpoint:onecall only to test whether the API key which not + officially for onecall is not supported yet onecall via API version 2.5. IMPORTANT!!! + apioption version must not be set to 3.0 location<latitude,longitude>
geographic coordinates in degrees of the location for which the weather is forecast; if missing, the values of the attributes @@ -1398,11 +1401,16 @@ sub Weather_CheckOptions { - + + Per Default 2.5, möglich ist noch 3.0 aber nur mit Zusatzsubscription + +
APIOpenWeatherMapAPI
apioptionscachemaxage:<cachemaxage> Zeitdauer in +
apioptionscachemaxage:<cachemaxage> Zeitdauer in Sekunden, innerhalb derer die Wettervorhersage nicht neu abgerufen sondern aus dem Cache zurück geliefert wird. version:<version> API Version welche verwendet werden soll. - Per Default 2.5, möglich ist noch 3.0 aber nur mit Zusatzsubscription
endpoint:onecall nur zum testen ob der API Key welcher nicht + offiziell für onecall ist nicht doch onecall über die API Version 2.5 unterstützt. WICHTIG!!! + apioption version darf nicht auf 3.0 gesetzt werden
location<latitude,longitude> Geographische Breite und Länge des Ortes in Grad, für den das Wetter vorhergesagt wird. Bei fehlender Angabe werden die Werte aus den gleichnamigen Attributen @@ -1542,7 +1550,7 @@ sub Weather_CheckOptions { ], "release_status": "stable", "license": "GPL_2", - "version": "v2.2.11", + "version": "v2.2.15", "author": [ "Marko Oldenburg " ], diff --git a/controls_Weather.txt b/controls_Weather.txt index f4de39e..7e6e317 100644 --- a/controls_Weather.txt +++ b/controls_Weather.txt @@ -1,4 +1,4 @@ -UPD 2022-12-30_12:22:17 54815 FHEM/59_Weather.pm -UPD 2022-12-30_12:22:17 49883 lib/FHEM/APIs/Weather/DarkSkyAPI.pm -UPD 2022-12-30_12:22:17 32101 lib/FHEM/APIs/Weather/OpenWeatherMapAPI.pm -UPD 2023-01-02_09:25:12 36090 lib/FHEM/APIs/Weather/wundergroundAPI.pm +UPD 2023-01-05_08:17:10 55320 FHEM/59_Weather.pm +UPD 2023-01-04_16:37:24 49883 lib/FHEM/APIs/Weather/DarkSkyAPI.pm +UPD 2023-01-05_08:05:28 32255 lib/FHEM/APIs/Weather/OpenWeatherMapAPI.pm +UPD 2023-01-04_16:37:24 36090 lib/FHEM/APIs/Weather/wundergroundAPI.pm diff --git a/hooks/pre-commit b/hooks/pre-commit new file mode 100755 index 0000000..4fc1c9a --- /dev/null +++ b/hooks/pre-commit @@ -0,0 +1,41 @@ +#!/usr/bin/perl -w + +use File::Basename; +use POSIX qw(strftime); +use strict; + +my @filenames = ( 'FHEM/59_Weather.pm', + 'lib/FHEM/APIs/Weather/DarkSkyAPI.pm', + 'lib/FHEM/APIs/Weather/OpenWeatherMapAPI.pm', + 'lib/FHEM/APIs/Weather/wundergroundAPI.pm', + ); + +my $controlsfile = 'controls_Weather.txt'; + +open(FH, ">$controlsfile") || return("Can't open $controlsfile: $!"); + +for my $filename (@filenames) { + my @statOutput = stat($filename); + + if (scalar @statOutput != 13) { + printf 'error: stat has unexpected return value for ' . $filename . "\n"; + next; + } + + my $mtime = $statOutput[9]; + my $date = POSIX::strftime("%Y-%m-%d", localtime($mtime)); + my $time = POSIX::strftime("%H:%M:%S", localtime($mtime)); + my $filetime = $date."_".$time; + + my $filesize = $statOutput[7]; + + printf FH 'UPD ' . $filetime . ' ' . $filesize . ' ' .$filename . "\n"; +} + +close(FH); + +system("git add $controlsfile"); + +print 'Create controls File succesfully' . "\n"; + +exit 0; diff --git a/lib/FHEM/APIs/Weather/OpenWeatherMapAPI.pm b/lib/FHEM/APIs/Weather/OpenWeatherMapAPI.pm index 1514290..d5dc975 100644 --- a/lib/FHEM/APIs/Weather/OpenWeatherMapAPI.pm +++ b/lib/FHEM/APIs/Weather/OpenWeatherMapAPI.pm @@ -213,6 +213,8 @@ sub new { $self->{apiversion} = ( $apioptions->{version} ? $apioptions->{version} : '2.5' ); + $self->{endpointType} = + ( $apioptions->{endpoint} ? $apioptions->{endpoint} : 'forecast' ); $self->{cached} = _CreateForecastRef($self); @@ -316,7 +318,8 @@ sub _RetrieveDataFromOpenWeatherMap { timeout => 15, self => $self, endpoint => $self->{endpoint} eq 'none' - ? ( $self->{apiversion} == 3.0 ? 'onecall' : 'weather' ) + ? ( $self->{apiversion} == 3.0 + || $self->{endpointType} eq 'onecall' ? 'onecall' : 'weather' ) : 'forecast', callback => \&_RetrieveDataFinished, }; @@ -989,7 +992,7 @@ sub _strftimeWrapper { "abstract": "Wetter API für OpenWeatherMap" } }, - "version": "v3.0.12", + "version": "v3.0.15", "author": [ "Marko Oldenburg " ], -- 2.45.2