From 3325066859877d0474bbdcb5f583d6d4a64f274c Mon Sep 17 00:00:00 2001 From: Kevin Stillhammer Date: Thu, 1 Oct 2026 19:43:36 +0200 Subject: [PATCH] Bump pywaze to 1.2.3 and close Waze clients on unload (#183923) --- .../components/waze_travel_time/__init__.py | 1 + .../components/waze_travel_time/helpers.py | 12 +++---- .../components/waze_travel_time/manifest.json | 2 +- .../components/waze_travel_time/services.py | 36 +++++++++---------- requirements_all.txt | 2 +- 5 files changed, 27 insertions(+), 26 deletions(-) diff --git a/homeassistant/components/waze_travel_time/__init__.py b/homeassistant/components/waze_travel_time/__init__.py index 5af3dfface6a..a67c03fc4e76 100644 --- a/homeassistant/components/waze_travel_time/__init__.py +++ b/homeassistant/components/waze_travel_time/__init__.py @@ -49,6 +49,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b client = WazeRouteCalculator( region=config_entry.data[CONF_REGION].upper(), client=httpx_client ) + config_entry.async_on_unload(client.close) coordinator = WazeTravelTimeCoordinator(hass, config_entry, client) config_entry.runtime_data = coordinator diff --git a/homeassistant/components/waze_travel_time/helpers.py b/homeassistant/components/waze_travel_time/helpers.py index 7bee77e8e4fd..c2d3d5d37122 100644 --- a/homeassistant/components/waze_travel_time/helpers.py +++ b/homeassistant/components/waze_travel_time/helpers.py @@ -38,10 +38,10 @@ async def is_valid_config_entry( resolved_origin = find_coordinates(hass, origin) resolved_destination = find_coordinates(hass, destination) httpx_client = get_async_client(hass) - client = WazeRouteCalculator(region=region, client=httpx_client) - try: - await client.calc_routes(resolved_origin, resolved_destination) - except WRCError as error: - _LOGGER.error("Error trying to validate entry: %s", error) - return False + async with WazeRouteCalculator(region=region, client=httpx_client) as client: + try: + await client.calc_routes(resolved_origin, resolved_destination) + except WRCError as error: + _LOGGER.error("Error trying to validate entry: %s", error) + return False return True diff --git a/homeassistant/components/waze_travel_time/manifest.json b/homeassistant/components/waze_travel_time/manifest.json index 312db2587cd8..d677c06512a9 100644 --- a/homeassistant/components/waze_travel_time/manifest.json +++ b/homeassistant/components/waze_travel_time/manifest.json @@ -7,5 +7,5 @@ "integration_type": "service", "iot_class": "cloud_polling", "loggers": ["pywaze", "homeassistant.helpers.location"], - "requirements": ["pywaze==1.2.1"] + "requirements": ["pywaze==1.2.3"] } diff --git a/homeassistant/components/waze_travel_time/services.py b/homeassistant/components/waze_travel_time/services.py index 4193f123a2ac..4671921f65db 100644 --- a/homeassistant/components/waze_travel_time/services.py +++ b/homeassistant/components/waze_travel_time/services.py @@ -113,9 +113,6 @@ SERVICE_GET_TRAVEL_TIMES_SCHEMA = probatio.Schema( async def async_get_travel_times_service(service: ServiceCall) -> ServiceResponse: """Get travel times.""" httpx_client = get_async_client(service.hass) - client = WazeRouteCalculator( - region=service.data[CONF_REGION].upper(), client=httpx_client - ) origin_coordinates = find_coordinates(service.hass, service.data[CONF_ORIGIN]) destination_coordinates = find_coordinates( @@ -135,21 +132,24 @@ async def async_get_travel_times_service(service: ServiceCall) -> ServiceRespons / 60 ) - response = await async_get_travel_times( - client=client, - origin=origin, - destination=destination, - vehicle_type=service.data[CONF_VEHICLE_TYPE], - avoid_toll_roads=service.data[CONF_AVOID_TOLL_ROADS], - avoid_subscription_roads=service.data[CONF_AVOID_SUBSCRIPTION_ROADS], - avoid_ferries=service.data[CONF_AVOID_FERRIES], - realtime=service.data[CONF_REALTIME], - units=service.data[CONF_UNITS], - incl_filters=service.data.get(CONF_INCL_FILTER, DEFAULT_FILTER), - excl_filters=service.data.get(CONF_EXCL_FILTER, DEFAULT_FILTER), - time_delta=time_delta, - base_coordinates=base_coordinates, - ) + async with WazeRouteCalculator( + region=service.data[CONF_REGION].upper(), client=httpx_client + ) as client: + response = await async_get_travel_times( + client=client, + origin=origin, + destination=destination, + vehicle_type=service.data[CONF_VEHICLE_TYPE], + avoid_toll_roads=service.data[CONF_AVOID_TOLL_ROADS], + avoid_subscription_roads=service.data[CONF_AVOID_SUBSCRIPTION_ROADS], + avoid_ferries=service.data[CONF_AVOID_FERRIES], + realtime=service.data[CONF_REALTIME], + units=service.data[CONF_UNITS], + incl_filters=service.data.get(CONF_INCL_FILTER, DEFAULT_FILTER), + excl_filters=service.data.get(CONF_EXCL_FILTER, DEFAULT_FILTER), + time_delta=time_delta, + base_coordinates=base_coordinates, + ) return {"routes": [vars(route) for route in response]} diff --git a/requirements_all.txt b/requirements_all.txt index 2ea995522f2b..3b2f4e5b143a 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2888,7 +2888,7 @@ pyvlx==0.2.36 pyvolumio==0.1.5 # homeassistant.components.waze_travel_time -pywaze==1.2.1 +pywaze==1.2.3 # homeassistant.components.weatherflow pyweatherflowudp==1.6.3