mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Add dict of translated errors to Tessie (#131346)
* Add dict of translated errors * Fix test
This commit is contained in:
parent
0d14005602
commit
fa1b7d73d5
@ -13,6 +13,16 @@ MODELS = {
|
||||
"models": "Model S",
|
||||
}
|
||||
|
||||
TRANSLATED_ERRORS = {
|
||||
"unknown": "unknown",
|
||||
"not supported": "not_supported",
|
||||
"cable connected": "cable_connected",
|
||||
"already active": "already_active",
|
||||
"already inactive": "already_inactive",
|
||||
"incorrect pin": "incorrect_pin",
|
||||
"no cable": "no_cable",
|
||||
}
|
||||
|
||||
|
||||
class TessieState(StrEnum):
|
||||
"""Tessie status."""
|
||||
|
@ -10,7 +10,7 @@ from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import DOMAIN
|
||||
from .const import DOMAIN, TRANSLATED_ERRORS
|
||||
from .coordinator import (
|
||||
TessieEnergySiteInfoCoordinator,
|
||||
TessieEnergySiteLiveCoordinator,
|
||||
@ -107,10 +107,11 @@ class TessieEntity(TessieBaseEntity):
|
||||
if response["result"] is False:
|
||||
name: str = getattr(self, "name", self.entity_id)
|
||||
reason: str = response.get("reason", "unknown")
|
||||
translation_key = TRANSLATED_ERRORS.get(reason, "command_failed")
|
||||
raise HomeAssistantError(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key=reason.replace(" ", "_"),
|
||||
translation_placeholders={"name": name},
|
||||
translation_key=translation_key,
|
||||
translation_placeholders={"name": name, "message": reason},
|
||||
)
|
||||
|
||||
def _async_update_attrs(self) -> None:
|
||||
|
@ -112,4 +112,4 @@ async def test_errors(hass: HomeAssistant) -> None:
|
||||
blocking=True,
|
||||
)
|
||||
mock_set.assert_called_once()
|
||||
assert str(error.value) == TEST_RESPONSE_ERROR["reason"]
|
||||
assert str(error.value) == f"Command failed, {TEST_RESPONSE_ERROR["reason"]}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user