mirror of
https://github.com/home-assistant/core.git
synced 2025-11-14 13:30:43 +00:00
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:
@@ -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)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user