1
0
mirror of https://github.com/home-assistant/core.git synced 2026-05-08 17:49:37 +01:00

Add exception translation to SFR box (#157756)

This commit is contained in:
epenet
2025-12-02 17:42:16 +01:00
committed by GitHub
parent f5b046ee7d
commit b2d4c9ecb4
5 changed files with 38 additions and 8 deletions
+9 -2
View File
@@ -28,9 +28,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: SFRConfigEntry) -> bool:
try:
await box.authenticate(username=username, password=password)
except SFRBoxAuthenticationError as err:
raise ConfigEntryAuthFailed from err
raise ConfigEntryAuthFailed(
translation_domain=DOMAIN,
translation_key="invalid_credentials",
) from err
except SFRBoxError as err:
raise ConfigEntryNotReady from err
raise ConfigEntryNotReady(
translation_domain=DOMAIN,
translation_key="unknown_error",
translation_placeholders={"error": str(err)},
) from err
platforms = PLATFORMS_WITH_AUTH
data = SFRRuntimeData(
+6 -1
View File
@@ -21,6 +21,7 @@ from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from .const import DOMAIN
from .coordinator import SFRConfigEntry
from .entity import SFREntity
@@ -44,7 +45,11 @@ def with_error_wrapping[**_P, _R](
try:
return await func(self, *args, **kwargs)
except SFRBoxError as err:
raise HomeAssistantError(err) from err
raise HomeAssistantError(
translation_domain=DOMAIN,
translation_key="unknown_error",
translation_placeholders={"error": str(err)},
) from err
return wrapper
@@ -16,6 +16,8 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
_SCAN_INTERVAL = timedelta(minutes=1)
@@ -63,5 +65,12 @@ class SFRDataUpdateCoordinator[_DataT](DataUpdateCoordinator[_DataT]):
if data := await self._method(self.box):
return data
except SFRBoxError as err:
raise UpdateFailed from err
raise UpdateFailed("No data received from SFR Box")
raise UpdateFailed(
translation_domain=DOMAIN,
translation_key="unknown_error",
translation_placeholders={"error": str(err)},
) from err
raise UpdateFailed(
translation_domain=DOMAIN,
translation_key="no_data",
)
@@ -50,9 +50,7 @@ rules:
comment: Should be possible
stale-devices: done
diagnostics: done
exception-translations:
status: todo
comment: not yet documented
exception-translations: done
icon-translations: done
reconfiguration-flow: done
dynamic-devices: done
@@ -123,5 +123,16 @@
}
}
}
},
"exceptions": {
"invalid_credentials": {
"message": "The provided credentials are invalid."
},
"no_data": {
"message": "No data received from the SFR box."
},
"unknown_error": {
"message": "An unknown error occurred while communicating with the SFR box: {error}"
}
}
}