From 0ee3d8ded440d0caa2b3c188d5888a0e82ea0a16 Mon Sep 17 00:00:00 2001 From: igami Date: Thu, 20 Apr 2017 20:19:16 +0000 Subject: [PATCH] 59_LuftdatenInfo: timeout attribute added; delete SENSORID2 only if not set explicit git-svn-id: https://svn.fhem.de/fhem/trunk@14048 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/59_LuftdatenInfo.pm | 46 ++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/fhem/FHEM/59_LuftdatenInfo.pm b/fhem/FHEM/59_LuftdatenInfo.pm index 2afc4edc5..9e4c0ec9f 100644 --- a/fhem/FHEM/59_LuftdatenInfo.pm +++ b/fhem/FHEM/59_LuftdatenInfo.pm @@ -27,8 +27,6 @@ package main; use strict; use warnings; - use Encode qw(decode encode); - use HttpUtils; # forward declarations ######################################################## @@ -42,9 +40,7 @@ sub LuftdatenInfo_Attr(@); sub LuftdatenInfo_GetHttpResponse($$); sub LuftdatenInfo_ParseHttpResponse($); -sub LuftdatenInfo_readPassword($); sub LuftdatenInfo_statusRequest($); -sub LuftdatenInfo_storePassword($$); # initialize ################################################################## sub LuftdatenInfo_Initialize($) { @@ -89,6 +85,8 @@ sub LuftdatenInfo_Define($$) { return("Usage: define $TYPE []") if(@id != 1 && @id != 2); + $hash->{SENSORIDS} = (@id == 2) ? "explicit" : "implicit"; + $id[1] = $id[0] + 1 unless($id[1]); $hash->{SENSORID1} = $id[0]; @@ -107,8 +105,13 @@ sub LuftdatenInfo_Define($$) { my $interval = AttrVal($SELF, "interval", $minInterval); $interval = $minInterval unless(looks_like_number($interval)); $interval = $minInterval if($interval < $minInterval); + my $minTimeout = 5; + my $timeout = AttrVal($SELF, "timeout", $minTimeout); + $timeout = $minTimeout unless(looks_like_number($timeout)); + $timeout = $minTimeout if($timeout < $minTimeout); $hash->{INTERVAL} = $interval; + $hash->{TIMEOUT} = $timeout; readingsSingleUpdate($hash, "state", "active", 1); @@ -179,6 +182,14 @@ sub LuftdatenInfo_Attr(@) { $hash->{INTERVAL} = $interval; } + elsif($attribute eq "timeout"){ + my $minTimeout = 5; + my $timeout = $cmd eq "set" ? $value : $minTimeout; + $timeout = $minTimeout unless(looks_like_number($timeout)); + $timeout = $minTimeout if($timeout < $minTimeout); + + $hash->{TIMEOUT} = $timeout; + } return; } @@ -188,7 +199,7 @@ sub LuftdatenInfo_GetHttpResponse($$) { my ($hash, $id) = @_; my $SELF = $hash->{NAME}; my $TYPE = $hash->{TYPE}; - my $timeout = 5; + my $timeout = $hash->{TIMEOUT}; my $connection = $hash->{CONNECTION}; Log3($SELF, 5, "$TYPE ($SELF) - entering LuftdatenInfo_GetHttpResponse"); @@ -234,7 +245,9 @@ sub LuftdatenInfo_ParseHttpResponse($) { readingsSingleUpdate($hash, "state", "error", 1); } elsif($data eq "[]"){ - if(index($param->{url}, $hash->{SENSORID2}) > -1){ + if( index($param->{url}, $hash->{SENSORID2}) > -1 + && InternalVal($SELF, "SENSORIDS", "implicit") eq "implicit" + ){ delete($hash->{SENSORID2}); Log3($SELF, 2, "$TYPE ($SELF) - no second sensor found"); @@ -279,7 +292,7 @@ sub LuftdatenInfo_ParseHttpResponse($) { "http://nominatim.openstreetmap.org/reverse?" . "format=json&lat=$latitude&lon=$longitude" , - timeout => 5, + timeout => $hash->{TIMEOUT}, hash => $hash, method => "GET", header => "Accept: application/json", @@ -314,11 +327,10 @@ sub LuftdatenInfo_ParseHttpResponse($) { elsif($sensor_type eq "DHT22"){ Log3 $SELF, 5, "$TYPE ($SELF) - parsing $sensor_type data"; - if( - $sensor->{location}{latitude} ne - ReadingsVal($SELF, "latitude", "") - || $sensor->{location}{longitude} ne - ReadingsVal($SELF, "longitude", "") + if( $sensor->{location}{latitude} ne + ReadingsVal($SELF, "latitude", "") + || $sensor->{location}{longitude} ne + ReadingsVal($SELF, "longitude", "") ){ delete($hash->{SENSORID2}); @@ -521,6 +533,11 @@ sub LuftdatenInfo_statusRequest($) { Interval in seconds in which queries are performed.
The default and minimum value is 300 seconds. +
  • + timeout <seconds>
    + Timeout in seconds for the queries.
    + The default and minimum value is 5 seconds. +
  • @@ -634,6 +651,11 @@ sub LuftdatenInfo_statusRequest($) { Intervall in Sekunden in dem Abfragen durchgeführt werden.
    Der Vorgabe- und Mindestwert beträgt 300 Sekunden. +
  • + timeout <seconds>
    + Timeout in Sekunden für die Abfragen.
    + Der Vorgabe- und Mindestwert beträgt 5 Sekunden. +