Skip to content

Commit cd86e17

Browse files
authored
Add optional require_movement configuration variable & bump to 1.10.0 (pnbruckner#2)
1 parent 2609335 commit cd86e17

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ sudo apt install libatlas3-base
4545

4646
## Configuration variables
4747

48+
- **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.
4849
- **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`.
50+
- **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.
4951
- **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.
50-
- **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.
5152

5253
## Watched device notes
5354

custom_components/composite/device_tracker.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
from homeassistant.helpers.event import track_state_change
2525
from homeassistant.util.async_ import run_callback_threadsafe
2626
import homeassistant.util.dt as dt_util
27+
from homeassistant.util.location import distance
2728

2829
_LOGGER = logging.getLogger(__name__)
2930

30-
__version__ = '1.9.0'
31+
__version__ = '1.10.0'
3132

3233
CONF_TIME_AS = 'time_as'
34+
CONF_REQ_MOVEMENT = 'require_movement'
3335

3436
TZ_UTC = 'utc'
3537
TZ_LOCAL = 'local'
@@ -59,6 +61,7 @@
5961
vol.Required(CONF_ENTITY_ID): cv.entity_ids,
6062
vol.Optional(CONF_TIME_AS, default=TIME_AS_OPTS[0]):
6163
vol.In(TIME_AS_OPTS),
64+
vol.Optional(CONF_REQ_MOVEMENT, default=False): cv.boolean,
6265
})
6366

6467

@@ -84,6 +87,7 @@ def __init__(self, hass, config, see):
8487
if self._time_as in [TZ_DEVICE_UTC, TZ_DEVICE_LOCAL]:
8588
from timezonefinderL import TimezoneFinder
8689
self._tf = TimezoneFinder()
90+
self._req_movement = config[CONF_REQ_MOVEMENT]
8791
self._lock = threading.Lock()
8892
self._prev_seen = None
8993

@@ -194,6 +198,22 @@ def _update_info(self, entity_id, old_state, new_state, init=False):
194198
self._bad_entity(entity_id,
195199
'missing gps_accuracy attribute', init)
196200
return
201+
if self._req_movement and old_state is not None:
202+
try:
203+
old_lat = old_state.attributes[ATTR_LATITUDE]
204+
old_lon = old_state.attributes[ATTR_LONGITUDE]
205+
old_acc = old_state.attributes[ATTR_GPS_ACCURACY]
206+
except KeyError:
207+
self._bad_entity(entity_id,
208+
'old_state missing gps data', init)
209+
return
210+
if (distance(gps[0], gps[1], old_lat, old_lon) <=
211+
gps_accuracy + old_acc):
212+
_LOGGER.debug(
213+
'For {} skipping update from {}: '
214+
'not enough movement'
215+
.format(self._entity_id, entity_id))
216+
return
197217
self._good_entity(entity_id, SOURCE_TYPE_GPS, state)
198218

199219
elif source_type in SOURCE_TYPE_NON_GPS:

0 commit comments

Comments
 (0)