|
1 | 1 | """ |
2 | 2 | A Device Tracker platform that combines one or more device trackers. |
3 | 3 | """ |
4 | | -from datetime import datetime |
| 4 | +from datetime import datetime, timedelta |
5 | 5 | import logging |
6 | 6 | import threading |
7 | 7 |
|
|
28 | 28 |
|
29 | 29 | _LOGGER = logging.getLogger(__name__) |
30 | 30 |
|
31 | | -__version__ = '1.10.1' |
| 31 | +__version__ = '1.11.0' |
32 | 32 |
|
33 | 33 | CONF_TIME_AS = 'time_as' |
34 | 34 | CONF_REQ_MOVEMENT = 'require_movement' |
@@ -71,6 +71,12 @@ def setup_scanner(hass, config, see, discovery_info=None): |
71 | 71 | return True |
72 | 72 |
|
73 | 73 |
|
| 74 | +def nearest_second(time): |
| 75 | + """Round time to nearest second.""" |
| 76 | + return (time.replace(microsecond=0) + |
| 77 | + timedelta(seconds=0 if time.microsecond < 500000 else 1)) |
| 78 | + |
| 79 | + |
74 | 80 | class CompositeScanner: |
75 | 81 | def __init__(self, hass, config, see): |
76 | 82 | self._hass = hass |
@@ -271,6 +277,15 @@ def _update_info(self, entity_id, old_state, new_state): |
271 | 277 | # use it and make source_type gps. |
272 | 278 | elif gps: |
273 | 279 | source_type = SOURCE_TYPE_GPS |
| 280 | + # Otherwise, if new state is 'home' and old state is not 'home' |
| 281 | + # and no GPS data, then use HA's configured Home location and |
| 282 | + # make source_type gps. |
| 283 | + elif state == STATE_HOME and cur_state.state != STATE_HOME: |
| 284 | + gps = ( |
| 285 | + self._hass.config.latitude, |
| 286 | + self._hass.config.longitude) |
| 287 | + gps_accuracy = 0 |
| 288 | + source_type = SOURCE_TYPE_GPS |
274 | 289 | # Otherwise, don't use any GPS data, but set location_name to |
275 | 290 | # new state. |
276 | 291 | else: |
@@ -311,8 +326,7 @@ def _update_info(self, entity_id, old_state, new_state): |
311 | 326 | if entity[ATTR_SOURCE_TYPE] is not None), |
312 | 327 | ATTR_LAST_ENTITY_ID: entity_id, |
313 | 328 | ATTR_LAST_SEEN: |
314 | | - self._dt_attr_from_utc(last_seen.replace(microsecond=0), |
315 | | - tz) |
| 329 | + self._dt_attr_from_utc(nearest_second(last_seen), tz) |
316 | 330 | }) |
317 | 331 | if charging is not None: |
318 | 332 | attrs[ATTR_BATTERY_CHARGING] = charging |
|
0 commit comments