patch-addOnecallMode #5
@ -38,7 +38,6 @@ use Readonly;
|
||||
use FHEM::Meta;
|
||||
use vars qw($FW_ss);
|
||||
|
||||
|
||||
# use Data::Dumper; # for Debug only
|
||||
|
||||
my %pressure_trend_txt_en = ( 0 => "steady", 1 => "rising", 2 => "falling" );
|
||||
@ -354,11 +353,10 @@ sub Weather_WriteReadings {
|
||||
my $dataRef = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my $hourly = ( AttrVal( $name, 'forecast', '' ) =~ m{hourly}xms ? 1: 0 );
|
||||
my $hourly = ( AttrVal( $name, 'forecast', '' ) =~ m{hourly}xms ? 1 : 0 );
|
||||
my $daily = ( AttrVal( $name, 'forecast', '' ) =~ m{daily}xms ? 1 : 0 );
|
||||
my $alerts = ( AttrVal( $name, 'forecast', '' ) =~ m{alerts}xms ? 1 : 0 );
|
||||
|
||||
|
||||
readingsBeginUpdate($hash);
|
||||
|
||||
# housekeeping information
|
||||
@ -400,15 +398,13 @@ sub Weather_WriteReadings {
|
||||
|
||||
### forecast
|
||||
if ( ref( $dataRef->{forecast} ) eq 'HASH'
|
||||
&& ($hourly || $daily) )
|
||||
&& ( $hourly || $daily ) )
|
||||
{
|
||||
## hourly
|
||||
if (
|
||||
defined( $dataRef->{forecast}->{hourly} )
|
||||
if ( defined( $dataRef->{forecast}->{hourly} )
|
||||
&& ref( $dataRef->{forecast}->{hourly} ) eq 'ARRAY'
|
||||
&& scalar( @{ $dataRef->{forecast}->{hourly} } ) > 0
|
||||
&& $hourly
|
||||
)
|
||||
&& $hourly )
|
||||
{
|
||||
my $i = 0;
|
||||
my $limit = AttrVal( $name, 'forecastLimit', -1 );
|
||||
@ -458,12 +454,10 @@ sub Weather_WriteReadings {
|
||||
}
|
||||
|
||||
## daily
|
||||
if (
|
||||
defined( $dataRef->{forecast}->{daily} )
|
||||
if ( defined( $dataRef->{forecast}->{daily} )
|
||||
&& ref( $dataRef->{forecast}->{daily} ) eq 'ARRAY'
|
||||
&& scalar( @{ $dataRef->{forecast}->{daily} } ) > 0
|
||||
&& $daily
|
||||
)
|
||||
&& $daily )
|
||||
{
|
||||
my $i = 0;
|
||||
my $limit = AttrVal( $name, 'forecastLimit', -1 );
|
||||
@ -597,7 +591,7 @@ sub Weather_Set {
|
||||
// return qq{"set $name" needs at least one argument};
|
||||
|
||||
# usage check
|
||||
if ( scalar(@{$aRef}) == 0
|
||||
if ( scalar( @{$aRef} ) == 0
|
||||
&& $cmd eq 'update' )
|
||||
{
|
||||
Weather_DisarmTimer($hash);
|
||||
@ -605,29 +599,28 @@ sub Weather_Set {
|
||||
|
||||
return;
|
||||
}
|
||||
elsif ( scalar(@{$aRef}) == 1
|
||||
elsif ( scalar( @{$aRef} ) == 1
|
||||
&& $cmd eq "newLocation" )
|
||||
{
|
||||
if ( $hash->{API} eq 'DarkSkyAPI'
|
||||
|| $hash->{API} eq 'OpenWeatherMapAPI'
|
||||
|| $hash->{API} eq 'wundergroundAPI'
|
||||
)
|
||||
|| $hash->{API} eq 'wundergroundAPI' )
|
||||
{
|
||||
my ($lat,$long);
|
||||
($lat,$long) = split(',',$aRef->[0])
|
||||
if ( defined($aRef->[0]) && $aRef->[0] );
|
||||
($lat,$long) = split(',',$hash->{fhem}->{LOCATION})
|
||||
my ( $lat, $long );
|
||||
( $lat, $long ) = split( ',', $aRef->[0] )
|
||||
if ( defined( $aRef->[0] ) && $aRef->[0] );
|
||||
( $lat, $long ) = split( ',', $hash->{fhem}->{LOCATION} )
|
||||
unless ( defined($lat)
|
||||
&& defined($long)
|
||||
&& $lat =~ m{(-?\d+(\.\d+)?)}xms
|
||||
&& $long =~ m{(-?\d+(\.\d+)?)}xms );
|
||||
|
||||
$hash->{fhem}->{api}->setLocation($lat,$long);
|
||||
$hash->{fhem}->{api}->setLocation( $lat, $long );
|
||||
Weather_DisarmTimer($hash);
|
||||
Weather_GetUpdate($hash);
|
||||
return;
|
||||
}
|
||||
else { return 'this API is not ' . $aRef->[0] .' supported' }
|
||||
else { return 'this API is not ' . $aRef->[0] . ' supported' }
|
||||
}
|
||||
else {
|
||||
return "Unknown argument $cmd, choose one of update:noArg newLocation";
|
||||
@ -689,7 +682,6 @@ sub Weather_Define {
|
||||
my $aRef = shift // return;
|
||||
my $hRef = shift // undef;
|
||||
|
||||
|
||||
return $@ unless ( FHEM::Meta::SetInternals($hash) );
|
||||
use version 0.60; our $VERSION = FHEM::Meta::Get( $hash, 'version' );
|
||||
|
||||
@ -733,8 +725,8 @@ sub Weather_Define {
|
||||
$hash->{VERSION} = version->parse($VERSION)->normal;
|
||||
$hash->{fhem}->{allowCache} = 1;
|
||||
|
||||
readingsSingleUpdate($hash,'current_date_time',TimeNow(),0);
|
||||
readingsSingleUpdate($hash,'current_date_time','none',0);
|
||||
readingsSingleUpdate( $hash, 'current_date_time', TimeNow(), 0 );
|
||||
readingsSingleUpdate( $hash, 'current_date_time', 'none', 0 );
|
||||
|
||||
readingsSingleUpdate( $hash, 'state', 'Initialized', 1 );
|
||||
Weather_LanguageInitialize( $hash->{LANG} );
|
||||
@ -747,8 +739,8 @@ sub Weather_Define {
|
||||
location => $hash->{fhem}->{LOCATION},
|
||||
apioptions => $hash->{APIOPTIONS},
|
||||
language => $hash->{LANG},
|
||||
forecast => AttrVal($name,'forecast',''),
|
||||
alerts => AttrVal($name,'alerts',0)
|
||||
forecast => AttrVal( $name, 'forecast', '' ),
|
||||
alerts => AttrVal( $name, 'alerts', 0 )
|
||||
}
|
||||
);
|
||||
|
||||
@ -774,7 +766,7 @@ sub Weather_Attr {
|
||||
given ($attrName) {
|
||||
when ('forecast') {
|
||||
if ( $cmd eq 'set' ) {
|
||||
$hash->{fhem}->{api}->setForecast($attrVal)
|
||||
$hash->{fhem}->{api}->setForecast($attrVal);
|
||||
}
|
||||
|
||||
$hash->{fhem}->{api}->setForecast();
|
||||
|
@ -205,7 +205,8 @@ sub new {
|
||||
: 900
|
||||
);
|
||||
|
||||
$self->{apiversion} = ($apioptions->{version} ? $apioptions->{version} : '2.5');
|
||||
$self->{apiversion} =
|
||||
( $apioptions->{version} ? $apioptions->{version} : '2.5' );
|
||||
|
||||
$self->{cached} = _CreateForecastRef($self);
|
||||
|
||||
@ -339,10 +340,12 @@ sub _RetrieveDataFromOpenWeatherMap {
|
||||
. $self->{lat} . '&' . 'lon='
|
||||
. $self->{long} . '&'
|
||||
. 'APPID='
|
||||
. $self->{key} . '&' . 'units='
|
||||
. $self->{key} . '&'
|
||||
. 'units='
|
||||
. 'metric' . '&' . 'lang='
|
||||
. $self->{lang} . '&' . 'exclude='
|
||||
. _createExcludeString($self->{forecast},$self->{alerts});
|
||||
. $self->{lang} . '&'
|
||||
. 'exclude='
|
||||
. _createExcludeString( $self->{forecast}, $self->{alerts} );
|
||||
|
||||
::HttpUtils_NonblockingGet($paramRef);
|
||||
}
|
||||
@ -355,13 +358,13 @@ sub _createExcludeString {
|
||||
my $alerts = shift;
|
||||
|
||||
my @exclude = qw/alerts minutely hourly daily/;
|
||||
my @forecast = split(',',$forecast);
|
||||
my @forecast = split( ',', $forecast );
|
||||
my @alerts = ( $alerts ? ',alerts' : '' );
|
||||
|
||||
my %in_forecast = map {$_ => 1} @forecast,@alerts;
|
||||
my @diff = grep {not $in_forecast{$_}} @exclude;
|
||||
my %in_forecast = map { $_ => 1 } @forecast, @alerts;
|
||||
my @diff = grep { not $in_forecast{$_} } @exclude;
|
||||
|
||||
return join(',',@alerts);
|
||||
return join( ',', @alerts );
|
||||
}
|
||||
|
||||
sub _RetrieveDataFinished {
|
||||
@ -424,32 +427,30 @@ sub _ProcessingRetrieveData {
|
||||
$self->{cached}->{license}{text} = 'none';
|
||||
$self->{cached}->{current} = {
|
||||
'temperature' => int(
|
||||
sprintf( "%.1f",
|
||||
$data->{main}->{temp}) + 0.5
|
||||
sprintf( "%.1f", $data->{main}->{temp} ) + 0.5
|
||||
),
|
||||
'temp_c' => int(
|
||||
sprintf( "%.1f",
|
||||
$data->{main}->{temp}) + 0.5
|
||||
sprintf( "%.1f", $data->{main}->{temp} ) + 0.5
|
||||
),
|
||||
'low_c' => int(
|
||||
sprintf( "%.1f",
|
||||
$data->{main}->{temp_min}) + 0.5
|
||||
sprintf( "%.1f", $data->{main}->{temp_min} ) +
|
||||
0.5
|
||||
),
|
||||
'high_c' => int(
|
||||
sprintf( "%.1f",
|
||||
$data->{main}->{temp_max}) + 0.5
|
||||
sprintf( "%.1f", $data->{main}->{temp_max} ) +
|
||||
0.5
|
||||
),
|
||||
'tempLow' => int(
|
||||
sprintf( "%.1f",
|
||||
$data->{main}->{temp_min}) + 0.5
|
||||
sprintf( "%.1f", $data->{main}->{temp_min} ) +
|
||||
0.5
|
||||
),
|
||||
'tempHigh' => int(
|
||||
sprintf( "%.1f",
|
||||
$data->{main}->{temp_max}) + 0.5
|
||||
sprintf( "%.1f", $data->{main}->{temp_max} ) +
|
||||
0.5
|
||||
),
|
||||
'tempFeelsLike_c' => int(
|
||||
sprintf( "%.1f",
|
||||
$data->{main}->{feels_like}) + 0.5
|
||||
sprintf( "%.1f", $data->{main}->{feels_like} )
|
||||
+ 0.5
|
||||
),
|
||||
'humidity' => $data->{main}->{humidity},
|
||||
'condition' => encode_utf8(
|
||||
@ -488,8 +489,8 @@ sub _ProcessingRetrieveData {
|
||||
"%a, %e %b %Y %H:%M",
|
||||
localtime( $data->{dt} )
|
||||
),
|
||||
'visibility' => int( sprintf(
|
||||
"%.1f", $data->{visibility} ) + 0.5
|
||||
'visibility' => int(
|
||||
sprintf( "%.1f", $data->{visibility} ) + 0.5
|
||||
),
|
||||
|
||||
};
|
||||
@ -549,14 +550,12 @@ sub _ProcessingRetrieveData {
|
||||
) + 0.5
|
||||
),
|
||||
'dew_point' => int(
|
||||
sprintf(
|
||||
"%.1f",
|
||||
$data->{hourly}->[$i]->{dew_point}
|
||||
) + 0.5
|
||||
sprintf( "%.1f",
|
||||
$data->{hourly}->[$i]
|
||||
->{dew_point} ) + 0.5
|
||||
),
|
||||
'humidity' =>
|
||||
$data->{hourly}->[$i]
|
||||
->{humidity},
|
||||
$data->{hourly}->[$i]->{humidity},
|
||||
'condition' => encode_utf8(
|
||||
$data->{hourly}->[$i]->{weather}
|
||||
->[0]->{description}
|
||||
@ -594,8 +593,7 @@ sub _ProcessingRetrieveData {
|
||||
) + 0.5
|
||||
),
|
||||
'cloudCover' =>
|
||||
$data->{hourly}->[$i]
|
||||
->{clouds},
|
||||
$data->{hourly}->[$i]->{clouds},
|
||||
'code' => $codes{
|
||||
$data->{hourly}->[$i]->{weather}
|
||||
->[0]->{id}
|
||||
@ -607,11 +605,11 @@ sub _ProcessingRetrieveData {
|
||||
$data->{hourly}->[$i]->{rain}->{'1h'},
|
||||
'snow1h' =>
|
||||
$data->{hourly}->[$i]->{snow}->{'1h'},
|
||||
'uvi' =>
|
||||
$data->{hourly}->[$i]->{uvi},
|
||||
'visibility' => int( sprintf(
|
||||
"%.1f", $data->{hourly}->[$i]->{visibility} )
|
||||
+ 0.5
|
||||
'uvi' => $data->{hourly}->[$i]->{uvi},
|
||||
'visibility' => int(
|
||||
sprintf( "%.1f",
|
||||
$data->{hourly}->[$i]
|
||||
->{visibility} ) + 0.5
|
||||
),
|
||||
},
|
||||
);
|
||||
@ -669,8 +667,8 @@ sub _ProcessingRetrieveData {
|
||||
) - 3600
|
||||
)
|
||||
),
|
||||
'moon_phase' => $data->{daily}->[$i]
|
||||
->{moon_phase},
|
||||
'moon_phase' =>
|
||||
$data->{daily}->[$i]->{moon_phase},
|
||||
'moonset' => strftime(
|
||||
"%a, %H:%M",
|
||||
localtime(
|
||||
@ -681,88 +679,75 @@ sub _ProcessingRetrieveData {
|
||||
)
|
||||
),
|
||||
'temperature' => int(
|
||||
sprintf(
|
||||
"%.1f",
|
||||
$data->{daily}->[$i]->{temp}->{day}
|
||||
) + 0.5
|
||||
sprintf( "%.1f",
|
||||
$data->{daily}->[$i]->{temp}
|
||||
->{day} ) + 0.5
|
||||
),
|
||||
'temperature_morn' => int(
|
||||
sprintf(
|
||||
"%.1f",
|
||||
$data->{daily}->[$i]->{temp}->{morn}
|
||||
) + 0.5
|
||||
sprintf( "%.1f",
|
||||
$data->{daily}->[$i]->{temp}
|
||||
->{morn} ) + 0.5
|
||||
),
|
||||
'temperature_eve' => int(
|
||||
sprintf(
|
||||
"%.1f",
|
||||
$data->{daily}->[$i]->{temp}->{eve}
|
||||
) + 0.5
|
||||
sprintf( "%.1f",
|
||||
$data->{daily}->[$i]->{temp}
|
||||
->{eve} ) + 0.5
|
||||
),
|
||||
'temperature_night' => int(
|
||||
sprintf(
|
||||
"%.1f",
|
||||
$data->{daily}->[$i]->{temp}->{night}
|
||||
) + 0.5
|
||||
sprintf( "%.1f",
|
||||
$data->{daily}->[$i]->{temp}
|
||||
->{night} ) + 0.5
|
||||
),
|
||||
'tempFeelsLike_morn' => int(
|
||||
sprintf(
|
||||
"%.1f",
|
||||
$data->{daily}->[$i]->{feels_like}->{morn}
|
||||
) + 0.5
|
||||
sprintf( "%.1f",
|
||||
$data->{daily}->[$i]
|
||||
->{feels_like}->{morn} ) + 0.5
|
||||
),
|
||||
'tempFeelsLike_eve' => int(
|
||||
sprintf(
|
||||
"%.1f",
|
||||
$data->{daily}->[$i]->{feels_like}->{eve}
|
||||
) + 0.5
|
||||
sprintf( "%.1f",
|
||||
$data->{daily}->[$i]
|
||||
->{feels_like}->{eve} ) + 0.5
|
||||
),
|
||||
'tempFeelsLike_night' => int(
|
||||
sprintf(
|
||||
"%.1f",
|
||||
$data->{daily}->[$i]->{feels_like}->{night}
|
||||
) + 0.5
|
||||
sprintf( "%.1f",
|
||||
$data->{daily}->[$i]
|
||||
->{feels_like}->{night} ) +
|
||||
0.5
|
||||
),
|
||||
'tempFeelsLike_day' => int(
|
||||
sprintf(
|
||||
"%.1f",
|
||||
$data->{daily}->[$i]->{feels_like}->{day}
|
||||
) + 0.5
|
||||
sprintf( "%.1f",
|
||||
$data->{daily}->[$i]
|
||||
->{feels_like}->{day} ) + 0.5
|
||||
),
|
||||
'temp_c' => int(
|
||||
sprintf(
|
||||
"%.1f",
|
||||
$data->{daily}->[$i]->{temp}->{day}
|
||||
) + 0.5
|
||||
sprintf( "%.1f",
|
||||
$data->{daily}->[$i]->{temp}
|
||||
->{day} ) + 0.5
|
||||
),
|
||||
'low_c' => int(
|
||||
sprintf(
|
||||
"%.1f",
|
||||
$data->{daily}->[$i]->{temp}->{min}
|
||||
) + 0.5
|
||||
sprintf( "%.1f",
|
||||
$data->{daily}->[$i]->{temp}
|
||||
->{min} ) + 0.5
|
||||
),
|
||||
'high_c' => int(
|
||||
sprintf(
|
||||
"%.1f",
|
||||
$data->{daily}->[$i]->{temp}->{max}
|
||||
) + 0.5
|
||||
sprintf( "%.1f",
|
||||
$data->{daily}->[$i]->{temp}
|
||||
->{max} ) + 0.5
|
||||
),
|
||||
'tempLow' => int(
|
||||
sprintf(
|
||||
"%.1f",
|
||||
$data->{daily}->[$i]->{temp}->{min}
|
||||
) + 0.5
|
||||
sprintf( "%.1f",
|
||||
$data->{daily}->[$i]->{temp}
|
||||
->{min} ) + 0.5
|
||||
),
|
||||
'tempHigh' => int(
|
||||
sprintf(
|
||||
"%.1f",
|
||||
$data->{daily}->[$i]->{temp}->{max}
|
||||
) + 0.5
|
||||
sprintf( "%.1f",
|
||||
$data->{daily}->[$i]->{temp}
|
||||
->{max} ) + 0.5
|
||||
),
|
||||
'dew_point' => int(
|
||||
sprintf(
|
||||
"%.1f",
|
||||
$data->{daily}->[$i]->{dew_point}
|
||||
) + 0.5
|
||||
sprintf( "%.1f",
|
||||
$data->{daily}->[$i]
|
||||
->{dew_point} ) + 0.5
|
||||
),
|
||||
'humidity' =>
|
||||
$data->{daily}->[$i]->{humidity},
|
||||
@ -770,8 +755,13 @@ sub _ProcessingRetrieveData {
|
||||
$data->{daily}->[$i]->{weather}
|
||||
->[0]->{description}
|
||||
),
|
||||
'code' => $codes{ $data->{daily}->[$i]->{weather}->[0]->{id} },
|
||||
'iconAPI' => $data->{daily}->[$i]->{weather}->[0]->{icon},
|
||||
'code' => $codes{
|
||||
$data->{daily}->[$i]->{weather}
|
||||
->[0]->{id}
|
||||
},
|
||||
'iconAPI' =>
|
||||
$data->{daily}->[$i]->{weather}->[0]
|
||||
->{icon},
|
||||
'pressure' => int(
|
||||
sprintf( "%.1f",
|
||||
$data->{daily}->[$i]->{pressure}
|
||||
@ -843,27 +833,40 @@ sub _ProcessingRetrieveData {
|
||||
push(
|
||||
@{ $self->{cached}->{alerts} },
|
||||
{
|
||||
'warn_'.$i.'_End' => strftimeWrapper(
|
||||
'warn_'
|
||||
. $i
|
||||
. '_End' => strftimeWrapper(
|
||||
"%a, %e %b %Y %H:%M",
|
||||
localtime(
|
||||
( $data->{alerts}->[$i]->{end} )
|
||||
- 3600
|
||||
(
|
||||
$data->{alerts}->[$i]->{end}
|
||||
) - 3600
|
||||
)
|
||||
),
|
||||
'warn_'.$i.'_Start' => strftimeWrapper(
|
||||
'warn_'
|
||||
. $i
|
||||
. '_Start' => strftimeWrapper(
|
||||
"%a, %e %b %Y %H:%M",
|
||||
localtime(
|
||||
( $data->{alerts}->[$i]->{start} )
|
||||
- 3600
|
||||
(
|
||||
$data->{alerts}->[$i]
|
||||
->{start}
|
||||
) - 3600
|
||||
)
|
||||
),
|
||||
'warn_'.$i.'_Description' => encode_utf8(
|
||||
'warn_'
|
||||
. $i
|
||||
. '_Description' => encode_utf8(
|
||||
$data->{alerts}->[$i]->{description}
|
||||
),
|
||||
'warn_'.$i.'_SenderName' => encode_utf8(
|
||||
'warn_'
|
||||
. $i
|
||||
. '_SenderName' => encode_utf8(
|
||||
$data->{alerts}->[$i]->{sender_name}
|
||||
),
|
||||
'warn_'.$i.'_Event' => encode_utf8(
|
||||
'warn_'
|
||||
. $i
|
||||
. '_Event' => encode_utf8(
|
||||
$data->{alerts}->[$i]->{event}
|
||||
),
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user