mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Add translation to Tessie exceptions (#106525)
* Fix HomeAssistantError * Add error translations * Add cable error * remove underscore from fallback * Add more exceptions * Try again for name * Improve messages * Address review feedback
This commit is contained in:
parent
a5ab2dfb62
commit
ff0ba5361f
@ -53,7 +53,7 @@ class TessieEntity(CoordinatorEntity[TessieStateUpdateCoordinator]):
|
||||
return self.coordinator.data.get(key or self.key, default)
|
||||
|
||||
async def run(
|
||||
self, func: Callable[..., Awaitable[dict[str, bool | str]]], **kargs: Any
|
||||
self, func: Callable[..., Awaitable[dict[str, Any]]], **kargs: Any
|
||||
) -> None:
|
||||
"""Run a tessie_api function and handle exceptions."""
|
||||
try:
|
||||
@ -66,8 +66,13 @@ class TessieEntity(CoordinatorEntity[TessieStateUpdateCoordinator]):
|
||||
except ClientResponseError as e:
|
||||
raise HomeAssistantError from e
|
||||
if response["result"] is False:
|
||||
name: str = getattr(self, "name", self.entity_id)
|
||||
reason: str = response.get("reason", "unknown")
|
||||
raise HomeAssistantError(
|
||||
response.get("reason", "An unknown issue occurred")
|
||||
reason.replace("_", " "),
|
||||
translation_domain=DOMAIN,
|
||||
translation_key=reason.replace(" ", "_"),
|
||||
translation_placeholders={"name": name},
|
||||
)
|
||||
|
||||
def set(self, *args: Any) -> None:
|
||||
|
@ -389,6 +389,24 @@
|
||||
}
|
||||
},
|
||||
"exceptions": {
|
||||
"unknown": {
|
||||
"message": "An unknown issue occured changing {name}."
|
||||
},
|
||||
"not_supported": {
|
||||
"message": "{name} is not supported."
|
||||
},
|
||||
"cable_connected": {
|
||||
"message": "Charge cable is connected."
|
||||
},
|
||||
"already_active": {
|
||||
"message": "{name} is already active."
|
||||
},
|
||||
"already_inactive": {
|
||||
"message": "{name} is already inactive."
|
||||
},
|
||||
"incorrect_pin": {
|
||||
"message": "Incorrect pin for {name}."
|
||||
},
|
||||
"no_cable": {
|
||||
"message": "Insert cable to lock"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user