mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 12:49:34 +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:
parent
0ee3d8ded4
commit
3ed34ea73c
@ -1223,20 +1223,22 @@ m/^((?:DELETE)?ATTR)\s+([A-Za-z\d._]+)\s+([A-Za-z\d_\.\-\/]+)(?:\s+(.*)\s*)?$/
|
||||
my $events = deviceEvents( $dev, 1 );
|
||||
return "" unless ($events);
|
||||
|
||||
# process wakeup devices
|
||||
my @registeredWakeupdevs =
|
||||
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 this is a notification of a registered wakeup device
|
||||
if ( grep { m/^$devName$/ } @registeredWakeupdevs ) {
|
||||
|
||||
foreach my $event ( @{$events} ) {
|
||||
next unless ( defined($event) );
|
||||
RESIDENTStk_wakeupSet( $devName, $event );
|
||||
}
|
||||
|
||||
return "";
|
||||
next;
|
||||
}
|
||||
|
||||
# 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
|
||||
# of one of our wakeup devices
|
||||
if ( AttrVal( $wakeupDev, "wakeupResetSwitcher", "" ) eq $devName
|
||||
if (
|
||||
AttrVal( $wakeupDev, "wakeupResetSwitcher", "" ) eq $devName
|
||||
&& IsDevice( $devName, "dummy" ) )
|
||||
{
|
||||
foreach my $event ( @{$events} ) {
|
||||
next unless ( defined($event) );
|
||||
RESIDENTStk_wakeupSet( $wakeupDev, $event )
|
||||
unless ( $event =~ /^(?:state:\s*)?off$/i );
|
||||
}
|
||||
|
||||
return "";
|
||||
$found = 1;
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
next if ($found);
|
||||
}
|
||||
|
||||
# process PRESENCE
|
||||
my @presenceDevices =
|
||||
split( ',', AttrVal( $name, $prefix . "presenceDevices", "" ) );
|
||||
if ( @presenceDevices
|
||||
&& grep { /^[\s\t ]*$devName(:[A-Za-z\d_\.\-\/]*)?[\s\t ]*$/ }
|
||||
@presenceDevices )
|
||||
&& ( grep { /^$devName(:[A-Za-z\d_\.\-\/]+)?$/ } @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 = {
|
||||
absent => 0,
|
||||
@ -1276,23 +1281,22 @@ m/^((?:DELETE)?ATTR)\s+([A-Za-z\d._]+)\s+([A-Za-z\d_\.\-\/]+)(?:\s+(.*)\s*)?$/
|
||||
for (@presenceDevices) {
|
||||
my $r = "presence";
|
||||
my $d = $_;
|
||||
if ( $d =~
|
||||
m/^[\s\t ]*([A-Za-z\d_\.\-\/]+):([A-Za-z\d_\.\-\/]+)?[\s\t ]*$/
|
||||
)
|
||||
{
|
||||
if ( $d =~ m/^([a-zA-Z\d._]+)(?::([A-Za-z\d_\.\-\/]*))?$/ ) {
|
||||
$d = $1;
|
||||
$r = $2;
|
||||
}
|
||||
|
||||
my $presenceState =
|
||||
ReadingsVal( $d, $r, ReadingsVal( $d, "state", "" ) );
|
||||
|
||||
# ignore device if it has unexpected state
|
||||
next
|
||||
unless ( $presenceState =~
|
||||
m/^(0|false|absent|disappeared|unavailable|unreachable|disconnected)|(1|true|present|appeared|available|reachable|connected|)$/i
|
||||
);
|
||||
|
||||
$counter->{absent}++ if ($1);
|
||||
$counter->{present}++ if ($2);
|
||||
$counter->{absent}++ if ( defined($1) );
|
||||
$counter->{present}++ if ( defined($2) );
|
||||
}
|
||||
|
||||
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";
|
||||
fhem "set $name:FILTER=presence=absent home";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
@ -3511,10 +3514,7 @@ sub RESIDENTStk_findDummySlaves($) {
|
||||
$hash->{NOTIFYDEV} .= "," if ( $hash->{NOTIFYDEV} ne "" );
|
||||
$hash->{NOTIFYDEV} .= $wakeupDevice;
|
||||
|
||||
my @wakeupdevs =
|
||||
split( ',', $wakeupDevice );
|
||||
|
||||
foreach (@wakeupdevs) {
|
||||
foreach ( split( ',', $wakeupDevice ) ) {
|
||||
my $rsw;
|
||||
next unless ( IsDevice($_) );
|
||||
|
||||
@ -3528,8 +3528,12 @@ sub RESIDENTStk_findDummySlaves($) {
|
||||
}
|
||||
|
||||
if ($presenceDevices) {
|
||||
foreach ($presenceDevices) {
|
||||
my $d = $_;
|
||||
$d =~ s/:.*$//g;
|
||||
$hash->{NOTIFYDEV} .= "," if ( $hash->{NOTIFYDEV} ne "" );
|
||||
$hash->{NOTIFYDEV} .= $presenceDevices;
|
||||
$hash->{NOTIFYDEV} .= $d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user