2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-02-01 01:09:47 +00:00

GEOFANCY: use devspec2array to find r*_geofenceUUIDs attributes from ROOMMATE/GUEST devices

git-svn-id: https://svn.fhem.de/fhem/trunk@14110 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2017-04-26 06:54:58 +00:00
parent 9ca84e618e
commit b1e796d5b4

View File

@ -341,67 +341,53 @@ m/(19|20)\d\d-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([0-1][0-9]|2[0-3]):([0-5
# update ROOMMATE devices associated with this device UUID # update ROOMMATE devices associated with this device UUID
my $matchingResident = 0; my $matchingResident = 0;
delete $hash->{ROOMMATES}; delete $hash->{ROOMMATES};
if ( defined( $modules{ROOMMATE}{defptr} ) ) { foreach my $gdev ( devspec2array("rr_geofenceUUIDs=.+") ) {
Log3 $name, 5, "GEOFANCY $name: found defptr for ROOMMATE\n" next unless ( IsDevice( $gdev, "ROOMMATE" ) );
. Dumper( $modules{ROOMMATE}{defptr} ); Log3 $name, 5, "GEOFANCY $name: Checking rr_geofenceUUIDs for $gdev";
my $geofenceUUIDs = AttrVal( $gdev, "rr_geofenceUUIDs", undef );
while ( my ( $key, $value ) = each %{ $modules{ROOMMATE}{defptr} } ) { $hash->{ROOMMATES} .= ",$gdev" if $hash->{ROOMMATES};
Log3 $name, 5, "GEOFANCY $name: Checking rr_geofenceUUIDs for $key"; $hash->{ROOMMATES} = $gdev if !$hash->{ROOMMATES};
my $geofenceUUIDs = AttrVal( $key, "rr_geofenceUUIDs", undef );
next if !$geofenceUUIDs;
Log3 $name, 5,
"GEOFANCY $name: ROOMMATE device $key has assigned UUIDs: $geofenceUUIDs";
$hash->{ROOMMATES} .= ",$key" if $hash->{ROOMMATES};
$hash->{ROOMMATES} = $key if !$hash->{ROOMMATES};
my @UUIDs = split( ',', $geofenceUUIDs ); my @UUIDs = split( ',', $geofenceUUIDs );
if (@UUIDs) { if (@UUIDs) {
foreach (@UUIDs) { foreach (@UUIDs) {
if ( $_ eq $device ) { if ( $_ eq $device ) {
Log3 $name, 4, Log3 $name, 4,
"GEOFANCY $name: Found matching UUID at ROOMMATE device $key"; "GEOFANCY $name: "
$deviceAlias = $key; . "Found matching UUID at ROOMMATE device $gdev";
$deviceAlias = $gdev;
$matchingResident = 1; $matchingResident = 1;
last; last;
} }
} }
} }
} }
}
delete $hash->{GUESTS};
# update GUEST devices associated with this device UUID # update GUEST devices associated with this device UUID
if ( $matchingResident == 0 && defined( $modules{GUEST}{defptr} ) ) { delete $hash->{GUESTS};
while ( my ( $key, $value ) = each %{ $modules{GUEST}{defptr} } ) { foreach my $gdev ( devspec2array("rg_geofenceUUIDs=.+") ) {
my $geofenceUUIDs = AttrVal( $key, "rg_geofenceUUIDs", undef ); next unless ( IsDevice( $gdev, "GUEST" ) );
next if !$geofenceUUIDs; Log3 $name, 5, "GEOFANCY $name: Checking rg_geofenceUUIDs for $gdev";
my $geofenceUUIDs = AttrVal( $gdev, "rg_geofenceUUIDs", undef );
Log3 $name, 5, $hash->{GUESTS} .= ",$gdev" if $hash->{GUESTS};
"GEOFANCY $name: GUEST device $key has assigned UUIDs: $geofenceUUIDs"; $hash->{GUESTS} = $gdev if !$hash->{GUESTS};
$hash->{GUESTS} .= ",$key" if $hash->{GUESTS};
$hash->{GUESTS} = $key if !$hash->{GUESTS};
my @UUIDs = split( ',', $geofenceUUIDs ); my @UUIDs = split( ',', $geofenceUUIDs );
if (@UUIDs) { if (@UUIDs) {
foreach (@UUIDs) { foreach (@UUIDs) {
if ( $_ eq $device ) { if ( $_ eq $device ) {
Log3 $name, 4, Log3 $name, 4,
"GEOFANCY $name: Found matching UUID at GUEST device $key"; "GEOFANCY $name: "
$deviceAlias = $key; . "Found matching UUID at GUESTS device $gdev";
$deviceAlias = $gdev;
$matchingResident = 1; $matchingResident = 1;
last; last;
} }
} }
} }
} }
}
# Device alias handling # Device alias handling
# #
@ -410,10 +396,7 @@ m/(19|20)\d\d-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([0-1][0-9]|2[0-3]):([0-5
delete $hash->{helper}{device_names} delete $hash->{helper}{device_names}
if $hash->{helper}{device_names}; if $hash->{helper}{device_names};
if ( defined( $attr{$name}{devAlias} ) ) { my @devices = split( ' ', AttrVal( $name, "devAlias", "" ) );
my @devices = split( ' ', $attr{$name}{devAlias} );
if (@devices) {
foreach (@devices) { foreach (@devices) {
my @device = split( ':', $_ ); my @device = split( ':', $_ );
$hash->{helper}{device_aliases}{ $device[0] } = $hash->{helper}{device_aliases}{ $device[0] } =
@ -421,8 +404,6 @@ m/(19|20)\d\d-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([0-1][0-9]|2[0-3]):([0-5
$hash->{helper}{device_names}{ $device[1] } = $hash->{helper}{device_names}{ $device[1] } =
$device[0]; $device[0];
} }
}
}
$deviceAlias = $hash->{helper}{device_aliases}{$device} $deviceAlias = $hash->{helper}{device_aliases}{$device}
if ( $hash->{helper}{device_aliases}{$device} && $matchingResident == 0 ); if ( $hash->{helper}{device_aliases}{$device} && $matchingResident == 0 );
@ -497,22 +478,16 @@ m/(19|20)\d\d-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([0-1][0-9]|2[0-3]):([0-5
# backup last known location if not "underway" # backup last known location if not "underway"
$currReading = "currLoc_" . $deviceAlias; $currReading = "currLoc_" . $deviceAlias;
if ( defined( $hash->{READINGS}{$currReading}{VAL} ) my $currVal = ReadingsVal( $name, $currReading, undef );
&& $hash->{READINGS}{$currReading}{VAL} ne "underway" ) if ( $currVal && $currVal ne "underway" ) {
{
foreach ( 'Loc', 'LocLat', 'LocLong', 'LocAddr' ) { foreach ( 'Loc', 'LocLat', 'LocLong', 'LocAddr' ) {
$currReading = "curr" . $_ . "_" . $deviceAlias; $currReading = "curr" . $_ . "_" . $deviceAlias;
$lastReading = "last" . $_ . "_" . $deviceAlias; $lastReading = "last" . $_ . "_" . $deviceAlias;
readingsBulkUpdate( $hash, $lastReading, readingsBulkUpdate( $hash, $lastReading, $currVal );
$hash->{READINGS}{$currReading}{VAL} )
if ( defined( $hash->{READINGS}{$currReading}{VAL} ) );
} }
$currReading = "currLocTime_" . $deviceAlias; $currReading = "currLocTime_" . $deviceAlias;
readingsBulkUpdate( readingsBulkUpdate( $hash, "lastLocArr_" . $deviceAlias,
$hash, $currVal );
"lastLocArr_" . $deviceAlias,
$hash->{READINGS}{$currReading}{VAL}
) if ( defined( $hash->{READINGS}{$currReading}{VAL} ) );
readingsBulkUpdate( $hash, "lastLocDep_" . $deviceAlias, readingsBulkUpdate( $hash, "lastLocDep_" . $deviceAlias,
$time ); $time );
} }
@ -541,9 +516,7 @@ m/(19|20)\d\d-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([0-1][0-9]|2[0-3]):([0-5
RESIDENTStk_SetLocation( RESIDENTStk_SetLocation(
$deviceAlias, $locName, $trigger, $id, $time, $deviceAlias, $locName, $trigger, $id, $time,
$lat, $long, $address, $device $lat, $long, $address, $device
) ) if ( IsDevice( $deviceAlias, "ROOMMATE|GUEST" ) );
if ( $defs{$deviceAlias}{TYPE} eq "ROOMMATE"
|| $defs{$deviceAlias}{TYPE} eq "GUEST" );
} }
$msg = lc($entry) . " OK"; $msg = lc($entry) . " OK";