Home Assistant Unofficial Reference 2024.12.1
helpers.py
Go to the documentation of this file.
1 """Helpers for Waze Travel Time integration."""
2 
3 import logging
4 
5 from pywaze.route_calculator import WazeRouteCalculator, WRCError
6 
7 from homeassistant.core import HomeAssistant
8 from homeassistant.helpers.httpx_client import get_async_client
9 from homeassistant.helpers.location import find_coordinates
10 
11 _LOGGER = logging.getLogger(__name__)
12 
13 
15  hass: HomeAssistant, origin: str, destination: str, region: str
16 ) -> bool:
17  """Return whether the config entry data is valid."""
18  resolved_origin = find_coordinates(hass, origin)
19  resolved_destination = find_coordinates(hass, destination)
20  httpx_client = get_async_client(hass)
21  client = WazeRouteCalculator(region=region, client=httpx_client)
22  try:
23  await client.calc_routes(resolved_origin, resolved_destination)
24  except WRCError as error:
25  _LOGGER.error("Error trying to validate entry: %s", error)
26  return False
27  return True
bool is_valid_config_entry(HomeAssistant hass, str origin, str destination, str region)
Definition: helpers.py:16
httpx.AsyncClient get_async_client(HomeAssistant hass, bool verify_ssl=True)
Definition: httpx_client.py:41
str|None find_coordinates(HomeAssistant hass, str name, list|None recursion_history=None)
Definition: location.py:51