Skip to content
Merged
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
22 changes: 18 additions & 4 deletions custom_components/composite/device_tracker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
A Device Tracker platform that combines one or more device trackers.
"""
from datetime import datetime
from datetime import datetime, timedelta
import logging
import threading

Expand All @@ -28,7 +28,7 @@

_LOGGER = logging.getLogger(__name__)

__version__ = '1.10.1'
__version__ = '1.11.0'

CONF_TIME_AS = 'time_as'
CONF_REQ_MOVEMENT = 'require_movement'
Expand Down Expand Up @@ -71,6 +71,12 @@ def setup_scanner(hass, config, see, discovery_info=None):
return True


def nearest_second(time):
"""Round time to nearest second."""
return (time.replace(microsecond=0) +
timedelta(seconds=0 if time.microsecond < 500000 else 1))


class CompositeScanner:
def __init__(self, hass, config, see):
self._hass = hass
Expand Down Expand Up @@ -271,6 +277,15 @@ def _update_info(self, entity_id, old_state, new_state):
# use it and make source_type gps.
elif gps:
source_type = SOURCE_TYPE_GPS
# Otherwise, if new state is 'home' and old state is not 'home'
# and no GPS data, then use HA's configured Home location and
# make source_type gps.
elif state == STATE_HOME and cur_state.state != STATE_HOME:
gps = (
self._hass.config.latitude,
self._hass.config.longitude)
gps_accuracy = 0
source_type = SOURCE_TYPE_GPS
# Otherwise, don't use any GPS data, but set location_name to
# new state.
else:
Expand Down Expand Up @@ -311,8 +326,7 @@ def _update_info(self, entity_id, old_state, new_state):
if entity[ATTR_SOURCE_TYPE] is not None),
ATTR_LAST_ENTITY_ID: entity_id,
ATTR_LAST_SEEN:
self._dt_attr_from_utc(last_seen.replace(microsecond=0),
tz)
self._dt_attr_from_utc(nearest_second(last_seen), tz)
})
if charging is not None:
attrs[ATTR_BATTERY_CHARGING] = charging
Expand Down