mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
google_travel_time: always resolve zones (#66165)
This commit is contained in:
parent
6ec0e3811a
commit
a17650550f
@ -26,8 +26,6 @@ TIME_TYPES = [ARRIVAL_TIME, DEPARTURE_TIME]
|
|||||||
|
|
||||||
DEFAULT_NAME = "Google Travel Time"
|
DEFAULT_NAME = "Google Travel Time"
|
||||||
|
|
||||||
TRACKABLE_DOMAINS = ["device_tracker", "sensor", "zone", "person"]
|
|
||||||
|
|
||||||
ALL_LANGUAGES = [
|
ALL_LANGUAGES = [
|
||||||
"ar",
|
"ar",
|
||||||
"bg",
|
"bg",
|
||||||
|
@ -35,7 +35,6 @@ from .const import (
|
|||||||
CONF_UNITS,
|
CONF_UNITS,
|
||||||
DEFAULT_NAME,
|
DEFAULT_NAME,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
TRACKABLE_DOMAINS,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -109,17 +108,10 @@ class GoogleTravelTimeSensor(SensorEntity):
|
|||||||
self._api_key = api_key
|
self._api_key = api_key
|
||||||
self._unique_id = config_entry.entry_id
|
self._unique_id = config_entry.entry_id
|
||||||
self._client = client
|
self._client = client
|
||||||
|
self._origin = origin
|
||||||
# Check if location is a trackable entity
|
self._destination = destination
|
||||||
if origin.split(".", 1)[0] in TRACKABLE_DOMAINS:
|
self._resolved_origin = None
|
||||||
self._origin_entity_id = origin
|
self._resolved_destination = None
|
||||||
else:
|
|
||||||
self._origin = origin
|
|
||||||
|
|
||||||
if destination.split(".", 1)[0] in TRACKABLE_DOMAINS:
|
|
||||||
self._destination_entity_id = destination
|
|
||||||
else:
|
|
||||||
self._destination = destination
|
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Handle when entity is added."""
|
"""Handle when entity is added."""
|
||||||
@ -179,8 +171,8 @@ class GoogleTravelTimeSensor(SensorEntity):
|
|||||||
res["duration"] = _data["duration"]["text"]
|
res["duration"] = _data["duration"]["text"]
|
||||||
if "distance" in _data:
|
if "distance" in _data:
|
||||||
res["distance"] = _data["distance"]["text"]
|
res["distance"] = _data["distance"]["text"]
|
||||||
res["origin"] = self._origin
|
res["origin"] = self._resolved_origin
|
||||||
res["destination"] = self._destination
|
res["destination"] = self._resolved_destination
|
||||||
res[ATTR_ATTRIBUTION] = ATTRIBUTION
|
res[ATTR_ATTRIBUTION] = ATTRIBUTION
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@ -211,14 +203,18 @@ class GoogleTravelTimeSensor(SensorEntity):
|
|||||||
elif atime is not None:
|
elif atime is not None:
|
||||||
options_copy[CONF_ARRIVAL_TIME] = atime
|
options_copy[CONF_ARRIVAL_TIME] = atime
|
||||||
|
|
||||||
# Convert device_trackers to google friendly location
|
self._resolved_origin = find_coordinates(self.hass, self._origin)
|
||||||
if hasattr(self, "_origin_entity_id"):
|
self._resolved_destination = find_coordinates(self.hass, self._destination)
|
||||||
self._origin = find_coordinates(self.hass, self._origin_entity_id)
|
|
||||||
|
|
||||||
if hasattr(self, "_destination_entity_id"):
|
_LOGGER.debug(
|
||||||
self._destination = find_coordinates(self.hass, self._destination_entity_id)
|
"Getting update for origin: %s destination: %s",
|
||||||
|
self._resolved_origin,
|
||||||
if self._destination is not None and self._origin is not None:
|
self._resolved_destination,
|
||||||
|
)
|
||||||
|
if self._resolved_destination is not None and self._resolved_origin is not None:
|
||||||
self._matrix = distance_matrix(
|
self._matrix = distance_matrix(
|
||||||
self._client, self._origin, self._destination, **options_copy
|
self._client,
|
||||||
|
self._resolved_origin,
|
||||||
|
self._resolved_destination,
|
||||||
|
**options_copy,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user