mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 03:06:37 +00:00
59_Weather.pm:plus all API Files - Add new Modul setter newLocation
git-svn-id: https://svn.fhem.de/fhem/trunk@20155 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
88a692ad57
commit
eab8bbe01a
@ -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: 59_Weather.pm: plus all API Files - Add new Modul setter newLocation
|
||||||
- feature: 49_SSCam(STRM): hide buttons in streaming device with new attribute
|
- feature: 49_SSCam(STRM): hide buttons in streaming device with new attribute
|
||||||
hideFooter, minor code changes
|
hideFooter, minor code changes
|
||||||
- feature 73_AutoShuttersControl: add roommate value for ASC_Up/Down for
|
- feature 73_AutoShuttersControl: add roommate value for ASC_Up/Down for
|
||||||
|
@ -310,6 +310,10 @@ sub Weather_ReturnWithError($$) {
|
|||||||
|
|
||||||
sub Weather_RetrieveCallbackFn($) {
|
sub Weather_RetrieveCallbackFn($) {
|
||||||
my $name = shift;
|
my $name = shift;
|
||||||
|
|
||||||
|
return undef
|
||||||
|
unless ( IsDevice($name) );
|
||||||
|
|
||||||
my $hash = $defs{$name};
|
my $hash = $defs{$name};
|
||||||
my $responseRef = $hash->{fhem}->{api}->getWeather;
|
my $responseRef = $hash->{fhem}->{api}->getWeather;
|
||||||
|
|
||||||
@ -567,8 +571,27 @@ sub Weather_Set($@) {
|
|||||||
Weather_GetUpdate($hash);
|
Weather_GetUpdate($hash);
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
elsif ( ( @a >= 2 ) && ( $a[1] eq "newLocation" ) ) {
|
||||||
|
if ( $hash->{API} eq 'DarkSkyAPI'
|
||||||
|
or $hash->{API} eq 'OpenWeatherMapAPI'
|
||||||
|
or $hash->{API} eq 'wundergroundAPI'
|
||||||
|
)
|
||||||
|
{
|
||||||
|
my ($lat,$long);
|
||||||
|
($lat,$long) = split(',',$a[2])
|
||||||
|
if ( defined($a[2]) and $a[2] );
|
||||||
|
($lat,$long) = split(',',$hash->{fhem}->{LOCATION})
|
||||||
|
unless ( defined($lat) and defined($long) );
|
||||||
|
|
||||||
|
$hash->{fhem}->{api}->setLocation($lat,$long);
|
||||||
|
Weather_DisarmTimer($hash);
|
||||||
|
Weather_GetUpdate($hash);
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
else { return 'this API is not ' . $a[1] .' supported' }
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
return "Unknown argument $cmd, choose one of update:noArg";
|
return "Unknown argument $cmd, choose one of update:noArg newLocation";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -649,7 +672,7 @@ sub Weather_Define($$) {
|
|||||||
|
|
||||||
$hash->{NOTIFYDEV} = "global";
|
$hash->{NOTIFYDEV} = "global";
|
||||||
$hash->{fhem}->{interfaces} = "temperature;humidity;wind";
|
$hash->{fhem}->{interfaces} = "temperature;humidity;wind";
|
||||||
$hash->{LOCATION} = (
|
$hash->{fhem}->{LOCATION} = (
|
||||||
( defined($location) and $location )
|
( defined($location) and $location )
|
||||||
? $location
|
? $location
|
||||||
: AttrVal( 'global', 'latitude', 'error' ) . ','
|
: AttrVal( 'global', 'latitude', 'error' ) . ','
|
||||||
@ -665,8 +688,10 @@ sub Weather_Define($$) {
|
|||||||
$hash->{MODEL} = $api;
|
$hash->{MODEL} = $api;
|
||||||
$hash->{APIKEY} = $apikey;
|
$hash->{APIKEY} = $apikey;
|
||||||
$hash->{APIOPTIONS} = $apioptions;
|
$hash->{APIOPTIONS} = $apioptions;
|
||||||
$hash->{READINGS}->{current_date_time}->{TIME} = TimeNow();
|
readingsSingleUpdate($hash,'current_date_time',TimeNow(),0);
|
||||||
$hash->{READINGS}->{current_date_time}->{VAL} = "none";
|
readingsSingleUpdate($hash,'current_date_time','none',0);
|
||||||
|
#$hash->{READINGS}->{current_date_time}->{TIME} = TimeNow();
|
||||||
|
#$hash->{READINGS}->{current_date_time}->{VAL} = "none";
|
||||||
$hash->{fhem}->{allowCache} = 1;
|
$hash->{fhem}->{allowCache} = 1;
|
||||||
|
|
||||||
readingsSingleUpdate( $hash, 'state', 'Initialized', 1 );
|
readingsSingleUpdate( $hash, 'state', 'Initialized', 1 );
|
||||||
@ -677,7 +702,7 @@ sub Weather_Define($$) {
|
|||||||
{
|
{
|
||||||
devName => $hash->{NAME},
|
devName => $hash->{NAME},
|
||||||
apikey => $hash->{APIKEY},
|
apikey => $hash->{APIKEY},
|
||||||
location => $hash->{LOCATION},
|
location => $hash->{fhem}->{LOCATION},
|
||||||
apioptions => $hash->{APIOPTIONS},
|
apioptions => $hash->{APIOPTIONS},
|
||||||
language => $hash->{LANG}
|
language => $hash->{LANG}
|
||||||
}
|
}
|
||||||
@ -1034,10 +1059,19 @@ sub WeatherCheckOptions($@) {
|
|||||||
<a name="Weatherset"></a>
|
<a name="Weatherset"></a>
|
||||||
<b>Set </b>
|
<b>Set </b>
|
||||||
<ul>
|
<ul>
|
||||||
<code>set <name> update</code><br><br>
|
<li>
|
||||||
|
<code>set <name> update</code><br><br>
|
||||||
|
|
||||||
Forces the retrieval of the weather data. The next automatic retrieval is scheduled to occur
|
Forces the retrieval of the weather data. The next automatic retrieval is scheduled to occur
|
||||||
<code>interval</code> seconds later.<br><br>
|
<code>interval</code> seconds later.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<code>set <name> newLocation latitude,longitude</code><br><br>
|
||||||
|
|
||||||
|
set a new temporary location.
|
||||||
|
the value pair Latitude Longitude is separated by a comma.
|
||||||
|
if no value is entered (empty value), the location detected by definition is automatically taken.<br><br>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
@ -1207,11 +1241,20 @@ sub WeatherCheckOptions($@) {
|
|||||||
<a name="Weatherset"></a>
|
<a name="Weatherset"></a>
|
||||||
<b>Set </b>
|
<b>Set </b>
|
||||||
<ul>
|
<ul>
|
||||||
<code>set <name> update</code><br><br>
|
<li>
|
||||||
|
<code>set <name> update</code><br><br>
|
||||||
|
|
||||||
Erzwingt eine Abfrage der Wetterdaten. Die darauffolgende Abfrage
|
Erzwingt eine Abfrage der Wetterdaten. Die darauffolgende Abfrage
|
||||||
wird gemäß dem eingestellten
|
wird gemäß dem eingestellten
|
||||||
Intervall <code>interval</code> Sekunden später durchgeführt.<br><br>
|
Intervall <code>interval</code> Sekunden später durchgeführt.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<code>set <name> newLocation latitude,longitude</code><br><br>
|
||||||
|
|
||||||
|
Gibt die Möglichkeit eine neue temporäre Location zu setzen.
|
||||||
|
Das Wertepaar Latitude Longitude wird durch ein Komma getrennt übergeben.
|
||||||
|
Wird kein Wert mitgegebn (leere Übergabe) wird automatisch die per Definition erkannte Location genommen<br><br>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
@ -32,6 +32,15 @@
|
|||||||
# https://api.openweathermap.org/data/2.5/forecast?lat=[lat]&lon=[long]&APPID=[API] Forecast
|
# https://api.openweathermap.org/data/2.5/forecast?lat=[lat]&lon=[long]&APPID=[API] Forecast
|
||||||
# https://openweathermap.org/weather-conditions Icons und Conditions ID's
|
# https://openweathermap.org/weather-conditions Icons und Conditions ID's
|
||||||
|
|
||||||
|
package OpenWeatherMapAPI;
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use FHEM::Meta;
|
||||||
|
use Data::Dumper;
|
||||||
|
|
||||||
|
FHEM::Meta::Load(__PACKAGE__);
|
||||||
|
use version 0.50; our $VERSION = $main::packages{OpenWeatherMapAPI}{META}{version};
|
||||||
|
|
||||||
package OpenWeatherMapAPI::Weather;
|
package OpenWeatherMapAPI::Weather;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
@ -116,7 +125,6 @@ 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.4.0';
|
|
||||||
## URL . 'weather?' for current data
|
## URL . 'weather?' for current data
|
||||||
## URL . 'forecast?' for forecast data
|
## URL . 'forecast?' for forecast data
|
||||||
|
|
||||||
@ -237,6 +245,15 @@ sub setRetrieveData {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub setLocation {
|
||||||
|
my ($self,$lat,$long) = @_;
|
||||||
|
|
||||||
|
$self->{lat} = $lat;
|
||||||
|
$self->{long} = $long;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
sub getFetchTime {
|
sub getFetchTime {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
@ -253,12 +270,19 @@ sub _RetrieveDataFromOpenWeatherMap($) {
|
|||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
# retrieve data from cache
|
# retrieve data from cache
|
||||||
if ( $self->{endpoint} eq 'none' ) {
|
if ( ( time() - $self->{fetchTime} ) < $self->{cachemaxage}
|
||||||
if ( ( time() - $self->{fetchTime} ) < $self->{cachemaxage} ) {
|
and $self->{cached}->{lat} == $self->{lat}
|
||||||
return _CallWeatherCallbackFn($self);
|
and $self->{cached}->{long} == $self->{long}
|
||||||
}
|
)
|
||||||
|
{
|
||||||
|
return _CallWeatherCallbackFn($self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$self->{cached}->{lat} = $self->{lat}
|
||||||
|
unless ( $self->{cached}->{lat} == $self->{lat} );
|
||||||
|
$self->{cached}->{long} = $self->{long}
|
||||||
|
unless ( $self->{cached}->{long} == $self->{long} );
|
||||||
|
|
||||||
my $paramRef = {
|
my $paramRef = {
|
||||||
timeout => 15,
|
timeout => 15,
|
||||||
self => $self,
|
self => $self,
|
||||||
@ -582,7 +606,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,
|
apiVersion => version->parse(OpenWeatherMapAPI->VERSION())->normal,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -611,3 +635,51 @@ sub strftimeWrapper(@) {
|
|||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
|
|
||||||
|
=pod
|
||||||
|
|
||||||
|
=encoding utf8
|
||||||
|
|
||||||
|
=for :application/json;q=META.json OpenWeatherMapAPI.pm
|
||||||
|
{
|
||||||
|
"abstract": "Weather API for Weather OpenWeatherMap",
|
||||||
|
"x_lang": {
|
||||||
|
"de": {
|
||||||
|
"abstract": "Wetter API für OpenWeatherMap"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"version": "v1.0.0",
|
||||||
|
"author": [
|
||||||
|
"Marko Oldenburg <leongaultier@gmail.com>"
|
||||||
|
],
|
||||||
|
"x_fhem_maintainer": [
|
||||||
|
"CoolTux"
|
||||||
|
],
|
||||||
|
"x_fhem_maintainer_github": [
|
||||||
|
"LeonGaultier"
|
||||||
|
],
|
||||||
|
"prereqs": {
|
||||||
|
"runtime": {
|
||||||
|
"requires": {
|
||||||
|
"FHEM::Meta": 0,
|
||||||
|
"HttpUtils": 0,
|
||||||
|
"strict": 0,
|
||||||
|
"warnings": 0,
|
||||||
|
"constant": 0,
|
||||||
|
"POSIX": 0,
|
||||||
|
"JSON::PP": 0
|
||||||
|
},
|
||||||
|
"recommends": {
|
||||||
|
"JSON": 0
|
||||||
|
},
|
||||||
|
"suggests": {
|
||||||
|
"JSON::XS": 0,
|
||||||
|
"Cpanel::JSON::XS": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
=end :application/json;q=META.json
|
||||||
|
|
||||||
|
=cut
|
||||||
|
@ -172,6 +172,15 @@ sub setRetrieveData {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub setLocation {
|
||||||
|
my ($self,$lat,$long) = @_;
|
||||||
|
|
||||||
|
$self->{lat} = $lat;
|
||||||
|
$self->{long} = $long;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
sub getFetchTime {
|
sub getFetchTime {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
@ -188,10 +197,19 @@ sub _RetrieveDataFromWU($) {
|
|||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
# retrieve data from cache
|
# retrieve data from cache
|
||||||
if ( ( time() - $self->{fetchTime} ) < $self->{cachemaxage} ) {
|
if ( ( time() - $self->{fetchTime} ) < $self->{cachemaxage}
|
||||||
|
and $self->{cached}->{lat} == $self->{lat}
|
||||||
|
and $self->{cached}->{long} == $self->{long}
|
||||||
|
)
|
||||||
|
{
|
||||||
return _CallWeatherCallbackFn($self);
|
return _CallWeatherCallbackFn($self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$self->{cached}->{lat} = $self->{lat}
|
||||||
|
unless ( $self->{cached}->{lat} == $self->{lat} );
|
||||||
|
$self->{cached}->{long} = $self->{long}
|
||||||
|
unless ( $self->{cached}->{long} == $self->{long} );
|
||||||
|
|
||||||
my $paramRef = {
|
my $paramRef = {
|
||||||
timeout => 15,
|
timeout => 15,
|
||||||
self => $self,
|
self => $self,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user