testing #29

Merged
marko merged 73 commits from testing into main 2023-01-07 12:49:01 +00:00
2 changed files with 210 additions and 215 deletions
Showing only changes of commit 8ec9dae902 - Show all commits

View File

@ -38,7 +38,6 @@ use Readonly;
use FHEM::Meta; use FHEM::Meta;
use vars qw($FW_ss); use vars qw($FW_ss);
# use Data::Dumper; # for Debug only # use Data::Dumper; # for Debug only
my %pressure_trend_txt_en = ( 0 => "steady", 1 => "rising", 2 => "falling" ); my %pressure_trend_txt_en = ( 0 => "steady", 1 => "rising", 2 => "falling" );
@ -358,7 +357,6 @@ sub Weather_WriteReadings {
my $daily = ( AttrVal( $name, 'forecast', '' ) =~ m{daily}xms ? 1 : 0 ); my $daily = ( AttrVal( $name, 'forecast', '' ) =~ m{daily}xms ? 1 : 0 );
my $alerts = ( AttrVal( $name, 'forecast', '' ) =~ m{alerts}xms ? 1 : 0 ); my $alerts = ( AttrVal( $name, 'forecast', '' ) =~ m{alerts}xms ? 1 : 0 );
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
# housekeeping information # housekeeping information
@ -403,12 +401,10 @@ sub Weather_WriteReadings {
&& ( $hourly || $daily ) ) && ( $hourly || $daily ) )
{ {
## hourly ## hourly
if ( if ( defined( $dataRef->{forecast}->{hourly} )
defined( $dataRef->{forecast}->{hourly} )
&& ref( $dataRef->{forecast}->{hourly} ) eq 'ARRAY' && ref( $dataRef->{forecast}->{hourly} ) eq 'ARRAY'
&& scalar( @{ $dataRef->{forecast}->{hourly} } ) > 0 && scalar( @{ $dataRef->{forecast}->{hourly} } ) > 0
&& $hourly && $hourly )
)
{ {
my $i = 0; my $i = 0;
my $limit = AttrVal( $name, 'forecastLimit', -1 ); my $limit = AttrVal( $name, 'forecastLimit', -1 );
@ -458,12 +454,10 @@ sub Weather_WriteReadings {
} }
## daily ## daily
if ( if ( defined( $dataRef->{forecast}->{daily} )
defined( $dataRef->{forecast}->{daily} )
&& ref( $dataRef->{forecast}->{daily} ) eq 'ARRAY' && ref( $dataRef->{forecast}->{daily} ) eq 'ARRAY'
&& scalar( @{ $dataRef->{forecast}->{daily} } ) > 0 && scalar( @{ $dataRef->{forecast}->{daily} } ) > 0
&& $daily && $daily )
)
{ {
my $i = 0; my $i = 0;
my $limit = AttrVal( $name, 'forecastLimit', -1 ); my $limit = AttrVal( $name, 'forecastLimit', -1 );
@ -610,8 +604,7 @@ sub Weather_Set {
{ {
if ( $hash->{API} eq 'DarkSkyAPI' if ( $hash->{API} eq 'DarkSkyAPI'
|| $hash->{API} eq 'OpenWeatherMapAPI' || $hash->{API} eq 'OpenWeatherMapAPI'
|| $hash->{API} eq 'wundergroundAPI' || $hash->{API} eq 'wundergroundAPI' )
)
{ {
my ( $lat, $long ); my ( $lat, $long );
( $lat, $long ) = split( ',', $aRef->[0] ) ( $lat, $long ) = split( ',', $aRef->[0] )
@ -689,7 +682,6 @@ sub Weather_Define {
my $aRef = shift // return; my $aRef = shift // return;
my $hRef = shift // undef; my $hRef = shift // undef;
return $@ unless ( FHEM::Meta::SetInternals($hash) ); return $@ unless ( FHEM::Meta::SetInternals($hash) );
use version 0.60; our $VERSION = FHEM::Meta::Get( $hash, 'version' ); use version 0.60; our $VERSION = FHEM::Meta::Get( $hash, 'version' );
@ -774,7 +766,7 @@ sub Weather_Attr {
given ($attrName) { given ($attrName) {
when ('forecast') { when ('forecast') {
if ( $cmd eq 'set' ) { if ( $cmd eq 'set' ) {
$hash->{fhem}->{api}->setForecast($attrVal) $hash->{fhem}->{api}->setForecast($attrVal);
} }
$hash->{fhem}->{api}->setForecast(); $hash->{fhem}->{api}->setForecast();

View File

@ -205,7 +205,8 @@ sub new {
: 900 : 900
); );
$self->{apiversion} = ($apioptions->{version} ? $apioptions->{version} : '2.5'); $self->{apiversion} =
( $apioptions->{version} ? $apioptions->{version} : '2.5' );
$self->{cached} = _CreateForecastRef($self); $self->{cached} = _CreateForecastRef($self);
@ -339,9 +340,11 @@ sub _RetrieveDataFromOpenWeatherMap {
. $self->{lat} . '&' . 'lon=' . $self->{lat} . '&' . 'lon='
. $self->{long} . '&' . $self->{long} . '&'
. 'APPID=' . 'APPID='
. $self->{key} . '&' . 'units=' . $self->{key} . '&'
. 'units='
. 'metric' . '&' . 'lang=' . 'metric' . '&' . 'lang='
. $self->{lang} . '&' . 'exclude=' . $self->{lang} . '&'
. 'exclude='
. _createExcludeString( $self->{forecast}, $self->{alerts} ); . _createExcludeString( $self->{forecast}, $self->{alerts} );
::HttpUtils_NonblockingGet($paramRef); ::HttpUtils_NonblockingGet($paramRef);
@ -424,32 +427,30 @@ sub _ProcessingRetrieveData {
$self->{cached}->{license}{text} = 'none'; $self->{cached}->{license}{text} = 'none';
$self->{cached}->{current} = { $self->{cached}->{current} = {
'temperature' => int( 'temperature' => int(
sprintf( "%.1f", sprintf( "%.1f", $data->{main}->{temp} ) + 0.5
$data->{main}->{temp}) + 0.5
), ),
'temp_c' => int( 'temp_c' => int(
sprintf( "%.1f", sprintf( "%.1f", $data->{main}->{temp} ) + 0.5
$data->{main}->{temp}) + 0.5
), ),
'low_c' => int( 'low_c' => int(
sprintf( "%.1f", sprintf( "%.1f", $data->{main}->{temp_min} ) +
$data->{main}->{temp_min}) + 0.5 0.5
), ),
'high_c' => int( 'high_c' => int(
sprintf( "%.1f", sprintf( "%.1f", $data->{main}->{temp_max} ) +
$data->{main}->{temp_max}) + 0.5 0.5
), ),
'tempLow' => int( 'tempLow' => int(
sprintf( "%.1f", sprintf( "%.1f", $data->{main}->{temp_min} ) +
$data->{main}->{temp_min}) + 0.5 0.5
), ),
'tempHigh' => int( 'tempHigh' => int(
sprintf( "%.1f", sprintf( "%.1f", $data->{main}->{temp_max} ) +
$data->{main}->{temp_max}) + 0.5 0.5
), ),
'tempFeelsLike_c' => int( 'tempFeelsLike_c' => int(
sprintf( "%.1f", sprintf( "%.1f", $data->{main}->{feels_like} )
$data->{main}->{feels_like}) + 0.5 + 0.5
), ),
'humidity' => $data->{main}->{humidity}, 'humidity' => $data->{main}->{humidity},
'condition' => encode_utf8( 'condition' => encode_utf8(
@ -488,8 +489,8 @@ sub _ProcessingRetrieveData {
"%a, %e %b %Y %H:%M", "%a, %e %b %Y %H:%M",
localtime( $data->{dt} ) localtime( $data->{dt} )
), ),
'visibility' => int( sprintf( 'visibility' => int(
"%.1f", $data->{visibility} ) + 0.5 sprintf( "%.1f", $data->{visibility} ) + 0.5
), ),
}; };
@ -549,14 +550,12 @@ sub _ProcessingRetrieveData {
) + 0.5 ) + 0.5
), ),
'dew_point' => int( 'dew_point' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{hourly}->[$i]
$data->{hourly}->[$i]->{dew_point} ->{dew_point} ) + 0.5
) + 0.5
), ),
'humidity' => 'humidity' =>
$data->{hourly}->[$i] $data->{hourly}->[$i]->{humidity},
->{humidity},
'condition' => encode_utf8( 'condition' => encode_utf8(
$data->{hourly}->[$i]->{weather} $data->{hourly}->[$i]->{weather}
->[0]->{description} ->[0]->{description}
@ -594,8 +593,7 @@ sub _ProcessingRetrieveData {
) + 0.5 ) + 0.5
), ),
'cloudCover' => 'cloudCover' =>
$data->{hourly}->[$i] $data->{hourly}->[$i]->{clouds},
->{clouds},
'code' => $codes{ 'code' => $codes{
$data->{hourly}->[$i]->{weather} $data->{hourly}->[$i]->{weather}
->[0]->{id} ->[0]->{id}
@ -607,11 +605,11 @@ sub _ProcessingRetrieveData {
$data->{hourly}->[$i]->{rain}->{'1h'}, $data->{hourly}->[$i]->{rain}->{'1h'},
'snow1h' => 'snow1h' =>
$data->{hourly}->[$i]->{snow}->{'1h'}, $data->{hourly}->[$i]->{snow}->{'1h'},
'uvi' => 'uvi' => $data->{hourly}->[$i]->{uvi},
$data->{hourly}->[$i]->{uvi}, 'visibility' => int(
'visibility' => int( sprintf( sprintf( "%.1f",
"%.1f", $data->{hourly}->[$i]->{visibility} ) $data->{hourly}->[$i]
+ 0.5 ->{visibility} ) + 0.5
), ),
}, },
); );
@ -669,8 +667,8 @@ sub _ProcessingRetrieveData {
) - 3600 ) - 3600
) )
), ),
'moon_phase' => $data->{daily}->[$i] 'moon_phase' =>
->{moon_phase}, $data->{daily}->[$i]->{moon_phase},
'moonset' => strftime( 'moonset' => strftime(
"%a, %H:%M", "%a, %H:%M",
localtime( localtime(
@ -681,88 +679,75 @@ sub _ProcessingRetrieveData {
) )
), ),
'temperature' => int( 'temperature' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]->{temp}
$data->{daily}->[$i]->{temp}->{day} ->{day} ) + 0.5
) + 0.5
), ),
'temperature_morn' => int( 'temperature_morn' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]->{temp}
$data->{daily}->[$i]->{temp}->{morn} ->{morn} ) + 0.5
) + 0.5
), ),
'temperature_eve' => int( 'temperature_eve' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]->{temp}
$data->{daily}->[$i]->{temp}->{eve} ->{eve} ) + 0.5
) + 0.5
), ),
'temperature_night' => int( 'temperature_night' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]->{temp}
$data->{daily}->[$i]->{temp}->{night} ->{night} ) + 0.5
) + 0.5
), ),
'tempFeelsLike_morn' => int( 'tempFeelsLike_morn' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]
$data->{daily}->[$i]->{feels_like}->{morn} ->{feels_like}->{morn} ) + 0.5
) + 0.5
), ),
'tempFeelsLike_eve' => int( 'tempFeelsLike_eve' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]
$data->{daily}->[$i]->{feels_like}->{eve} ->{feels_like}->{eve} ) + 0.5
) + 0.5
), ),
'tempFeelsLike_night' => int( 'tempFeelsLike_night' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]
$data->{daily}->[$i]->{feels_like}->{night} ->{feels_like}->{night} ) +
) + 0.5 0.5
), ),
'tempFeelsLike_day' => int( 'tempFeelsLike_day' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]
$data->{daily}->[$i]->{feels_like}->{day} ->{feels_like}->{day} ) + 0.5
) + 0.5
), ),
'temp_c' => int( 'temp_c' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]->{temp}
$data->{daily}->[$i]->{temp}->{day} ->{day} ) + 0.5
) + 0.5
), ),
'low_c' => int( 'low_c' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]->{temp}
$data->{daily}->[$i]->{temp}->{min} ->{min} ) + 0.5
) + 0.5
), ),
'high_c' => int( 'high_c' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]->{temp}
$data->{daily}->[$i]->{temp}->{max} ->{max} ) + 0.5
) + 0.5
), ),
'tempLow' => int( 'tempLow' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]->{temp}
$data->{daily}->[$i]->{temp}->{min} ->{min} ) + 0.5
) + 0.5
), ),
'tempHigh' => int( 'tempHigh' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]->{temp}
$data->{daily}->[$i]->{temp}->{max} ->{max} ) + 0.5
) + 0.5
), ),
'dew_point' => int( 'dew_point' => int(
sprintf( sprintf( "%.1f",
"%.1f", $data->{daily}->[$i]
$data->{daily}->[$i]->{dew_point} ->{dew_point} ) + 0.5
) + 0.5
), ),
'humidity' => 'humidity' =>
$data->{daily}->[$i]->{humidity}, $data->{daily}->[$i]->{humidity},
@ -770,8 +755,13 @@ sub _ProcessingRetrieveData {
$data->{daily}->[$i]->{weather} $data->{daily}->[$i]->{weather}
->[0]->{description} ->[0]->{description}
), ),
'code' => $codes{ $data->{daily}->[$i]->{weather}->[0]->{id} }, 'code' => $codes{
'iconAPI' => $data->{daily}->[$i]->{weather}->[0]->{icon}, $data->{daily}->[$i]->{weather}
->[0]->{id}
},
'iconAPI' =>
$data->{daily}->[$i]->{weather}->[0]
->{icon},
'pressure' => int( 'pressure' => int(
sprintf( "%.1f", sprintf( "%.1f",
$data->{daily}->[$i]->{pressure} $data->{daily}->[$i]->{pressure}
@ -843,27 +833,40 @@ sub _ProcessingRetrieveData {
push( push(
@{ $self->{cached}->{alerts} }, @{ $self->{cached}->{alerts} },
{ {
'warn_'.$i.'_End' => strftimeWrapper( 'warn_'
. $i
. '_End' => strftimeWrapper(
"%a, %e %b %Y %H:%M", "%a, %e %b %Y %H:%M",
localtime( 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", "%a, %e %b %Y %H:%M",
localtime( 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} $data->{alerts}->[$i]->{description}
), ),
'warn_'.$i.'_SenderName' => encode_utf8( 'warn_'
. $i
. '_SenderName' => encode_utf8(
$data->{alerts}->[$i]->{sender_name} $data->{alerts}->[$i]->{sender_name}
), ),
'warn_'.$i.'_Event' => encode_utf8( 'warn_'
. $i
. '_Event' => encode_utf8(
$data->{alerts}->[$i]->{event} $data->{alerts}->[$i]->{event}
), ),
}, },