2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

DarkSkyAPI: add extend=hourly to apioption

git-svn-id: https://svn.fhem.de/fhem/trunk@18973 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
LeonGaultier 2019-03-19 20:39:44 +00:00
parent 8a791b8086
commit 9915a9ea05
4 changed files with 51 additions and 23 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # 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. # Do not insert empty lines here, update check depends on it.
- feature: DarkSkyAPI: add extend=hourly to apioption
- feature: 93_DbRep: allow PRAGMA leading an SQLIte SQL-Statement in sqlCmd - feature: 93_DbRep: allow PRAGMA leading an SQLIte SQL-Statement in sqlCmd
- bugfix/feature: 59_Weather/API's: fix weblink bug, add extended hourly - bugfix/feature: 59_Weather/API's: fix weblink bug, add extended hourly
data format data format

View File

@ -977,7 +977,8 @@ sub WeatherCheckOptions($@) {
<table border="1"> <table border="1">
<tr><td>API</td><td><code>DarkSkyAPI</code></td></tr> <tr><td>API</td><td><code>DarkSkyAPI</code></td></tr>
<tr><td>apioptions</td><td><code>cachemaxage=&lt;cachemaxage&gt;</code><br>duration <tr><td>apioptions</td><td><code>cachemaxage=&lt;cachemaxage&gt;</code><br>duration
in seconds to retrieve the forecast from the cache instead from the API</td></tr> in seconds to retrieve the forecast from the cache instead from the API<br><code>extend=hourly</code>
<br>extends the number of hours forecast records to 149</td></tr>
<tr><td>location</td><td><code>&lt;latitude,longitude&gt;</code><br> <tr><td>location</td><td><code>&lt;latitude,longitude&gt;</code><br>
geographic coordinates in degrees of the location for which the geographic coordinates in degrees of the location for which the
weather is forecast; if missing, the values of the attributes weather is forecast; if missing, the values of the attributes
@ -1144,7 +1145,8 @@ sub WeatherCheckOptions($@) {
<tr><td>API</td><td><code>DarkSkyAPI</code></td></tr> <tr><td>API</td><td><code>DarkSkyAPI</code></td></tr>
<tr><td>apioptions</td><td><code>cachemaxage=&lt;cachemaxage&gt;</code><br>Zeitdauer in <tr><td>apioptions</td><td><code>cachemaxage=&lt;cachemaxage&gt;</code><br>Zeitdauer in
Sekunden, innerhalb derer die Wettervorhersage nicht neu abgerufen Sekunden, innerhalb derer die Wettervorhersage nicht neu abgerufen
sondern aus dem Cache zur&uuml;ck geliefert wird.</td></tr> sondern aus dem Cache zur&uuml;ck geliefert wird.<br><code>extend=hourly</code>
<br>erweitert die Anzahl der Datens&auml;tze f&uuml;r die Stundenvorhersage auf 149</td></tr>
<tr><td>location</td><td><code>&lt;latitude,longitude&gt;</code><br> Geographische Breite <tr><td>location</td><td><code>&lt;latitude,longitude&gt;</code><br> Geographische Breite
und L&auml;nge des Ortes in Grad, f&uuml;r den das Wetter vorhergesagt wird. und L&auml;nge des Ortes in Grad, f&uuml;r den das Wetter vorhergesagt wird.
Bei fehlender Angabe werden die Werte aus den gleichnamigen Attributen Bei fehlender Angabe werden die Werte aus den gleichnamigen Attributen

View File

@ -48,7 +48,7 @@ use constant DEMODATA => '{"latitude":50.112,"longitude":8.686,"timezone":"Europ
use constant URL => 'https://api.darksky.net/forecast/'; use constant URL => 'https://api.darksky.net/forecast/';
use constant VERSION => '0.2.8'; use constant VERSION => '0.2.9';
my %codes = ( my %codes = (
'clear-day' => 32, 'clear-day' => 32,
@ -69,6 +69,7 @@ my %codes = (
sub new { sub new {
### geliefert wird ein Hash ### geliefert wird ein Hash
my ( $class, $argsRef ) = @_; my ( $class, $argsRef ) = @_;
my $apioptions = parseApiOptions($argsRef->{apioptions});
my $self = { my $self = {
devName => $argsRef->{devName}, devName => $argsRef->{devName},
@ -77,27 +78,38 @@ sub new {
? $argsRef->{apikey} ? $argsRef->{apikey}
: 'none' : 'none'
), ),
cachemaxage => (
( defined( $argsRef->{apioptions} ) and $argsRef->{apioptions} )
? (
( split( ':', $argsRef->{apioptions} ) )[0] eq 'cachemaxage'
? ( split( ':', $argsRef->{apioptions} ) )[1]
: 900
)
: 900
),
lang => $argsRef->{language}, lang => $argsRef->{language},
lat => ( split( ',', $argsRef->{location} ) )[0], lat => ( split( ',', $argsRef->{location} ) )[0],
long => ( split( ',', $argsRef->{location} ) )[1], long => ( split( ',', $argsRef->{location} ) )[1],
fetchTime => 0, fetchTime => 0,
}; };
$self->{cachemaxage} = ( defined($apioptions->{cachemaxage}) ? $apioptions->{cachemaxage} : 900 );
$self->{extend} = ( defined($apioptions->{extend}) ? $apioptions->{extend} : 'none' );
$self->{cached} = _CreateForecastRef($self); $self->{cached} = _CreateForecastRef($self);
bless $self, $class; bless $self, $class;
return $self; return $self;
} }
sub parseApiOptions($) {
my $apioptions = shift;
my @params;
my %h;
@params = split(',',$apioptions);
while (@params) {
my $param = shift(@params);
next if($param eq '');
my ($key, $value) = split(':', $param, 2 );
$h{$key} = $value;
}
return \%h;
}
sub setFetchTime { sub setFetchTime {
my $self = shift; my $self = shift;
@ -159,6 +171,9 @@ sub _RetrieveDataFromDarkSky($) {
if ($missingModul); if ($missingModul);
} }
else { else {
my $options = '&units=auto';
$options .= '&extend=' . $self->{extend} if ( $self->{extend} ne 'none' );
$paramRef->{url} = $paramRef->{url} =
URL URL
. $self->{key} . '/' . $self->{key} . '/'
@ -166,7 +181,7 @@ sub _RetrieveDataFromDarkSky($) {
. $self->{long} . $self->{long}
. '?lang=' . '?lang='
. $self->{lang} . $self->{lang}
. '&units=auto&extend=hourly'; . $options;
if ( lc($self->{key}) eq 'demo' ) if ( lc($self->{key}) eq 'demo' )
{ _RetrieveDataFinished($paramRef,undef,DEMODATA); } { _RetrieveDataFinished($paramRef,undef,DEMODATA); }

View File

@ -48,7 +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.4'; use constant VERSION => '0.2.5';
## URL . 'weather?' for current data ## URL . 'weather?' for current data
## URL . 'forecast?' for forecast data ## URL . 'forecast?' for forecast data
@ -112,6 +112,7 @@ my %codes = (
sub new { sub new {
### geliefert wird ein Hash ### geliefert wird ein Hash
my ( $class, $argsRef ) = @_; my ( $class, $argsRef ) = @_;
my $apioptions = parseApiOptions($argsRef->{apioptions});
my $self = { my $self = {
devName => $argsRef->{devName}, devName => $argsRef->{devName},
@ -120,15 +121,6 @@ sub new {
? $argsRef->{apikey} ? $argsRef->{apikey}
: 'none' : 'none'
), ),
cachemaxage => (
( defined( $argsRef->{apioptions} ) and $argsRef->{apioptions} )
? (
( split( ':', $argsRef->{apioptions} ) )[0] eq 'cachemaxage'
? ( split( ':', $argsRef->{apioptions} ) )[1]
: 900
)
: 900
),
lang => $argsRef->{language}, lang => $argsRef->{language},
lat => ( split( ',', $argsRef->{location} ) )[0], lat => ( split( ',', $argsRef->{location} ) )[0],
long => ( split( ',', $argsRef->{location} ) )[1], long => ( split( ',', $argsRef->{location} ) )[1],
@ -136,12 +128,30 @@ sub new {
endpoint => 'none', endpoint => 'none',
}; };
$self->{cachemaxage} = ( defined($apioptions->{cachemaxage}) ? $apioptions->{cachemaxage} : 900 );
$self->{cached} = _CreateForecastRef($self); $self->{cached} = _CreateForecastRef($self);
bless $self, $class; bless $self, $class;
return $self; return $self;
} }
sub parseApiOptions($) {
my $apioptions = shift;
my @params;
my %h;
@params = split(',',$apioptions);
while (@params) {
my $param = shift(@params);
next if($param eq '');
my ($key, $value) = split(':', $param, 2 );
$h{$key} = $value;
}
return \%h;
}
sub setFetchTime { sub setFetchTime {
my $self = shift; my $self = shift;