diff --git a/fhem/FHEM/59_Weather.pm b/fhem/FHEM/59_Weather.pm index 37bfc2f00..c1a30b4f6 100755 --- a/fhem/FHEM/59_Weather.pm +++ b/fhem/FHEM/59_Weather.pm @@ -163,6 +163,33 @@ my @iconlist = ( 'sunny', 'scatteredthunderstorms', 'scatteredthunderstorms', 'scatteredthunderstorms', 'scatteredshowers', 'heavysnow', 'chance_of_snow', 'heavysnow', 'partly_cloudy', 'heavyrain', 'chance_of_snow', 'scatteredshowers'); +my @months= qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/; +my %monthindex; +@monthindex{@months} = (0..$#months); + +sub Weather_ParseDateTime($) { + + my ($value)= @_; ### "Fri, 13 Nov 2015 8:00 am CET" + + if($value =~ '^(\w{3}), (\d{1,2}) (\w{3}) (\d{4}) (\d{1,2}):(\d{2}) (\w{2}) (\w{3})$') { + my ($wd, $d, $mon, $y, $h, $n, $p, $tz)= ($1,$2,$3,$4,$5,$6,$7,$8); + # 12 AM= 0, 12 PM= 12 + $h+=12 if($h==12); if($p eq "pm") { $h= ($h+12) % 24 } else { $h%= 12 }; + my $m= $monthindex{$mon}; + return undef unless $m; + #main::Debug "###### $value -> $wd $d $m $y $h:$n $tz"; + # $mday= 1.. + # $month= 0..11 + # $year is year-1900 + # we ignore the time zone as it probably never changes for a weather device an assume + # local time zone + return fhemTimeLocal(0, $n, $h, $d, $m, $y-1900); + } else { + return undef; + } +} + + ################################### sub Weather_DebugCodes() { @@ -340,17 +367,14 @@ sub Weather_RetrieveDataFinished($$$) my $value= $1; ### pubDate Fri, 13 Nov 2015 8:00 am CET $urlResult->{"readings"}->{"pubDate"}= $value; - my $strp = DateTime::Format::Strptime->new( - pattern => '%a, %d %b %Y %I:%M %p %Z', - locale => 'en_US'); - ##main::Debug "pubDate= $value"; - my $ts= $strp->parse_datetime($value); + + my $ts= Weather_ParseDateTime($value); if(defined($ts)) { - $urlResult->{"readings"}->{"pubDateTs"}= $ts->epoch(); + $urlResult->{"readings"}->{"pubDateTs"}= $ts; $urlResult->{"readings"}->{"pubDateComment"}= "okay"; } else { $urlResult->{"readings"}->{"pubDateTs"}= 0; - $urlResult->{"readings"}->{"pubDateComment"}= "pubDate: " . $strp->errmsg unless(defined($ts)); + $urlResult->{"readings"}->{"pubDateComment"}= "could not parse pubDate $value"; } next; } @@ -458,8 +482,9 @@ sub Weather_RetrieveDataFinished($$$) my $ts2= $urlResult->{"readings"}->{"pubDateTs"}; readingsBeginUpdate($hash); + readingsBulkUpdate($hash, "pubDateRemote", $urlResult->{"readings"}->{"pubDate"}); - main::Debug "ts1= $ts1, ts2= $ts2"; + #main::Debug "ts1= $ts1, ts2= $ts2"; if($ts1 && $ts2 && ($ts2< $ts1)) { readingsBulkUpdate($hash, "validity", "stale"); @@ -740,9 +765,6 @@ WeatherAsHtmlD($;$)
Defines a virtual device for weather forecasts.

- You need the DateTime::Format::Strptime perl module. On Debian and derivatives, it can be installed - via apt-get install libdatetime-format-strptime-perl. - A Weather device periodically gathers current and forecast weather conditions from the Yahoo Weather API.

@@ -825,6 +847,14 @@ WeatherAsHtmlD($;$) wind_directiondirection wind comes from in degrees (0 = north wind) wind_speedsame as wind +
+ The following readings help to identify whether a workaround has kicked in to avoid the retrieval of + stale data from the remote server: + + + + +
pubDatepublication time of forecast for current set of readings
pubDateRemotepublication time of forecast as seen on remote server
validitystale, if publication time as seen on remote server is before that of current set of readings

@@ -853,9 +883,6 @@ WeatherAsHtmlD($;$)
Bezechnet ein virtuelles Gerät für Wettervorhersagen.

- Man braucht das Perl-Modul DateTime::Format::Strptime. Auf Debian und seinen Derivaten wird es - via apt-get install libdatetime-format-strptime-perl installiert. - Eine solche virtuelle Wetterstation sammelt periodisch aktuelle und zukünftige Wetterdaten aus der Yahoo-Wetter-API.

Der Parameter location entspricht der sechsstelligen WOEID (WHERE-ON-EARTH-ID). Die WOEID für den eigenen Standort kann auf http://weather.yahoo.com gefunden werden.

@@ -923,6 +950,14 @@ WeatherAsHtmlD($;$) wind_directionGradangabe der Windrichtung (0 = Nordwind) wind_speedWindgeschwindigkeit in km/h (mit wind identisch) +
+ Die folgenden Daten helfen zu identifizieren, ob ein Workaround angeschlagen hat, der die Verwendung von + veralteten Daten auf dem entfernten Server verhindert: + + + + +
pubDateVeröffentlichungszeitpunkt der Wettervorhersage in den aktuellen Daten (readings)
pubDateRemoteVeröffentlichungszeitpunkt der Wettervorhersage auf dem entfernten Server
validitystale, wenn der Veröffentlichungszeitpunkt auf dem entfernten Server vor dem Zeitpunkt der aktuellen Daten (readings) liegt