MYSENSORS_DEVICE: extend sending routines for smartsleep, https://forum.mysensors.org/topic 10221

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@18933 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Beta-User 2019-03-17 06:33:39 +00:00
parent 67c2aca7d7
commit c1121b0ec4

View File

@ -26,6 +26,7 @@
use strict; use strict;
use warnings; use warnings;
use SetExtensions;
sub MYSENSORS_DEVICE_Initialize($) { sub MYSENSORS_DEVICE_Initialize($) {
@ -37,25 +38,26 @@ sub MYSENSORS_DEVICE_Initialize($) {
$hash->{SetFn} = "MYSENSORS::DEVICE::Set"; $hash->{SetFn} = "MYSENSORS::DEVICE::Set";
$hash->{GetFn} = "MYSENSORS::DEVICE::Get"; $hash->{GetFn} = "MYSENSORS::DEVICE::Get";
$hash->{AttrFn} = "MYSENSORS::DEVICE::Attr"; $hash->{AttrFn} = "MYSENSORS::DEVICE::Attr";
no warnings 'qw';
$hash->{AttrList} = my @attrList = qw(
"config:M,I " . config:M,I
"mode:node,repeater " . mode:node,repeater
"version:1.4 " . version:1.4
"setCommands " . setCommands
"setReading_.+ " . setReading_.+
"mapReadingType_.+ " . mapReadingType_.+
"mapReading_.+ " . mapReading_.+
"requestAck:1 " . requestAck:1
"timeoutAck " . timeoutAck
"timeoutAlive " . timeoutAlive
"IODev " . IODev
"showtime:0,1 " . showtime:0,1
"OTA_autoUpdate:0,1 " . OTA_autoUpdate:0,1
"OTA_BL_Type:Optiboot,MYSBootloader " . OTA_BL_Type:Optiboot,MYSBootloader
"OTA_Chan76_IODev " . OTA_Chan76_IODev
$main::readingFnAttributes; );
use warnings 'qw';
$hash->{AttrList} = join(" ", @attrList)." ".$readingFnAttributes;
main::LoadModule("MYSENSORS"); main::LoadModule("MYSENSORS");
} }
@ -67,7 +69,7 @@ use GPUtils qw(:all);
use Device::MySensors::Constants qw(:all); use Device::MySensors::Constants qw(:all);
use Device::MySensors::Message qw(:all); use Device::MySensors::Message qw(:all);
use SetExtensions qw/ :all /; #use SetExtensions qw/ :all /;
BEGIN { BEGIN {
main::LoadModule("MYSENSORS"); main::LoadModule("MYSENSORS");
@ -828,6 +830,10 @@ sub onInternalMessage($$) {
$type == I_HEARTBEAT_RESPONSE and do { $type == I_HEARTBEAT_RESPONSE and do {
readingsSingleUpdate($hash, "heartbeat", "last", 0); readingsSingleUpdate($hash, "heartbeat", "last", 0);
refreshInternalMySTimer($hash,"Alive") if $hash->{timeoutAlive}; refreshInternalMySTimer($hash,"Alive") if $hash->{timeoutAlive};
if ($hash->{nowSleeping}) {
$hash->{nowSleeping} = 0 ;
sendRetainedMessages($hash);
}
#$hash->{$typeStr} = $msg->{payload}; #$hash->{$typeStr} = $msg->{payload};
last; last;
}; };
@ -901,10 +907,7 @@ sub onInternalMessage($$) {
refreshInternalMySTimer($hash,"Asleep"); refreshInternalMySTimer($hash,"Asleep");
refreshInternalMySTimer($hash,"Alive") if $hash->{timeoutAlive}; refreshInternalMySTimer($hash,"Alive") if $hash->{timeoutAlive};
MYSENSORS::Timer($hash); MYSENSORS::Timer($hash);
my $retainedMsg; sendRetainedMessages($hash) ;
while (ref ($retainedMsg = shift @{$hash->{retainedMessagesForRadioId}->{messages}}) eq 'HASH') {
sendClientMessage($hash,%$retainedMsg);
};
last; last;
}; };
$type == I_POST_SLEEP_NOTIFICATION and do { $type == I_POST_SLEEP_NOTIFICATION and do {
@ -927,6 +930,10 @@ sub sendClientMessage($%) {
sendMessage($hash->{IODev},%msg); sendMessage($hash->{IODev},%msg);
refreshInternalMySTimer($hash,"Ack") if (($msg{ack} or $hash->{IODev}->{ack}) and $hash->{timeoutAck}); refreshInternalMySTimer($hash,"Ack") if (($msg{ack} or $hash->{IODev}->{ack}) and $hash->{timeoutAck});
Log3 ($name,5,"$name is not sleeping, sending message!"); Log3 ($name,5,"$name is not sleeping, sending message!");
if ($hash->{nowSleeping}) {
$hash->{nowSleeping} = 0 ;
sendRetainedMessages($hash);
}
$hash->{retainedMessages}=scalar(@$messages) if (defined $hash->{retainedMessages}); $hash->{retainedMessages}=scalar(@$messages) if (defined $hash->{retainedMessages});
} else { } else {
Log3 ($name,5,"$name is sleeping, enqueing message! "); Log3 ($name,5,"$name is sleeping, enqueing message! ");
@ -1126,6 +1133,14 @@ sub timeoutMySTimer($) {
} }
} }
sub sendRetainedMessages($) {
my ($hash) = @_;
my $name = $hash->{NAME};
my $retainedMsg;
while (ref ($retainedMsg = shift @{$hash->{retainedMessagesForRadioId}->{messages}}) eq 'HASH') {
sendClientMessage($hash,%$retainedMsg);
};
}
1; 1;
=pod =pod