Async migration device_tracker (#4406)

* Async migration device_tracker

* change location stuff to async

* address paulus comments

* fix lint & add async discovery listener

* address paulus comments v2

* fix tests

* fix test_mqtt

* fix test_init

* fix gps_acc

* fix lint

* change async_update_stale to callback
This commit is contained in:
Pascal Vizeli
2016-11-18 23:35:08 +01:00
committed by GitHub
parent 265232af98
commit c56f99baaf
7 changed files with 233 additions and 120 deletions

View File

@@ -8,7 +8,10 @@ from homeassistant.util import location as loc_util
def has_location(state: State) -> bool:
"""Test if state contains a valid location."""
"""Test if state contains a valid location.
Async friendly.
"""
return (isinstance(state, State) and
isinstance(state.attributes.get(ATTR_LATITUDE), float) and
isinstance(state.attributes.get(ATTR_LONGITUDE), float))
@@ -16,7 +19,10 @@ def has_location(state: State) -> bool:
def closest(latitude: float, longitude: float,
states: Sequence[State]) -> State:
"""Return closest state to point."""
"""Return closest state to point.
Async friendly.
"""
with_location = [state for state in states if has_location(state)]
if not with_location: