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,63 +341,49 @@ 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 ); my @UUIDs = split( ',', $geofenceUUIDs );
next if !$geofenceUUIDs; if (@UUIDs) {
foreach (@UUIDs) {
Log3 $name, 5, if ( $_ eq $device ) {
"GEOFANCY $name: ROOMMATE device $key has assigned UUIDs: $geofenceUUIDs"; Log3 $name, 4,
"GEOFANCY $name: "
$hash->{ROOMMATES} .= ",$key" if $hash->{ROOMMATES}; . "Found matching UUID at ROOMMATE device $gdev";
$hash->{ROOMMATES} = $key if !$hash->{ROOMMATES}; $deviceAlias = $gdev;
$matchingResident = 1;
my @UUIDs = split( ',', $geofenceUUIDs ); last;
if (@UUIDs) {
foreach (@UUIDs) {
if ( $_ eq $device ) {
Log3 $name, 4,
"GEOFANCY $name: Found matching UUID at ROOMMATE device $key";
$deviceAlias = $key;
$matchingResident = 1;
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}; my @UUIDs = split( ',', $geofenceUUIDs );
$hash->{GUESTS} = $key if !$hash->{GUESTS}; if (@UUIDs) {
foreach (@UUIDs) {
my @UUIDs = split( ',', $geofenceUUIDs ); if ( $_ eq $device ) {
Log3 $name, 4,
if (@UUIDs) { "GEOFANCY $name: "
foreach (@UUIDs) { . "Found matching UUID at GUESTS device $gdev";
if ( $_ eq $device ) { $deviceAlias = $gdev;
Log3 $name, 4, $matchingResident = 1;
"GEOFANCY $name: Found matching UUID at GUEST device $key"; last;
$deviceAlias = $key;
$matchingResident = 1;
last;
}
} }
} }
} }
@ -410,18 +396,13 @@ 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} ); foreach (@devices) {
my @device = split( ':', $_ );
if (@devices) { $hash->{helper}{device_aliases}{ $device[0] } =
foreach (@devices) { $device[1];
my @device = split( ':', $_ ); $hash->{helper}{device_names}{ $device[1] } =
$hash->{helper}{device_aliases}{ $device[0] } = $device[0];
$device[1];
$hash->{helper}{device_names}{ $device[1] } =
$device[0];
}
}
} }
$deviceAlias = $hash->{helper}{device_aliases}{$device} $deviceAlias = $hash->{helper}{device_aliases}{$device}
@ -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";