From efc5ed8badda8692da29c67616fb1a909f2698fd Mon Sep 17 00:00:00 2001 From: borisneubert <> Date: Tue, 29 Mar 2016 17:47:43 +0000 Subject: [PATCH] 59_Weather: reject data with wrong units git-svn-id: https://svn.fhem.de/fhem/trunk@11149 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/59_Weather.pm | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/fhem/FHEM/59_Weather.pm b/fhem/FHEM/59_Weather.pm index ca087e345..c91585328 100755 --- a/fhem/FHEM/59_Weather.pm +++ b/fhem/FHEM/59_Weather.pm @@ -143,6 +143,9 @@ sub Weather_RetrieveDataFinished($$$) { my $name= $hash->{NAME}; my $doTrigger= $argsRef->{blocking} ? 0 : 1; + + # the next 4 stanzas need to be rewritten, they are too repetitive for my taste + # check for error from retrieving data if($err) { Log3 $hash, 3, "$name: $err"; @@ -195,6 +198,21 @@ sub Weather_RetrieveDataFinished($$$) { } } + # units + my $units= YahooWeatherAPI_units($data); # units hash reference + if($units->{temperature} ne "C") { + $err= "wrong units received"; + Log3 $hash, 3, "$name: $err"; + readingsBeginUpdate($hash); + readingsBulkUpdate($hash, "lastError", $err); + readingsBulkUpdate($hash, "pubDateComment", $pubDateComment); + readingsBulkUpdate($hash, "pubDateRemote", $pubDate); + readingsBulkUpdate($hash, "validity", "stale"); + readingsEndUpdate($hash, $doTrigger); + Weather_RearmTimer($hash, gettimeofday()+$hash->{INTERVAL}); + return; + } + # # from here on we assume that $data is complete and correct # @@ -240,7 +258,6 @@ sub Weather_RetrieveDataFinished($$$) { readingsBulkUpdate($hash, "validity", "up-to-date"); # units - my $units= YahooWeatherAPI_units($data); # units hash reference readingsBulkUpdate($hash, "unit_distance", $units->{distance}); readingsBulkUpdate($hash, "unit_speed", $units->{speed}); readingsBulkUpdate($hash, "unit_pressuree", $units->{pressure});