From 89c4efcb793b18df72401b6c1c0d5a1d11c97b5e Mon Sep 17 00:00:00 2001 From: Phil Date: Wed, 10 Jul 2019 11:57:41 -0500 Subject: [PATCH 1/2] Add require_movement config var --- custom_components/composite/device_tracker.py | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/custom_components/composite/device_tracker.py b/custom_components/composite/device_tracker.py index 15d0dde..00b0f6f 100644 --- a/custom_components/composite/device_tracker.py +++ b/custom_components/composite/device_tracker.py @@ -24,12 +24,14 @@ from homeassistant.helpers.event import track_state_change from homeassistant.util.async_ import run_callback_threadsafe import homeassistant.util.dt as dt_util +from homeassistant.util.location import distance _LOGGER = logging.getLogger(__name__) -__version__ = '1.9.0' +__version__ = '1.10.0' CONF_TIME_AS = 'time_as' +CONF_REQ_MOVEMENT = 'require_movement' TZ_UTC = 'utc' TZ_LOCAL = 'local' @@ -59,6 +61,7 @@ vol.Required(CONF_ENTITY_ID): cv.entity_ids, vol.Optional(CONF_TIME_AS, default=TIME_AS_OPTS[0]): vol.In(TIME_AS_OPTS), + vol.Optional(CONF_REQ_MOVEMENT, default=False): cv.boolean, }) @@ -84,6 +87,7 @@ def __init__(self, hass, config, see): if self._time_as in [TZ_DEVICE_UTC, TZ_DEVICE_LOCAL]: from timezonefinderL import TimezoneFinder self._tf = TimezoneFinder() + self._req_movement = config[CONF_REQ_MOVEMENT] self._lock = threading.Lock() self._prev_seen = None @@ -194,6 +198,22 @@ def _update_info(self, entity_id, old_state, new_state, init=False): self._bad_entity(entity_id, 'missing gps_accuracy attribute', init) return + if self._req_movement and old_state is not None: + try: + old_lat = old_state.attributes[ATTR_LATITUDE] + old_lon = old_state.attributes[ATTR_LONGITUDE] + old_acc = old_state.attributes[ATTR_GPS_ACCURACY] + except KeyError: + self._bad_entity(entity_id, + 'old_state missing gps data', init) + return + if (distance(gps[0], gps[1], old_lat, old_lon) <= + gps_accuracy + old_acc): + _LOGGER.debug( + 'For {} skipping update from {}: ' + 'not enough movement' + .format(self._entity_id, entity_id)) + return self._good_entity(entity_id, SOURCE_TYPE_GPS, state) elif source_type in SOURCE_TYPE_NON_GPS: From bfcfa12d84c68733c21ab8125a571fe75b1b8442 Mon Sep 17 00:00:00 2001 From: Phil Bruckner Date: Wed, 10 Jul 2019 12:03:21 -0500 Subject: [PATCH 2/2] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e368218..5a7b81e 100644 --- a/README.md +++ b/README.md @@ -45,9 +45,10 @@ sudo apt install libatlas3-base ## Configuration variables +- **entity_id**: Entity IDs of watched device tracker devices. Can be a single entity ID, a list of entity IDs, or a string containing multiple entity IDs separated by commas. - **name**: Object ID (i.e., part of entity ID after the dot) of composite device. For example, `NAME` would result in an entity ID of `device_tracker.NAME`. +- **require_movement** (*Optional*): `true` or `false`. If `true`, will skip update from a GPS-based tracker if it has not moved. Specifically, if circle defined by new GPS coordinates and accuracy overlaps circle defined by previous GPS coordinates and accuracy then update will be ignored. - **time_as** (*Optional*): One of `utc`, `local`, `device_or_utc` or `device_or_local`. Default is `utc` which shows time attributes in UTC. `local` shows time attributes per HA's `time_zone` configuration. `device_or_utc` and `device_or_local` attempt to determine the time zone in which the device is located based on its GPS coordinates. The name of the time zone (or `unknown`) will be shown in a new attribute named `time_zone`. If the time zone can be determined, then time attributes will be shown in that time zone. If the time zone cannot be determined, then time attributes will be shown in UTC if `device_or_utc` is selected, or in HA's local time zone if `device_or_local` is selected. -- **entity_id**: Entity IDs of watched device tracker devices. Can be a single entity ID, a list of entity IDs, or a string containing multiple entity IDs separated by commas. ## Watched device notes