2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 18:59:33 +00:00

RESIDENTStk: fix notification for presenceDevices

git-svn-id: https://svn.fhem.de/fhem/trunk@14049 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2017-04-20 20:41:15 +00:00
parent 0ee3d8ded4
commit 3ed34ea73c

View File

@ -1223,20 +1223,22 @@ m/^((?:DELETE)?ATTR)\s+([A-Za-z\d._]+)\s+([A-Za-z\d_\.\-\/]+)(?:\s+(.*)\s*)?$/
my $events = deviceEvents( $dev, 1 ); my $events = deviceEvents( $dev, 1 );
return "" unless ($events); return "" unless ($events);
# process wakeup devices
my @registeredWakeupdevs = my @registeredWakeupdevs =
split( ',', AttrVal( $name, $prefix . "wakeupDevice", "" ) ); split( ',', AttrVal( $name, $prefix . "wakeupDevice", "" ) );
my @presenceDevices =
split( ',', AttrVal( $name, $prefix . "presenceDevices", "" ) );
foreach my $event ( @{$events} ) {
next unless ( defined($event) );
my $found = 0;
# process wakeup devices
if (@registeredWakeupdevs) { if (@registeredWakeupdevs) {
# if this is a notification of a registered wakeup device # if this is a notification of a registered wakeup device
if ( grep { m/^$devName$/ } @registeredWakeupdevs ) { if ( grep { m/^$devName$/ } @registeredWakeupdevs ) {
foreach my $event ( @{$events} ) {
next unless ( defined($event) );
RESIDENTStk_wakeupSet( $devName, $event ); RESIDENTStk_wakeupSet( $devName, $event );
} next;
return "";
} }
# process sub-child notifies: *_wakeupDevice # process sub-child notifies: *_wakeupDevice
@ -1244,29 +1246,32 @@ m/^((?:DELETE)?ATTR)\s+([A-Za-z\d._]+)\s+([A-Za-z\d_\.\-\/]+)(?:\s+(.*)\s*)?$/
# if this is a notification of a registered sub dummy device # if this is a notification of a registered sub dummy device
# of one of our wakeup devices # of one of our wakeup devices
if ( AttrVal( $wakeupDev, "wakeupResetSwitcher", "" ) eq $devName if (
AttrVal( $wakeupDev, "wakeupResetSwitcher", "" ) eq $devName
&& IsDevice( $devName, "dummy" ) ) && IsDevice( $devName, "dummy" ) )
{ {
foreach my $event ( @{$events} ) {
next unless ( defined($event) );
RESIDENTStk_wakeupSet( $wakeupDev, $event ) RESIDENTStk_wakeupSet( $wakeupDev, $event )
unless ( $event =~ /^(?:state:\s*)?off$/i ); unless ( $event =~ /^(?:state:\s*)?off$/i );
} $found = 1;
last;
return "";
} }
} }
next if ($found);
return "";
} }
# process PRESENCE # process PRESENCE
my @presenceDevices =
split( ',', AttrVal( $name, $prefix . "presenceDevices", "" ) );
if ( @presenceDevices if ( @presenceDevices
&& grep { /^[\s\t ]*$devName(:[A-Za-z\d_\.\-\/]*)?[\s\t ]*$/ } && ( grep { /^$devName(:[A-Za-z\d_\.\-\/]+)?$/ } @presenceDevices )
@presenceDevices ) && $event =~ /^(?:([A-Za-z\d_\.\-\/]+): )?(.+)$/ )
{ {
my $reading = $1;
my $value = $2;
# early exit if unexpected event value
next
unless ( $value =~
m/^0|false|absent|disappeared|unavailable|unreachable|disconnected|1|true|present|appeared|available|reachable|connected$/i
);
my $counter = { my $counter = {
absent => 0, absent => 0,
@ -1276,23 +1281,22 @@ m/^((?:DELETE)?ATTR)\s+([A-Za-z\d._]+)\s+([A-Za-z\d_\.\-\/]+)(?:\s+(.*)\s*)?$/
for (@presenceDevices) { for (@presenceDevices) {
my $r = "presence"; my $r = "presence";
my $d = $_; my $d = $_;
if ( $d =~ if ( $d =~ m/^([a-zA-Z\d._]+)(?::([A-Za-z\d_\.\-\/]*))?$/ ) {
m/^[\s\t ]*([A-Za-z\d_\.\-\/]+):([A-Za-z\d_\.\-\/]+)?[\s\t ]*$/
)
{
$d = $1; $d = $1;
$r = $2; $r = $2;
} }
my $presenceState = my $presenceState =
ReadingsVal( $d, $r, ReadingsVal( $d, "state", "" ) ); ReadingsVal( $d, $r, ReadingsVal( $d, "state", "" ) );
# ignore device if it has unexpected state
next next
unless ( $presenceState =~ unless ( $presenceState =~
m/^(0|false|absent|disappeared|unavailable|unreachable|disconnected)|(1|true|present|appeared|available|reachable|connected|)$/i m/^(0|false|absent|disappeared|unavailable|unreachable|disconnected)|(1|true|present|appeared|available|reachable|connected|)$/i
); );
$counter->{absent}++ if ($1); $counter->{absent}++ if ( defined($1) );
$counter->{present}++ if ($2); $counter->{present}++ if ( defined($2) );
} }
if ( $counter->{absent} && !$counter->{present} ) { if ( $counter->{absent} && !$counter->{present} ) {
@ -1305,8 +1309,7 @@ m/^(0|false|absent|disappeared|unavailable|unreachable|disconnected)|(1|true|pre
"$TYPE $name: " . "Syncing status with $devName = present"; "$TYPE $name: " . "Syncing status with $devName = present";
fhem "set $name:FILTER=presence=absent home"; fhem "set $name:FILTER=presence=absent home";
} }
}
return "";
} }
return ""; return "";
@ -3511,10 +3514,7 @@ sub RESIDENTStk_findDummySlaves($) {
$hash->{NOTIFYDEV} .= "," if ( $hash->{NOTIFYDEV} ne "" ); $hash->{NOTIFYDEV} .= "," if ( $hash->{NOTIFYDEV} ne "" );
$hash->{NOTIFYDEV} .= $wakeupDevice; $hash->{NOTIFYDEV} .= $wakeupDevice;
my @wakeupdevs = foreach ( split( ',', $wakeupDevice ) ) {
split( ',', $wakeupDevice );
foreach (@wakeupdevs) {
my $rsw; my $rsw;
next unless ( IsDevice($_) ); next unless ( IsDevice($_) );
@ -3528,8 +3528,12 @@ sub RESIDENTStk_findDummySlaves($) {
} }
if ($presenceDevices) { if ($presenceDevices) {
foreach ($presenceDevices) {
my $d = $_;
$d =~ s/:.*$//g;
$hash->{NOTIFYDEV} .= "," if ( $hash->{NOTIFYDEV} ne "" ); $hash->{NOTIFYDEV} .= "," if ( $hash->{NOTIFYDEV} ne "" );
$hash->{NOTIFYDEV} .= $presenceDevices; $hash->{NOTIFYDEV} .= $d;
}
} }
} }