Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 21 additions & 1 deletion custom_components/composite/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
})


Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand Down