From 1f6aa21e2ccd4743b96882c2bd77a025ecf3b8cc Mon Sep 17 00:00:00 2001 From: LeonGaultier Date: Mon, 18 Mar 2019 12:43:26 +0000 Subject: [PATCH] 59_Weather: fix weblink bug, add extended hourly data format git-svn-id: https://svn.fhem.de/fhem/trunk@18958 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 2 + fhem/FHEM/59_Weather.pm | 88 +++++++++++++++++++---------------------- fhem/FHEM/DarkSkyAPI.pm | 4 +- 3 files changed, 44 insertions(+), 50 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 90372db9c..3d0f17cdc 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,7 @@ # 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. + - bugfix/feature: 59_Weather/API's: fix weblink bug, add extended hourly + data format - feature: 55_DWD_OpenData: - new readings SunRise, SunSet - SunUp based on upper solar limb - support warncells beginning with 7 diff --git a/fhem/FHEM/59_Weather.pm b/fhem/FHEM/59_Weather.pm index 814131c0a..a09bc5d1d 100755 --- a/fhem/FHEM/59_Weather.pm +++ b/fhem/FHEM/59_Weather.pm @@ -92,13 +92,13 @@ my %wdays_txt_de = ( 'Sun' => 'So' ); my %wdays_txt_nl = ( - 'Mon' => 'Maa', - 'Tue' => 'Din', - 'Wed' => 'Woe', - 'Thu' => 'Don', - 'Fri' => 'Vri', - 'Sat' => 'Zat', - 'Sun' => 'Zon' + 'Mon' => 'Ma', + 'Tue' => 'Di', + 'Wed' => 'Wo', + 'Thu' => 'Do', + 'Fri' => 'Vr', + 'Sat' => 'Za', + 'Sun' => 'Zo' ); my %wdays_txt_fr = ( 'Mon' => 'Lun', @@ -146,7 +146,7 @@ my %status_items_txt_nl = ( 0 => "Wind", 1 => "Vochtigheid", 2 => "Temperatuur", - 3 => "Direct", + 3 => "Actueel", 4 => "Weersvoorspelling voor " ); my %status_items_txt_fr = ( @@ -715,18 +715,8 @@ sub WeatherIconIMGTag($) { sub WeatherAsHtmlV($;$$) { my ( $d, $op1, $op2 ) = @_; - my $items = $op2; - my $f = $op1; - if($op1 =~ /[0-9]/g){ $items = $op1; } - if($op2 =~ /[dh]/g){ $f = $op2; } - - $f =~ tr/dh/./cd; - $f = "h" if ( !$f || length($f) > 1); - $items =~ tr/0-9/./cd; - $items = 6 if ( !$items ); - return "$d is not a Weather instance
" - if ( !$defs{$d} || $defs{$d}->{TYPE} ne "Weather" ); + my ($f,$items) = WeatherCheckOptions($d,$op1,$op2); my $h = $defs{$d}; my $width = int( ICONSCALE * ICONWIDTH ); @@ -791,33 +781,16 @@ sub WeatherAsHtmlV($;$$) { sub WeatherAsHtml($;$$) { my ( $d, $op1, $op2 ) = @_; - my $items = $op2; - my $f = $op1; - if($op1 =~ /[0-9]/g){ $items = $op1; } - if($op2 =~ /[dh]/g){ $f = $op2; } - - $f =~ tr/dh/./cd; - $f = "h" if ( !$f || length($f) > 1); - $items =~ tr/0-9/./cd; - $items = 6 if ( !$items ); + + my ($f,$items) = WeatherCheckOptions($d,$op1,$op2); WeatherAsHtmlV( $d, $f, $items ); } sub WeatherAsHtmlH($;$$) { my ( $d, $op1, $op2 ) = @_; - my $items = $op2; - my $f = $op1; - if($op1 =~ /[0-9]/g){ $items = $op1; } - if($op2 =~ /[dh]/g){ $f = $op2; } - - $f =~ tr/dh/./cd; - $f = "h" if ( !$f || length($f) > 1); - $items =~ tr/0-9/./cd; - $items = 6 if ( !$items ); - - return "$d is not a Weather instance
" - if ( !$defs{$d} || $defs{$d}->{TYPE} ne "Weather" ); + + my ($f,$items) = WeatherCheckOptions($d,$op1,$op2); my $h = $defs{$d}; my $width = int( ICONSCALE * ICONWIDTH ); @@ -902,15 +875,8 @@ sub WeatherAsHtmlH($;$$) { sub WeatherAsHtmlD($;$$) { my ( $d, $op1, $op2 ) = @_; - my $items = $op2; - my $f = $op1; - if($op1 =~ /[0-9]/g){ $items = $op1; } - if($op2 =~ /[dh]/g){ $f = $op2; } - $f =~ tr/dh/./cd; - $f = "h" if ( !$f || length($f) > 1); - $items =~ tr/0-9/./cd; - $items = 6 if ( !$items ); + my ($f,$items) = WeatherCheckOptions($d,$op1,$op2); if ($FW_ss) { WeatherAsHtmlV( $d, $f , $items); @@ -920,6 +886,32 @@ sub WeatherAsHtmlD($;$$) { } } +sub WeatherCheckOptions($@) { + my ($d,$op1,$op2) = @_; + + my $items = $op2; + my $f = $op1; + + if( defined($op1) and $op1 and $op1 =~ /[0-9]/g){ $items = $op1; } + if( defined($op2) and $op2 and $op2 =~ /[dh]/g){ $f = $op2; } + + $f =~ tr/dh/./cd if ( defined $f and $f ); + $items =~ tr/0-9/./cd if (defined($items) and $items ); + + $items = 6 if ( !$items ); + + return "$d is not a Weather instance
" + if ( !$defs{$d} || $defs{$d}->{TYPE} ne "Weather" ); + + if ( AttrVal($d,'forecast','none') ne 'none' ) { + $f = ( AttrVal($d,'forecast','none') eq 'daily' ? 'd' : 'h' ); + } + + $f = 'h' if ( !$f || length($f) > 1); + + return ($f,$items); +} + ##################################### 1; diff --git a/fhem/FHEM/DarkSkyAPI.pm b/fhem/FHEM/DarkSkyAPI.pm index 63f1c44ab..f7b1715eb 100644 --- a/fhem/FHEM/DarkSkyAPI.pm +++ b/fhem/FHEM/DarkSkyAPI.pm @@ -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 VERSION => '0.2.7'; +use constant VERSION => '0.2.8'; my %codes = ( 'clear-day' => 32, @@ -166,7 +166,7 @@ sub _RetrieveDataFromDarkSky($) { . $self->{long} . '?lang=' . $self->{lang} - . '&units=auto'; + . '&units=auto&extend=hourly'; if ( lc($self->{key}) eq 'demo' ) { _RetrieveDataFinished($paramRef,undef,DEMODATA); }