Skip to content

Commit b2d4c9e

Browse files
authored
Add exception translation to SFR box (home-assistant#157756)
1 parent f5b046e commit b2d4c9e

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

homeassistant/components/sfr_box/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: SFRConfigEntry) -> bool:
2828
try:
2929
await box.authenticate(username=username, password=password)
3030
except SFRBoxAuthenticationError as err:
31-
raise ConfigEntryAuthFailed from err
31+
raise ConfigEntryAuthFailed(
32+
translation_domain=DOMAIN,
33+
translation_key="invalid_credentials",
34+
) from err
3235
except SFRBoxError as err:
33-
raise ConfigEntryNotReady from err
36+
raise ConfigEntryNotReady(
37+
translation_domain=DOMAIN,
38+
translation_key="unknown_error",
39+
translation_placeholders={"error": str(err)},
40+
) from err
3441
platforms = PLATFORMS_WITH_AUTH
3542

3643
data = SFRRuntimeData(

homeassistant/components/sfr_box/button.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from homeassistant.exceptions import HomeAssistantError
2222
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
2323

24+
from .const import DOMAIN
2425
from .coordinator import SFRConfigEntry
2526
from .entity import SFREntity
2627

@@ -44,7 +45,11 @@ async def wrapper(
4445
try:
4546
return await func(self, *args, **kwargs)
4647
except SFRBoxError as err:
47-
raise HomeAssistantError(err) from err
48+
raise HomeAssistantError(
49+
translation_domain=DOMAIN,
50+
translation_key="unknown_error",
51+
translation_placeholders={"error": str(err)},
52+
) from err
4853

4954
return wrapper
5055

homeassistant/components/sfr_box/coordinator.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from homeassistant.core import HomeAssistant
1717
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
1818

19+
from .const import DOMAIN
20+
1921
_LOGGER = logging.getLogger(__name__)
2022
_SCAN_INTERVAL = timedelta(minutes=1)
2123

@@ -63,5 +65,12 @@ async def _async_update_data(self) -> _DataT:
6365
if data := await self._method(self.box):
6466
return data
6567
except SFRBoxError as err:
66-
raise UpdateFailed from err
67-
raise UpdateFailed("No data received from SFR Box")
68+
raise UpdateFailed(
69+
translation_domain=DOMAIN,
70+
translation_key="unknown_error",
71+
translation_placeholders={"error": str(err)},
72+
) from err
73+
raise UpdateFailed(
74+
translation_domain=DOMAIN,
75+
translation_key="no_data",
76+
)

homeassistant/components/sfr_box/quality_scale.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ rules:
5050
comment: Should be possible
5151
stale-devices: done
5252
diagnostics: done
53-
exception-translations:
54-
status: todo
55-
comment: not yet documented
53+
exception-translations: done
5654
icon-translations: done
5755
reconfiguration-flow: done
5856
dynamic-devices: done

homeassistant/components/sfr_box/strings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,16 @@
123123
}
124124
}
125125
}
126+
},
127+
"exceptions": {
128+
"invalid_credentials": {
129+
"message": "The provided credentials are invalid."
130+
},
131+
"no_data": {
132+
"message": "No data received from the SFR box."
133+
},
134+
"unknown_error": {
135+
"message": "An unknown error occurred while communicating with the SFR box: {error}"
136+
}
126137
}
127138
}

0 commit comments

Comments
 (0)