mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Bump pywaze to 1.0.0 (#108613)
This commit is contained in:
parent
7b2166243b
commit
3d6600364b
@ -20,7 +20,7 @@ async def is_valid_config_entry(
|
|||||||
httpx_client = get_async_client(hass)
|
httpx_client = get_async_client(hass)
|
||||||
client = WazeRouteCalculator(region=region, client=httpx_client)
|
client = WazeRouteCalculator(region=region, client=httpx_client)
|
||||||
try:
|
try:
|
||||||
await client.calc_all_routes_info(resolved_origin, resolved_destination)
|
await client.calc_routes(resolved_origin, resolved_destination)
|
||||||
except WRCError as error:
|
except WRCError as error:
|
||||||
_LOGGER.error("Error trying to validate entry: %s", error)
|
_LOGGER.error("Error trying to validate entry: %s", error)
|
||||||
return False
|
return False
|
||||||
|
@ -6,5 +6,5 @@
|
|||||||
"documentation": "https://www.home-assistant.io/integrations/waze_travel_time",
|
"documentation": "https://www.home-assistant.io/integrations/waze_travel_time",
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"loggers": ["pywaze", "homeassistant.helpers.location"],
|
"loggers": ["pywaze", "homeassistant.helpers.location"],
|
||||||
"requirements": ["pywaze==0.5.1"]
|
"requirements": ["pywaze==1.0.0"]
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ class WazeTravelTimeData:
|
|||||||
|
|
||||||
routes = {}
|
routes = {}
|
||||||
try:
|
try:
|
||||||
routes = await self.client.calc_all_routes_info(
|
routes = await self.client.calc_routes(
|
||||||
self.origin,
|
self.origin,
|
||||||
self.destination,
|
self.destination,
|
||||||
vehicle_type=vehicle_type,
|
vehicle_type=vehicle_type,
|
||||||
@ -204,29 +204,37 @@ class WazeTravelTimeData:
|
|||||||
avoid_subscription_roads=avoid_subscription_roads,
|
avoid_subscription_roads=avoid_subscription_roads,
|
||||||
avoid_ferries=avoid_ferries,
|
avoid_ferries=avoid_ferries,
|
||||||
real_time=realtime,
|
real_time=realtime,
|
||||||
|
alternatives=3,
|
||||||
)
|
)
|
||||||
|
|
||||||
if incl_filter not in {None, ""}:
|
if incl_filter not in {None, ""}:
|
||||||
routes = {
|
routes = [
|
||||||
k: v
|
r
|
||||||
for k, v in routes.items()
|
for r in routes
|
||||||
if incl_filter.lower() in k.lower()
|
if any(
|
||||||
}
|
incl_filter.lower() == street_name.lower()
|
||||||
|
for street_name in r.street_names
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
if excl_filter not in {None, ""}:
|
if excl_filter not in {None, ""}:
|
||||||
routes = {
|
routes = [
|
||||||
k: v
|
r
|
||||||
for k, v in routes.items()
|
for r in routes
|
||||||
if excl_filter.lower() not in k.lower()
|
if not any(
|
||||||
}
|
excl_filter.lower() == street_name.lower()
|
||||||
|
for street_name in r.street_names
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
if routes:
|
if len(routes) < 1:
|
||||||
route = list(routes)[0]
|
|
||||||
else:
|
|
||||||
_LOGGER.warning("No routes found")
|
_LOGGER.warning("No routes found")
|
||||||
return
|
return
|
||||||
|
|
||||||
self.duration, distance = routes[route]
|
route = routes[0]
|
||||||
|
|
||||||
|
self.duration = route.duration
|
||||||
|
distance = route.distance
|
||||||
|
|
||||||
if units == IMPERIAL_UNITS:
|
if units == IMPERIAL_UNITS:
|
||||||
# Convert to miles.
|
# Convert to miles.
|
||||||
@ -236,10 +244,7 @@ class WazeTravelTimeData:
|
|||||||
else:
|
else:
|
||||||
self.distance = distance
|
self.distance = distance
|
||||||
|
|
||||||
self.route = route
|
self.route = route.name
|
||||||
except WRCError as exp:
|
except WRCError as exp:
|
||||||
_LOGGER.warning("Error on retrieving data: %s", exp)
|
_LOGGER.warning("Error on retrieving data: %s", exp)
|
||||||
return
|
return
|
||||||
except KeyError:
|
|
||||||
_LOGGER.error("Error retrieving data from server")
|
|
||||||
return
|
|
||||||
|
@ -26,8 +26,8 @@
|
|||||||
"data": {
|
"data": {
|
||||||
"units": "Units",
|
"units": "Units",
|
||||||
"vehicle_type": "Vehicle Type",
|
"vehicle_type": "Vehicle Type",
|
||||||
"incl_filter": "Substring in Description of Selected Route",
|
"incl_filter": "Streetname which must be part of the Selected Route",
|
||||||
"excl_filter": "Substring NOT in Description of Selected Route",
|
"excl_filter": "Streetname which must NOT be part of the Selected Route",
|
||||||
"realtime": "Realtime Travel Time?",
|
"realtime": "Realtime Travel Time?",
|
||||||
"avoid_toll_roads": "Avoid Toll Roads?",
|
"avoid_toll_roads": "Avoid Toll Roads?",
|
||||||
"avoid_ferries": "Avoid Ferries?",
|
"avoid_ferries": "Avoid Ferries?",
|
||||||
|
@ -2360,7 +2360,7 @@ pyvlx==0.2.21
|
|||||||
pyvolumio==0.1.5
|
pyvolumio==0.1.5
|
||||||
|
|
||||||
# homeassistant.components.waze_travel_time
|
# homeassistant.components.waze_travel_time
|
||||||
pywaze==0.5.1
|
pywaze==1.0.0
|
||||||
|
|
||||||
# homeassistant.components.weatherflow
|
# homeassistant.components.weatherflow
|
||||||
pyweatherflowudp==1.4.5
|
pyweatherflowudp==1.4.5
|
||||||
|
@ -1821,7 +1821,7 @@ pyvlx==0.2.21
|
|||||||
pyvolumio==0.1.5
|
pyvolumio==0.1.5
|
||||||
|
|
||||||
# homeassistant.components.waze_travel_time
|
# homeassistant.components.waze_travel_time
|
||||||
pywaze==0.5.1
|
pywaze==1.0.0
|
||||||
|
|
||||||
# homeassistant.components.weatherflow
|
# homeassistant.components.weatherflow
|
||||||
pyweatherflowudp==1.4.5
|
pyweatherflowudp==1.4.5
|
||||||
|
@ -3,15 +3,28 @@
|
|||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from pywaze.route_calculator import WRCError
|
from pywaze.route_calculator import CalcRoutesResponse, WRCError
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="mock_update")
|
@pytest.fixture(name="mock_update")
|
||||||
def mock_update_fixture():
|
def mock_update_fixture():
|
||||||
"""Mock an update to the sensor."""
|
"""Mock an update to the sensor."""
|
||||||
with patch(
|
with patch(
|
||||||
"pywaze.route_calculator.WazeRouteCalculator.calc_all_routes_info",
|
"pywaze.route_calculator.WazeRouteCalculator.calc_routes",
|
||||||
return_value={"My route": (150, 300)},
|
return_value=[
|
||||||
|
CalcRoutesResponse(
|
||||||
|
distance=300,
|
||||||
|
duration=150,
|
||||||
|
name="E1337 - Teststreet",
|
||||||
|
street_names=["E1337", "IncludeThis", "Teststreet"],
|
||||||
|
),
|
||||||
|
CalcRoutesResponse(
|
||||||
|
distance=500,
|
||||||
|
duration=600,
|
||||||
|
name="E0815 - Otherstreet",
|
||||||
|
street_names=["E0815", "ExcludeThis", "Otherstreet"],
|
||||||
|
),
|
||||||
|
],
|
||||||
) as mock_wrc:
|
) as mock_wrc:
|
||||||
yield mock_wrc
|
yield mock_wrc
|
||||||
|
|
||||||
|
@ -7,12 +7,15 @@ from homeassistant.components.waze_travel_time.const import (
|
|||||||
CONF_AVOID_FERRIES,
|
CONF_AVOID_FERRIES,
|
||||||
CONF_AVOID_SUBSCRIPTION_ROADS,
|
CONF_AVOID_SUBSCRIPTION_ROADS,
|
||||||
CONF_AVOID_TOLL_ROADS,
|
CONF_AVOID_TOLL_ROADS,
|
||||||
|
CONF_EXCL_FILTER,
|
||||||
|
CONF_INCL_FILTER,
|
||||||
CONF_REALTIME,
|
CONF_REALTIME,
|
||||||
CONF_UNITS,
|
CONF_UNITS,
|
||||||
CONF_VEHICLE_TYPE,
|
CONF_VEHICLE_TYPE,
|
||||||
DEFAULT_OPTIONS,
|
DEFAULT_OPTIONS,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
IMPERIAL_UNITS,
|
IMPERIAL_UNITS,
|
||||||
|
METRIC_UNITS,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
@ -22,7 +25,7 @@ from tests.common import MockConfigEntry
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="mock_config")
|
@pytest.fixture(name="mock_config")
|
||||||
async def mock_config_fixture(hass, data, options):
|
async def mock_config_fixture(hass: HomeAssistant, data, options):
|
||||||
"""Mock a Waze Travel Time config entry."""
|
"""Mock a Waze Travel Time config entry."""
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
@ -42,13 +45,6 @@ def mock_update_wrcerror_fixture(mock_update):
|
|||||||
return mock_update
|
return mock_update
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="mock_update_keyerror")
|
|
||||||
def mock_update_keyerror_fixture(mock_update):
|
|
||||||
"""Mock an update to the sensor failed with KeyError."""
|
|
||||||
mock_update.side_effect = KeyError("test")
|
|
||||||
return mock_update
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("data", "options"),
|
("data", "options"),
|
||||||
[(MOCK_CONFIG, DEFAULT_OPTIONS)],
|
[(MOCK_CONFIG, DEFAULT_OPTIONS)],
|
||||||
@ -63,7 +59,10 @@ async def test_sensor(hass: HomeAssistant) -> None:
|
|||||||
)
|
)
|
||||||
assert hass.states.get("sensor.waze_travel_time").attributes["duration"] == 150
|
assert hass.states.get("sensor.waze_travel_time").attributes["duration"] == 150
|
||||||
assert hass.states.get("sensor.waze_travel_time").attributes["distance"] == 300
|
assert hass.states.get("sensor.waze_travel_time").attributes["distance"] == 300
|
||||||
assert hass.states.get("sensor.waze_travel_time").attributes["route"] == "My route"
|
assert (
|
||||||
|
hass.states.get("sensor.waze_travel_time").attributes["route"]
|
||||||
|
== "E1337 - Teststreet"
|
||||||
|
)
|
||||||
assert (
|
assert (
|
||||||
hass.states.get("sensor.waze_travel_time").attributes["origin"] == "location1"
|
hass.states.get("sensor.waze_travel_time").attributes["origin"] == "location1"
|
||||||
)
|
)
|
||||||
@ -101,6 +100,52 @@ async def test_imperial(hass: HomeAssistant) -> None:
|
|||||||
] == pytest.approx(186.4113)
|
] == pytest.approx(186.4113)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("data", "options"),
|
||||||
|
[
|
||||||
|
(
|
||||||
|
MOCK_CONFIG,
|
||||||
|
{
|
||||||
|
CONF_UNITS: METRIC_UNITS,
|
||||||
|
CONF_REALTIME: True,
|
||||||
|
CONF_VEHICLE_TYPE: "car",
|
||||||
|
CONF_AVOID_TOLL_ROADS: True,
|
||||||
|
CONF_AVOID_SUBSCRIPTION_ROADS: True,
|
||||||
|
CONF_AVOID_FERRIES: True,
|
||||||
|
CONF_INCL_FILTER: "IncludeThis",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
@pytest.mark.usefixtures("mock_update", "mock_config")
|
||||||
|
async def test_incl_filter(hass: HomeAssistant) -> None:
|
||||||
|
"""Test that incl_filter only includes route with the wanted street name."""
|
||||||
|
assert hass.states.get("sensor.waze_travel_time").attributes["distance"] == 300
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("data", "options"),
|
||||||
|
[
|
||||||
|
(
|
||||||
|
MOCK_CONFIG,
|
||||||
|
{
|
||||||
|
CONF_UNITS: METRIC_UNITS,
|
||||||
|
CONF_REALTIME: True,
|
||||||
|
CONF_VEHICLE_TYPE: "car",
|
||||||
|
CONF_AVOID_TOLL_ROADS: True,
|
||||||
|
CONF_AVOID_SUBSCRIPTION_ROADS: True,
|
||||||
|
CONF_AVOID_FERRIES: True,
|
||||||
|
CONF_EXCL_FILTER: "ExcludeThis",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
@pytest.mark.usefixtures("mock_update", "mock_config")
|
||||||
|
async def test_excl_filter(hass: HomeAssistant) -> None:
|
||||||
|
"""Test that excl_filter only includes route without the street name."""
|
||||||
|
assert hass.states.get("sensor.waze_travel_time").attributes["distance"] == 300
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_update_wrcerror")
|
@pytest.mark.usefixtures("mock_update_wrcerror")
|
||||||
async def test_sensor_failed_wrcerror(
|
async def test_sensor_failed_wrcerror(
|
||||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
@ -115,19 +160,3 @@ async def test_sensor_failed_wrcerror(
|
|||||||
|
|
||||||
assert hass.states.get("sensor.waze_travel_time").state == "unknown"
|
assert hass.states.get("sensor.waze_travel_time").state == "unknown"
|
||||||
assert "Error on retrieving data: " in caplog.text
|
assert "Error on retrieving data: " in caplog.text
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_update_keyerror")
|
|
||||||
async def test_sensor_failed_keyerror(
|
|
||||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
|
||||||
) -> None:
|
|
||||||
"""Test that sensor update fails with log message."""
|
|
||||||
config_entry = MockConfigEntry(
|
|
||||||
domain=DOMAIN, data=MOCK_CONFIG, options=DEFAULT_OPTIONS, entry_id="test"
|
|
||||||
)
|
|
||||||
config_entry.add_to_hass(hass)
|
|
||||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert hass.states.get("sensor.waze_travel_time").state == "unknown"
|
|
||||||
assert "Error retrieving data from server" in caplog.text
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user