mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Remove uneeded patch statements in here_travel_time (#72361)
This commit is contained in:
parent
5bb39a1db5
commit
9763b44357
@ -53,7 +53,6 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
import homeassistant.util.dt as dt_util
|
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
API_KEY,
|
API_KEY,
|
||||||
@ -264,62 +263,59 @@ async def test_no_attribution(hass: HomeAssistant):
|
|||||||
|
|
||||||
async def test_entity_ids(hass: HomeAssistant, valid_response: MagicMock):
|
async def test_entity_ids(hass: HomeAssistant, valid_response: MagicMock):
|
||||||
"""Test that origin/destination supplied by entities works."""
|
"""Test that origin/destination supplied by entities works."""
|
||||||
utcnow = dt_util.utcnow()
|
zone_config = {
|
||||||
# Patching 'utcnow' to gain more control over the timed update.
|
"zone": [
|
||||||
with patch("homeassistant.util.dt.utcnow", return_value=utcnow):
|
|
||||||
zone_config = {
|
|
||||||
"zone": [
|
|
||||||
{
|
|
||||||
"name": "Origin",
|
|
||||||
"latitude": CAR_ORIGIN_LATITUDE,
|
|
||||||
"longitude": CAR_ORIGIN_LONGITUDE,
|
|
||||||
"radius": 250,
|
|
||||||
"passive": False,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
assert await async_setup_component(hass, "zone", zone_config)
|
|
||||||
hass.states.async_set(
|
|
||||||
"device_tracker.test",
|
|
||||||
"not_home",
|
|
||||||
{
|
{
|
||||||
"latitude": float(CAR_DESTINATION_LATITUDE),
|
"name": "Origin",
|
||||||
"longitude": float(CAR_DESTINATION_LONGITUDE),
|
"latitude": CAR_ORIGIN_LATITUDE,
|
||||||
|
"longitude": CAR_ORIGIN_LONGITUDE,
|
||||||
|
"radius": 250,
|
||||||
|
"passive": False,
|
||||||
},
|
},
|
||||||
)
|
]
|
||||||
entry = MockConfigEntry(
|
}
|
||||||
domain=DOMAIN,
|
assert await async_setup_component(hass, "zone", zone_config)
|
||||||
unique_id="0123456789",
|
hass.states.async_set(
|
||||||
data={
|
"device_tracker.test",
|
||||||
CONF_ORIGIN_ENTITY_ID: "zone.origin",
|
"not_home",
|
||||||
CONF_DESTINATION_ENTITY_ID: "device_tracker.test",
|
{
|
||||||
CONF_API_KEY: API_KEY,
|
"latitude": float(CAR_DESTINATION_LATITUDE),
|
||||||
CONF_MODE: TRAVEL_MODE_TRUCK,
|
"longitude": float(CAR_DESTINATION_LONGITUDE),
|
||||||
CONF_NAME: "test",
|
},
|
||||||
},
|
)
|
||||||
)
|
entry = MockConfigEntry(
|
||||||
entry.add_to_hass(hass)
|
domain=DOMAIN,
|
||||||
await hass.config_entries.async_setup(entry.entry_id)
|
unique_id="0123456789",
|
||||||
await hass.async_block_till_done()
|
data={
|
||||||
|
CONF_ORIGIN_ENTITY_ID: "zone.origin",
|
||||||
|
CONF_DESTINATION_ENTITY_ID: "device_tracker.test",
|
||||||
|
CONF_API_KEY: API_KEY,
|
||||||
|
CONF_MODE: TRAVEL_MODE_TRUCK,
|
||||||
|
CONF_NAME: "test",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
sensor = hass.states.get("sensor.test")
|
sensor = hass.states.get("sensor.test")
|
||||||
assert sensor.attributes.get(ATTR_DISTANCE) == 23.903
|
assert sensor.attributes.get(ATTR_DISTANCE) == 23.903
|
||||||
|
|
||||||
valid_response.assert_called_with(
|
valid_response.assert_called_with(
|
||||||
[CAR_ORIGIN_LATITUDE, CAR_ORIGIN_LONGITUDE],
|
[CAR_ORIGIN_LATITUDE, CAR_ORIGIN_LONGITUDE],
|
||||||
[CAR_DESTINATION_LATITUDE, CAR_DESTINATION_LONGITUDE],
|
[CAR_DESTINATION_LATITUDE, CAR_DESTINATION_LONGITUDE],
|
||||||
True,
|
True,
|
||||||
[
|
[
|
||||||
RouteMode[ROUTE_MODE_FASTEST],
|
RouteMode[ROUTE_MODE_FASTEST],
|
||||||
RouteMode[TRAVEL_MODE_TRUCK],
|
RouteMode[TRAVEL_MODE_TRUCK],
|
||||||
RouteMode[TRAFFIC_MODE_ENABLED],
|
RouteMode[TRAFFIC_MODE_ENABLED],
|
||||||
],
|
],
|
||||||
arrival=None,
|
arrival=None,
|
||||||
departure="now",
|
departure="now",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("valid_response")
|
@pytest.mark.usefixtures("valid_response")
|
||||||
@ -433,9 +429,6 @@ async def test_invalid_origin_entity_state(hass: HomeAssistant, caplog):
|
|||||||
async def test_route_not_found(hass: HomeAssistant, caplog):
|
async def test_route_not_found(hass: HomeAssistant, caplog):
|
||||||
"""Test that route not found error is correctly handled."""
|
"""Test that route not found error is correctly handled."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.here_travel_time.config_flow.validate_api_key",
|
|
||||||
return_value=None,
|
|
||||||
), patch(
|
|
||||||
"herepy.RoutingApi.public_transport_timetable",
|
"herepy.RoutingApi.public_transport_timetable",
|
||||||
side_effect=NoRouteFoundError,
|
side_effect=NoRouteFoundError,
|
||||||
):
|
):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user