add setter locationTemp to change location temporary
This commit is contained in:
parent
150581147f
commit
ec08d0ec53
@ -571,8 +571,19 @@ sub Weather_Set($@) {
|
||||
Weather_GetUpdate($hash);
|
||||
return undef;
|
||||
}
|
||||
elsif ( ( @a == 3 ) && ( $a[1] eq "newLocation" ) ) {
|
||||
if ( $hash->{API} eq 'DarkSkyAPI'
|
||||
or $hash->{API} eq 'OpenWeatherMapAPI' )
|
||||
{
|
||||
$hash->{fhem}->{api}->setLocation((split(':',$a[2]))[0],(split(':',$a[2]))[1]);
|
||||
Weather_DisarmTimer($hash);
|
||||
Weather_GetUpdate($hash);
|
||||
return undef;
|
||||
}
|
||||
else { return 'this API is not ' . $a[1] .' supported' }
|
||||
}
|
||||
else {
|
||||
return "Unknown argument $cmd, choose one of update:noArg";
|
||||
return "Unknown argument $cmd, choose one of update:noArg newLocation";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,6 +195,15 @@ sub setRetrieveData {
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub setLocation {
|
||||
my ($self,$lat,$long) = @_;
|
||||
|
||||
$self->{lat} = $lat;
|
||||
$self->{long} = $long;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub getFetchTime {
|
||||
my $self = shift;
|
||||
|
||||
@ -211,10 +220,19 @@ sub _RetrieveDataFromDarkSky($) {
|
||||
my $self = shift;
|
||||
|
||||
# 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);
|
||||
}
|
||||
|
||||
$self->{cached}->{lat} = $self->{lat}
|
||||
unless ( $self->{cached}->{lat} == $self->{lat} );
|
||||
$self->{cached}->{long} = $self{long}
|
||||
unless ( $self->{cached}->{long} == $self->{long} );
|
||||
|
||||
my $paramRef = {
|
||||
timeout => 15,
|
||||
self => $self,
|
||||
|
@ -116,7 +116,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.4.0';
|
||||
use constant VERSION => '0.5.0';
|
||||
## URL . 'weather?' for current data
|
||||
## URL . 'forecast?' for forecast data
|
||||
|
||||
@ -237,6 +237,15 @@ sub setRetrieveData {
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub setLocation {
|
||||
my ($self,$lat,$long) = @_;
|
||||
|
||||
$self->{lat} = $lat;
|
||||
$self->{long} = $long;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub getFetchTime {
|
||||
my $self = shift;
|
||||
|
||||
@ -253,12 +262,19 @@ sub _RetrieveDataFromOpenWeatherMap($) {
|
||||
my $self = shift;
|
||||
|
||||
# retrieve data from cache
|
||||
if ( $self->{endpoint} eq 'none' ) {
|
||||
if ( ( time() - $self->{fetchTime} ) < $self->{cachemaxage} ) {
|
||||
return _CallWeatherCallbackFn($self);
|
||||
}
|
||||
if ( ( time() - $self->{fetchTime} ) < $self->{cachemaxage}
|
||||
and $self->{cached}->{lat} == $self->{lat}
|
||||
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 = {
|
||||
timeout => 15,
|
||||
self => $self,
|
||||
|
Loading…
x
Reference in New Issue
Block a user