mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Added resolve_state to template distance function (#17290)
_resolve_state was already used in the "closest" function, to allow for states and entity ids
This commit is contained in:
committed by
Paulus Schoutsen
parent
419725e1a9
commit
670c75e844
@@ -367,18 +367,9 @@ class TemplateMethods:
|
||||
|
||||
while to_process:
|
||||
value = to_process.pop(0)
|
||||
point_state = self._resolve_state(value)
|
||||
|
||||
if isinstance(value, State):
|
||||
latitude = value.attributes.get(ATTR_LATITUDE)
|
||||
longitude = value.attributes.get(ATTR_LONGITUDE)
|
||||
|
||||
if latitude is None or longitude is None:
|
||||
_LOGGER.warning(
|
||||
"Distance:State does not contains a location: %s",
|
||||
value)
|
||||
return None
|
||||
|
||||
else:
|
||||
if point_state is None:
|
||||
# We expect this and next value to be lat&lng
|
||||
if not to_process:
|
||||
_LOGGER.warning(
|
||||
@@ -395,6 +386,22 @@ class TemplateMethods:
|
||||
"longitude: %s, %s", value, value_2)
|
||||
return None
|
||||
|
||||
else:
|
||||
if not loc_helper.has_location(point_state):
|
||||
_LOGGER.warning(
|
||||
"distance:State does not contain valid location: %s",
|
||||
point_state)
|
||||
return None
|
||||
|
||||
latitude = point_state.attributes.get(ATTR_LATITUDE)
|
||||
longitude = point_state.attributes.get(ATTR_LONGITUDE)
|
||||
|
||||
if latitude is None or longitude is None:
|
||||
_LOGGER.warning(
|
||||
"Distance:State does not contains a location: %s",
|
||||
value)
|
||||
return None
|
||||
|
||||
locations.append((latitude, longitude))
|
||||
|
||||
if len(locations) == 1:
|
||||
|
||||
Reference in New Issue
Block a user