From 6ae59bac5d6ebb9736536205d9075bb6e5a42599 Mon Sep 17 00:00:00 2001 From: jensb Date: Mon, 14 May 2018 19:36:11 +0000 Subject: [PATCH] 55_DWD_OpenData.pm: fix platform dependent error "not a HASH reference" when updating alerts cache (Forum #83097) git-svn-id: https://svn.fhem.de/fhem/trunk@16739 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 2 ++ fhem/FHEM/55_DWD_OpenData.pm | 18 +++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 212f48ef3..0d0f7a980 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: 55_DWD_OpenData: updateAlertsCache causing "not a HASH reference" + error on some platforms (forum #83097) - change: 98_dewpoint: Don't manipulate STATE of target device if has stateFormat defined. - new: 55_DWD_OpenData: weather and alerts from DWD diff --git a/fhem/FHEM/55_DWD_OpenData.pm b/fhem/FHEM/55_DWD_OpenData.pm index 9ae692871..e44f47eb9 100644 --- a/fhem/FHEM/55_DWD_OpenData.pm +++ b/fhem/FHEM/55_DWD_OpenData.pm @@ -1024,7 +1024,7 @@ sub DWD_OpenData_GetAlertsBlockingFn($) # get communion (5, 8) or district (1, 9) alerts for Germany from DWD server my $communeUnion = DWD_OpenData_IsCommuneUnionWarncellId($warncellId); my $alertLanguage = AttrVal($name, 'alertLanguage', 'DE'); - my $url = 'https://opendata.dwd.de/weather/alerts/cap/'.($communeUnion? 'COMMUNEUNION' : 'DISTRICT').'_CELLS_STAT/Z_CAP_C_EDZW_LATEST_PVW_STATUS_PREMIUMCELLS_'.($communeUnion? 'COMMUNEUNION' : 'DISTRICT').'_'.$alertLanguage.'.zip'; + my $url = 'https://opendata.dwd.de/weather/alerts/cap/'.($communeUnion? 'COMMUNEUNION' : 'DISTRICT').'_CELLS_STAT/Z_CAP_C_EDZW_LATEST_PVW_STATUS_PREMIUMCELLS_'.($communeUnion? 'COMMUNEUNION' : 'DISTRICT').'_'.$alertLanguage.'.zip'; my $param = { url => $url, method => "GET", @@ -1216,10 +1216,10 @@ sub DWD_OpenData_ProcessAlerts($$$) Log3 $name, 3, "$name: DWD_OpenData_ProcessAlerts error: temp file name not defined"; } } - + # get rid of newlines and commas because of Blocking InformFn parameter restrictions - $errorMessage =~ s/\n/; /g; - $errorMessage =~ s/,/;/g; + $errorMessage =~ s/\n/; /g; + $errorMessage =~ s/,/;/g; Log3 $name, 5, "$name: DWD_OpenData_ProcessAlerts END"; @@ -1304,8 +1304,8 @@ sub DWD_OpenData_GetAlertsFinishFn(;$$$$) readingsSingleUpdate($hash, 'state', "alerts error: result file name not defined", 1); Log3 $name, 3, "$name: DWD_OpenData_GetAlertsFinishFn error: temp file name not defined"; } - - $hash->{ALERTS_IN_CACHE} = scalar(keys(%{$dwd_alerts[0]})) + scalar(keys(%{$dwd_alerts[1]})); + + $hash->{ALERTS_IN_CACHE} = (ref($dwd_alerts[0]) eq 'HASH'? scalar(keys(%{$dwd_alerts[0]})) : 0) + (ref($dwd_alerts[1]) eq 'HASH'? scalar(keys(%{$dwd_alerts[1]})) : 0); Log3 $name, 5, "$name: DWD_OpenData_GetAlertsFinishFn END"; } else { @@ -1460,6 +1460,9 @@ sub DWD_OpenData_Timer($) CHANGES + 13.05.2018 jensb + bugfix: total alerts in cache + 06.05.2018 jensb feature: detect empty alerts zip file bugfix: preprocess exception messages from ProcessAlerts because Blocking FinishFn parameter content may not contain commas or newlines @@ -1537,6 +1540,8 @@ sub DWD_OpenData_Timer($)
  • The weekday of the forecast will be in the language of your FHEM system. Enter {$ENV{LANG}} into the FHEM command line to verify. If nothing is displayed or you see an unexpected language setting, add export LANG=de_DE.UTF-8 or something similar to your FHEM start script, restart FHEM and check again. If you get a locale warning when starting FHEM the required language pack might be missing. It can be installed depending on your OS and your preferences (e.g. dpkg-reconfigure locales, apt-get install language-pack-de or something similar).

  • +
  • The digits in a warncell id of a communeunion or a district are mostly identical to an Amtliche Gemeindekennziffer if you strip of the 1st digit from the warncell id. You can lookup an Amtliche Gemeindekennziffer using the name of a communeunion or district e.g. at Statistische Ämter des Bundes und der Länder. Then add 8 for a communeunion or 1 or 9 for a district at the beginning and try to find an exact or near match in the Warncell-IDs for CAP alerts catalogue. This approach is an alternative to guessing the right warncell id by the name of a communeunion or district.

  • +
  • Like some other Perl modules this module temporarily modifies the TZ environment variable for timezone conversions. This may cause unexpected results in multi threaded environments.

  • The forecast reading names do not contain absolute days or hours to keep them independent of summertime adjustments. Forecast days are counted relative to "today" of the timezone defined by the attribute of the same name or the timezone specified by the Perl TZ environment variable if undefined.

  • @@ -1741,4 +1746,3 @@ sub DWD_OpenData_Timer($) =end html_DE =cut -