2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 03:06:37 +00:00

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
This commit is contained in:
mattwire 2015-11-14 17:42:57 +00:00
parent 89fee5a26c
commit eaef812d53
3 changed files with 28 additions and 14 deletions

View File

@ -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

View File

@ -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(@)
<ul>
<li>
<b>state</b><br/>
[ok|unreachable]: Set depending on result of a UDP ping sent every 10 seconds.
[Initialized|ok|unreachable]: Shows reachable status of bridge using "ping" check every 10 (checkInterval) seconds.
</li>
<li>
<b>sendFail</b><br/>
@ -398,7 +409,8 @@ sub MilightBridge_CmdQueue_Send(@)
</li>
<li>
<b>checkInterval</b><br/>
Default: 10s. Time after the bridge connection is re-checked.
Default: 10s. Time after the bridge connection is re-checked.<br>
If this is set to 0 checking is disabled and state = "Initialized".
</li>
<li>
<b>port</b><br/>

View File

@ -272,7 +272,7 @@ sub MilightDevice_Set(@)
my $event = undef;
my $usage = "set $name ...";
if ($hash->{IODev}->{STATE} ne "ok") {
if ($hash->{IODev}->{STATE} ne "ok" && $hash->{IODev}->{STATE} ne "Initialized") {
readingsSingleUpdate($hash, "state", "error", 1);
$flags = "q";
$args[2] .= "q" if ($args[2] !~ m/.*[qQ].*/);
@ -1991,7 +1991,7 @@ sub MilightDevice_CmdQueue_Exec(@)
{
my ($hash) = @_;
if ($hash->{IODev}->{STATE} ne "ok") {
if ($hash->{IODev}->{STATE} ne "ok" && $hash->{IODev}->{STATE} ne "Initialized") {
InternalTimer(gettimeofday() + 60, "MilightDevice_CmdQueue_Exec", $hash, 0);
return undef;
}
@ -2052,7 +2052,7 @@ sub MilightDevice_CmdQueue_Clear(@)
{
my ($hash) = @_;
if ($hash->{IODev}->{STATE} ne "ok") {
if ($hash->{IODev}->{STATE} ne "ok" && $hash->{IODev}->{STATE} ne "Initialized") {
InternalTimer(gettimeofday() + 60, "MilightDevice_CmdQueue_Exec", $hash, 0);
return undef;
}