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:
parent
0ee3d8ded4
commit
3ed34ea73c
@ -1223,90 +1223,93 @@ 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", "" ) );
|
||||||
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 "";
|
|
||||||
}
|
|
||||||
|
|
||||||
# process sub-child notifies: *_wakeupDevice
|
|
||||||
foreach my $wakeupDev (@registeredWakeupdevs) {
|
|
||||||
|
|
||||||
# if this is a notification of a registered sub dummy device
|
|
||||||
# of one of our wakeup devices
|
|
||||||
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 "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
# process PRESENCE
|
|
||||||
my @presenceDevices =
|
my @presenceDevices =
|
||||||
split( ',', AttrVal( $name, $prefix . "presenceDevices", "" ) );
|
split( ',', AttrVal( $name, $prefix . "presenceDevices", "" ) );
|
||||||
if ( @presenceDevices
|
|
||||||
&& grep { /^[\s\t ]*$devName(:[A-Za-z\d_\.\-\/]*)?[\s\t ]*$/ }
|
|
||||||
@presenceDevices )
|
|
||||||
{
|
|
||||||
|
|
||||||
my $counter = {
|
foreach my $event ( @{$events} ) {
|
||||||
absent => 0,
|
next unless ( defined($event) );
|
||||||
present => 0,
|
my $found = 0;
|
||||||
};
|
|
||||||
|
|
||||||
for (@presenceDevices) {
|
# process wakeup devices
|
||||||
my $r = "presence";
|
if (@registeredWakeupdevs) {
|
||||||
my $d = $_;
|
|
||||||
if ( $d =~
|
# if this is a notification of a registered wakeup device
|
||||||
m/^[\s\t ]*([A-Za-z\d_\.\-\/]+):([A-Za-z\d_\.\-\/]+)?[\s\t ]*$/
|
if ( grep { m/^$devName$/ } @registeredWakeupdevs ) {
|
||||||
)
|
RESIDENTStk_wakeupSet( $devName, $event );
|
||||||
{
|
next;
|
||||||
$d = $1;
|
|
||||||
$r = $2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
my $presenceState =
|
# process sub-child notifies: *_wakeupDevice
|
||||||
ReadingsVal( $d, $r, ReadingsVal( $d, "state", "" ) );
|
foreach my $wakeupDev (@registeredWakeupdevs) {
|
||||||
|
|
||||||
|
# if this is a notification of a registered sub dummy device
|
||||||
|
# of one of our wakeup devices
|
||||||
|
if (
|
||||||
|
AttrVal( $wakeupDev, "wakeupResetSwitcher", "" ) eq $devName
|
||||||
|
&& IsDevice( $devName, "dummy" ) )
|
||||||
|
{
|
||||||
|
RESIDENTStk_wakeupSet( $wakeupDev, $event )
|
||||||
|
unless ( $event =~ /^(?:state:\s*)?off$/i );
|
||||||
|
$found = 1;
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
next if ($found);
|
||||||
|
}
|
||||||
|
|
||||||
|
# process PRESENCE
|
||||||
|
if ( @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
|
next
|
||||||
unless ( $presenceState =~
|
unless ( $value =~
|
||||||
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);
|
my $counter = {
|
||||||
$counter->{present}++ if ($2);
|
absent => 0,
|
||||||
}
|
present => 0,
|
||||||
|
};
|
||||||
|
|
||||||
if ( $counter->{absent} && !$counter->{present} ) {
|
for (@presenceDevices) {
|
||||||
Log3 $name, 4,
|
my $r = "presence";
|
||||||
"$TYPE $name: " . "Syncing status with $devName = absent";
|
my $d = $_;
|
||||||
fhem "set $name:FILTER=presence=present absent";
|
if ( $d =~ m/^([a-zA-Z\d._]+)(?::([A-Za-z\d_\.\-\/]*))?$/ ) {
|
||||||
}
|
$d = $1;
|
||||||
elsif ( $counter->{present} ) {
|
$r = $2;
|
||||||
Log3 $name, 4,
|
}
|
||||||
"$TYPE $name: " . "Syncing status with $devName = present";
|
|
||||||
fhem "set $name:FILTER=presence=absent home";
|
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
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 ( defined($1) );
|
||||||
|
$counter->{present}++ if ( defined($2) );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $counter->{absent} && !$counter->{present} ) {
|
||||||
|
Log3 $name, 4,
|
||||||
|
"$TYPE $name: " . "Syncing status with $devName = absent";
|
||||||
|
fhem "set $name:FILTER=presence=present absent";
|
||||||
|
}
|
||||||
|
elsif ( $counter->{present} ) {
|
||||||
|
Log3 $name, 4,
|
||||||
|
"$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} .= "," 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) {
|
||||||
$hash->{NOTIFYDEV} .= "," if ( $hash->{NOTIFYDEV} ne "" );
|
foreach ($presenceDevices) {
|
||||||
$hash->{NOTIFYDEV} .= $presenceDevices;
|
my $d = $_;
|
||||||
|
$d =~ s/:.*$//g;
|
||||||
|
$hash->{NOTIFYDEV} .= "," if ( $hash->{NOTIFYDEV} ne "" );
|
||||||
|
$hash->{NOTIFYDEV} .= $d;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user