Start type annotating/testing helpers (#17858)

* Add type hints to helpers.intent and location

* Test typing for helpers.icon, json, and typing

* Add type hints to helpers.state

* Add type hints to helpers.translation
This commit is contained in:
Ville Skyttä 2018-10-28 21:12:52 +02:00 committed by GitHub
parent 0f877711a0
commit c9c707e368
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 92 additions and 55 deletions

View file

@ -1,6 +1,6 @@
"""Location helpers for Home Assistant."""
from typing import Sequence
from typing import Optional, Sequence
from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE
from homeassistant.core import State
@ -18,7 +18,7 @@ def has_location(state: State) -> bool:
def closest(latitude: float, longitude: float,
states: Sequence[State]) -> State:
states: Sequence[State]) -> Optional[State]:
"""Return closest state to point.
Async friendly.
@ -31,6 +31,7 @@ def closest(latitude: float, longitude: float,
return min(
with_location,
key=lambda state: loc_util.distance(
latitude, longitude, state.attributes.get(ATTR_LATITUDE),
state.attributes.get(ATTR_LONGITUDE))
state.attributes.get(ATTR_LATITUDE),
state.attributes.get(ATTR_LONGITUDE),
latitude, longitude)
)