From eaef812d53cbcba2d09d7036e5a62e4f1bf7a98c Mon Sep 17 00:00:00 2001 From: mattwire <> Date: Sat, 14 Nov 2015 17:42:57 +0000 Subject: [PATCH] 30_MilightBridge/31_MilightDevice: Allow to disable ping check. Add state "Initialized". git-svn-id: https://svn.fhem.de/fhem/trunk@9890 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 2 ++ fhem/FHEM/30_MilightBridge.pm | 34 +++++++++++++++++++++++----------- fhem/FHEM/31_MilightDevice.pm | 6 +++--- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index b5ad71930..91a5f9d95 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. + - change: 30_MilightBridge/31_MilightDevice: Allow to disable ping check. + Add state "Initialized". - feature: 50_HP1000: new module to support HP1000 weather station - feature: new module 53_GHoma.pm added (klausw) - feature: 14_CUL_REDIRECT: Rename 14_CUL_OTHER to 14_CUL_REDIRECT diff --git a/fhem/FHEM/30_MilightBridge.pm b/fhem/FHEM/30_MilightBridge.pm index 66f888a4e..8cada688e 100644 --- a/fhem/FHEM/30_MilightBridge.pm +++ b/fhem/FHEM/30_MilightBridge.pm @@ -98,8 +98,12 @@ sub MilightBridge_Define($$) $attr{$name}{"event-on-change-reading"} = "state" if (!defined($attr{$name}{"event-on-change-reading"})); $attr{$name}{"checkInterval"} = 10 if (!defined($attr{$name}{"checkInterval"})); + readingsSingleUpdate($hash, "state", "Initialized", 1); + # Set state $hash->{SENDFAIL} = 0; + + # Get initial bridge state MilightBridge_State($hash); return undef; @@ -139,11 +143,12 @@ sub MilightBridge_Attr($$$$) { } if ($attribute eq "checkInterval") { - if (($value !~ /^\d*$/) || ($value < 5)) + if (($value !~ /^\d*$/) || ($value < 0)) { $attr{$name}{"checkInterval"} = 10; - return "checkInterval is required in s (default: 10, min: 5)"; + return "checkInterval is required in s (default: 10, min: 0)"; } + readingsSingleUpdate($hash, "state", "Initialized", 1); } elsif ($attribute eq "port") { @@ -164,11 +169,11 @@ sub MilightBridge_Attr($$$$) { # Disable on 1, enable on anything else. if ($value eq "1") { - $hash->{STATE} = "disabled"; + readingsSingleUpdate($hash, "state", "disabled", 1); } else { - $hash->{STATE} = "ok"; + readingsSingleUpdate($hash, "state", "Initialized", 1); } } @@ -199,6 +204,12 @@ sub MilightBridge_State(@) # Update Bridge state my ($hash) = @_; + if (AttrVal($hash->{NAME}, "checkInterval", "10") == 0) + { + Log3 ( $hash, 5, "$hash->{NAME}_State: Bridge status disabled"); + return undef; + } + Log3 ( $hash, 5, "$hash->{NAME}_State: Checking Bridge Status"); # Do a ping check to see if bridge is reachable @@ -217,11 +228,11 @@ sub MilightBridge_State(@) $p->close(); $pingstatus = "ok" if $alive; - # And update state - readingsSingleUpdate($hash, "state", $pingstatus, 1); - - # Update send fail flag - readingsSingleUpdate( $hash, "sendFail", $hash->{SENDFAIL}, 1 ); + # Update readings + readingsBeginUpdate($hash); + readingsBulkUpdate($hash, "state", $pingstatus); + readingsBulkUpdate( $hash, "sendFail", $hash->{SENDFAIL}); + readingsEndUpdate($hash, 1); # Check state every X seconds InternalTimer(gettimeofday() + AttrVal($hash->{NAME}, "checkInterval", "10"), "MilightBridge_State", $hash, 0); @@ -378,7 +389,7 @@ sub MilightBridge_CmdQueue_Send(@)