Handle failed updates in Tessie (#106450)
This commit is contained in:
parent
4b19c28ad9
commit
2fe982c7f3
3 changed files with 28 additions and 2 deletions
|
@ -56,7 +56,7 @@ class TessieEntity(CoordinatorEntity[TessieStateUpdateCoordinator]):
|
|||
) -> None:
|
||||
"""Run a tessie_api function and handle exceptions."""
|
||||
try:
|
||||
await func(
|
||||
response = await func(
|
||||
session=self.coordinator.session,
|
||||
vin=self.vin,
|
||||
api_key=self.coordinator.api_key,
|
||||
|
@ -64,6 +64,10 @@ class TessieEntity(CoordinatorEntity[TessieStateUpdateCoordinator]):
|
|||
)
|
||||
except ClientResponseError as e:
|
||||
raise HomeAssistantError from e
|
||||
if response["result"] is False:
|
||||
raise HomeAssistantError(
|
||||
response.get("reason"), "An unknown issue occurred"
|
||||
)
|
||||
|
||||
def set(self, *args: Any) -> None:
|
||||
"""Set a value in coordinator data."""
|
||||
|
|
|
@ -16,6 +16,7 @@ TEST_STATE_OF_ALL_VEHICLES = load_json_object_fixture("vehicles.json", DOMAIN)
|
|||
TEST_VEHICLE_STATE_ONLINE = load_json_object_fixture("online.json", DOMAIN)
|
||||
TEST_VEHICLE_STATE_ASLEEP = load_json_object_fixture("asleep.json", DOMAIN)
|
||||
TEST_RESPONSE = {"result": True}
|
||||
TEST_RESPONSE_ERROR = {"result": False, "reason": "reason why"}
|
||||
|
||||
TEST_CONFIG = {CONF_ACCESS_TOKEN: "1234567890"}
|
||||
TESSIE_URL = "https://api.tessie.com/"
|
||||
|
|
|
@ -14,7 +14,7 @@ from homeassistant.const import ATTR_ENTITY_ID
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
|
||||
from .common import ERROR_UNKNOWN, TEST_RESPONSE, setup_platform
|
||||
from .common import ERROR_UNKNOWN, TEST_RESPONSE, TEST_RESPONSE_ERROR, setup_platform
|
||||
|
||||
|
||||
async def test_window(hass: HomeAssistant) -> None:
|
||||
|
@ -110,3 +110,24 @@ async def test_errors(hass: HomeAssistant) -> None:
|
|||
)
|
||||
mock_set.assert_called_once()
|
||||
assert error.from_exception == ERROR_UNKNOWN
|
||||
|
||||
|
||||
async def test_response_error(hass: HomeAssistant) -> None:
|
||||
"""Tests response errors are handled."""
|
||||
|
||||
await setup_platform(hass)
|
||||
entity_id = "cover.test_charge_port_door"
|
||||
|
||||
# Test setting cover open with unknown error
|
||||
with patch(
|
||||
"homeassistant.components.tessie.cover.open_unlock_charge_port",
|
||||
return_value=TEST_RESPONSE_ERROR,
|
||||
) as mock_set, pytest.raises(HomeAssistantError) as error:
|
||||
await hass.services.async_call(
|
||||
COVER_DOMAIN,
|
||||
SERVICE_OPEN_COVER,
|
||||
{ATTR_ENTITY_ID: [entity_id]},
|
||||
blocking=True,
|
||||
)
|
||||
mock_set.assert_called_once()
|
||||
assert str(error) == TEST_RESPONSE_ERROR["reason"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue