Make exceptions translatable for SMLIGHT (#142587)

* Exceptions translations

* check off quality scale

* translate another exception
This commit is contained in:
TimL 2025-04-10 03:04:19 +10:00 committed by GitHub
parent ba629fbddb
commit 7f4d178781
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 22 additions and 4 deletions

View File

@ -111,7 +111,11 @@ class SmBaseDataUpdateCoordinator[_DataT](DataUpdateCoordinator[_DataT]):
raise ConfigEntryAuthFailed from err raise ConfigEntryAuthFailed from err
except SmlightConnectionError as err: except SmlightConnectionError as err:
raise UpdateFailed(err) from err raise UpdateFailed(
translation_domain=DOMAIN,
translation_key="cannot_connect_device",
translation_placeholders={"error": str(err)},
) from err
@abstractmethod @abstractmethod
async def _internal_update_data(self) -> _DataT: async def _internal_update_data(self) -> _DataT:

View File

@ -70,7 +70,7 @@ rules:
entity-device-class: done entity-device-class: done
entity-disabled-by-default: done entity-disabled-by-default: done
entity-translations: done entity-translations: done
exception-translations: todo exception-translations: done
icon-translations: done icon-translations: done
reconfiguration-flow: todo reconfiguration-flow: todo
repair-issues: done repair-issues: done

View File

@ -145,6 +145,14 @@
} }
} }
}, },
"exceptions": {
"firmware_update_failed": {
"message": "Firmware update failed for {device_name}."
},
"cannot_connect_device": {
"message": "An error occurred while connecting to the SMLIGHT device: {error}."
}
},
"issues": { "issues": {
"unsupported_firmware": { "unsupported_firmware": {
"title": "SLZB core firmware update required", "title": "SLZB core firmware update required",

View File

@ -22,7 +22,7 @@ from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from .const import LOGGER from .const import DOMAIN, LOGGER
from .coordinator import SmConfigEntry, SmFirmwareUpdateCoordinator, SmFwData from .coordinator import SmConfigEntry, SmFirmwareUpdateCoordinator, SmFwData
from .entity import SmEntity from .entity import SmEntity
@ -210,7 +210,13 @@ class SmUpdateEntity(SmEntity, UpdateEntity):
def _update_failed(self, event: MessageEvent) -> None: def _update_failed(self, event: MessageEvent) -> None:
self._update_done() self._update_done()
self.coordinator.in_progress = False self.coordinator.in_progress = False
raise HomeAssistantError(f"Update failed for {self.name}") raise HomeAssistantError(
translation_domain=DOMAIN,
translation_key="firmware_update_failed",
translation_placeholders={
"device_name": str(self.name),
},
)
async def async_install( async def async_install(
self, version: str | None, backup: bool, **kwargs: Any self, version: str | None, backup: bool, **kwargs: Any