From 1496240c75467ba500b09d2df69555754d95514e Mon Sep 17 00:00:00 2001 From: loredo Date: Sat, 2 Jan 2016 04:14:15 +0000 Subject: [PATCH] ROOMMATE,GUEST: location readings git-svn-id: https://svn.fhem.de/fhem/trunk@10328 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/20_GUEST.pm | 35 ++++++++++++++++++++++++++++------- fhem/FHEM/20_ROOMMATE.pm | 35 ++++++++++++++++++++++++++++------- 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/fhem/FHEM/20_GUEST.pm b/fhem/FHEM/20_GUEST.pm index bf695401d..da75a42c3 100644 --- a/fhem/FHEM/20_GUEST.pm +++ b/fhem/FHEM/20_GUEST.pm @@ -925,7 +925,14 @@ sub GUEST_SetLocation($$$;$$$$$$) { my $hash = $defs{$name}; my $state = ReadingsVal( $name, "state", "initialized" ); my $presence = ReadingsVal( $name, "presence", "present" ); - my $lastLocation = ReadingsVal( $name, "location", undef ); + my $currLocation = ReadingsVal( $name, "location", "-" ); + my $currLat = ReadingsVal( $name, "locationLat", "-" ); + my $currLong = ReadingsVal( $name, "locationLong", "-" ); + my $currAddr = ReadingsVal( $name, "locationAddr", "-" ); + $id = "-" if ( !$id || $id eq "" ); + $lat = "-" if ( !$lat || $lat eq "" ); + $long = "-" if ( !$long || $long eq "" ); + $address = "-" if ( !$address || $address eq "" ); $location = "underway" if ( $trigger eq "0" ); Log3 $name, 5, @@ -944,12 +951,26 @@ sub GUEST_SetLocation($$$;$$$$$$) { split( ' ', AttrVal( $name, "rr_locationWayhome", "wayhome" ) ); $searchstring = quotemeta($location); - readingsBulkUpdate( $hash, "lastLocation", $lastLocation ) - if ( $lastLocation - && $location ne "wayhome" - && !grep( m/^$searchstring$/, @location_underway ) ); - readingsBulkUpdate( $hash, "location", $location ) - if ( $location ne "wayhome" ); + if ( $location ne "wayhome" ) { + if ( + !grep( m/^$searchstring$/, @location_underway ) + && ( $currLocation ne $location + || $currLat ne $lat + || $currLong ne $long + || $currAddr ne $address ) + ) + { + readingsBulkUpdate( $hash, "lastLocation", $currLocation ); + readingsBulkUpdate( $hash, "lastLocationLat", $currLat ); + readingsBulkUpdate( $hash, "lastLocationLong", $currLong ); + readingsBulkUpdate( $hash, "lastLocationAddr", $currAddr ); + } + + readingsBulkUpdate( $hash, "location", $location ); + readingsBulkUpdate( $hash, "locationLat", $lat ); + readingsBulkUpdate( $hash, "locationLong", $long ); + readingsBulkUpdate( $hash, "locationAddr", $address ); + } # wayhome detection $searchstring = quotemeta($location); diff --git a/fhem/FHEM/20_ROOMMATE.pm b/fhem/FHEM/20_ROOMMATE.pm index 2ee697507..4941f3791 100644 --- a/fhem/FHEM/20_ROOMMATE.pm +++ b/fhem/FHEM/20_ROOMMATE.pm @@ -898,7 +898,14 @@ sub ROOMMATE_SetLocation($$$;$$$$$$) { my $hash = $defs{$name}; my $state = ReadingsVal( $name, "state", "initialized" ); my $presence = ReadingsVal( $name, "presence", "present" ); - my $lastLocation = ReadingsVal( $name, "location", undef ); + my $currLocation = ReadingsVal( $name, "location", "-" ); + my $currLat = ReadingsVal( $name, "locationLat", "-" ); + my $currLong = ReadingsVal( $name, "locationLong", "-" ); + my $currAddr = ReadingsVal( $name, "locationAddr", "-" ); + $id = "-" if ( !$id || $id eq "" ); + $lat = "-" if ( !$lat || $lat eq "" ); + $long = "-" if ( !$long || $long eq "" ); + $address = "-" if ( !$address || $address eq "" ); $location = "underway" if ( $trigger eq "0" ); Log3 $name, 5, @@ -917,12 +924,26 @@ sub ROOMMATE_SetLocation($$$;$$$$$$) { split( ' ', AttrVal( $name, "rr_locationWayhome", "wayhome" ) ); $searchstring = quotemeta($location); - readingsBulkUpdate( $hash, "lastLocation", $lastLocation ) - if ( $lastLocation - && $location ne "wayhome" - && !grep( m/^$searchstring$/, @location_underway ) ); - readingsBulkUpdate( $hash, "location", $location ) - if ( $location ne "wayhome" ); + if ( $location ne "wayhome" ) { + if ( + !grep( m/^$searchstring$/, @location_underway ) + && ( $currLocation ne $location + || $currLat ne $lat + || $currLong ne $long + || $currAddr ne $address ) + ) + { + readingsBulkUpdate( $hash, "lastLocation", $currLocation ); + readingsBulkUpdate( $hash, "lastLocationLat", $currLat ); + readingsBulkUpdate( $hash, "lastLocationLong", $currLong ); + readingsBulkUpdate( $hash, "lastLocationAddr", $currAddr ); + } + + readingsBulkUpdate( $hash, "location", $location ); + readingsBulkUpdate( $hash, "locationLat", $lat ); + readingsBulkUpdate( $hash, "locationLong", $long ); + readingsBulkUpdate( $hash, "locationAddr", $address ); + } # wayhome detection $searchstring = quotemeta($location);