Raise UpdateFailed when here_travel_time cannot find_location (#83157)
Fixes https://github.com/home-assistant/core/issues/83100 fixes undefinedpull/83482/head
parent
bb827a60ed
commit
75038d420c
|
@ -14,7 +14,7 @@ from homeassistant.const import ATTR_ATTRIBUTION, UnitOfLength
|
|||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.location import find_coordinates
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
from homeassistant.util import dt
|
||||
from homeassistant.util.unit_conversion import DistanceConverter
|
||||
|
||||
|
@ -215,13 +215,15 @@ def prepare_parameters(
|
|||
def _from_entity_id(entity_id: str) -> list[str]:
|
||||
coordinates = find_coordinates(hass, entity_id)
|
||||
if coordinates is None:
|
||||
raise InvalidCoordinatesException(f"No coordinates found for {entity_id}")
|
||||
raise UpdateFailed(f"No coordinates found for {entity_id}")
|
||||
if coordinates is entity_id:
|
||||
raise UpdateFailed(f"Could not find entity {entity_id}")
|
||||
try:
|
||||
formatted_coordinates = coordinates.split(",")
|
||||
vol.Schema(cv.gps(formatted_coordinates))
|
||||
except (AttributeError, vol.ExactSequenceInvalid) as ex:
|
||||
raise InvalidCoordinatesException(
|
||||
f"{coordinates} are not valid coordinates"
|
||||
raise UpdateFailed(
|
||||
f"{entity_id} does not have valid coordinates: {coordinates}"
|
||||
) from ex
|
||||
return formatted_coordinates
|
||||
|
||||
|
@ -275,7 +277,3 @@ def next_datetime(simple_time: time) -> datetime:
|
|||
if combined < datetime.now():
|
||||
combined = combined + timedelta(days=1)
|
||||
return combined
|
||||
|
||||
|
||||
class InvalidCoordinatesException(Exception):
|
||||
"""Coordinates for origin or destination are malformed."""
|
||||
|
|
|
@ -25,7 +25,7 @@ from homeassistant.core import HomeAssistant, callback
|
|||
from homeassistant.helpers.device_registry import DeviceEntryType
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.start import async_at_start
|
||||
from homeassistant.helpers.start import async_at_started
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import (
|
||||
|
@ -134,7 +134,7 @@ class HERETravelTimeSensor(CoordinatorEntity, RestoreSensor):
|
|||
async def _update_at_start(_):
|
||||
await self.async_update()
|
||||
|
||||
self.async_on_remove(async_at_start(self.hass, _update_at_start))
|
||||
self.async_on_remove(async_at_started(self.hass, _update_at_start))
|
||||
|
||||
@callback
|
||||
def _handle_coordinator_update(self) -> None:
|
||||
|
|
|
@ -330,7 +330,7 @@ async def test_destination_entity_not_found(hass: HomeAssistant, caplog):
|
|||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert "device_tracker.test are not valid coordinates" in caplog.text
|
||||
assert "Could not find entity device_tracker.test" in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("valid_response")
|
||||
|
@ -356,7 +356,7 @@ async def test_origin_entity_not_found(hass: HomeAssistant, caplog):
|
|||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert "device_tracker.test are not valid coordinates" in caplog.text
|
||||
assert "Could not find entity device_tracker.test" in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("valid_response")
|
||||
|
@ -386,7 +386,9 @@ async def test_invalid_destination_entity_state(hass: HomeAssistant, caplog):
|
|||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert "test_state are not valid coordinates" in caplog.text
|
||||
assert (
|
||||
"device_tracker.test does not have valid coordinates: test_state" in caplog.text
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("valid_response")
|
||||
|
@ -416,7 +418,9 @@ async def test_invalid_origin_entity_state(hass: HomeAssistant, caplog):
|
|||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert "test_state are not valid coordinates" in caplog.text
|
||||
assert (
|
||||
"device_tracker.test does not have valid coordinates: test_state" in caplog.text
|
||||
)
|
||||
|
||||
|
||||
async def test_route_not_found(hass: HomeAssistant, caplog):
|
||||
|
|
Loading…
Reference in New Issue