mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Add translations for exceptions (#138669)
* Add translations for exceptions * Review comment * Add translation for exception in the coordinator * Use same translation string for switch exceptions
This commit is contained in:
parent
9422c4de65
commit
82f2e72327
@ -25,6 +25,7 @@ from homeassistant.exceptions import HomeAssistantError
|
|||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
|
DOMAIN,
|
||||||
MAX_TEMP,
|
MAX_TEMP,
|
||||||
MIN_TEMP,
|
MIN_TEMP,
|
||||||
PRESET_TO_VENTILATION_MODE_MAP,
|
PRESET_TO_VENTILATION_MODE_MAP,
|
||||||
@ -133,7 +134,13 @@ class FlexitClimateEntity(FlexitEntity, ClimateEntity):
|
|||||||
try:
|
try:
|
||||||
await self.device.set_ventilation_mode(ventilation_mode)
|
await self.device.set_ventilation_mode(ventilation_mode)
|
||||||
except (asyncio.exceptions.TimeoutError, ConnectionError, DecodingError) as exc:
|
except (asyncio.exceptions.TimeoutError, ConnectionError, DecodingError) as exc:
|
||||||
raise HomeAssistantError from exc
|
raise HomeAssistantError(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="set_preset_mode",
|
||||||
|
translation_placeholders={
|
||||||
|
"preset": str(ventilation_mode),
|
||||||
|
},
|
||||||
|
) from exc
|
||||||
finally:
|
finally:
|
||||||
await self.coordinator.async_refresh()
|
await self.coordinator.async_refresh()
|
||||||
|
|
||||||
@ -153,6 +160,12 @@ class FlexitClimateEntity(FlexitEntity, ClimateEntity):
|
|||||||
else:
|
else:
|
||||||
await self.device.set_ventilation_mode(VENTILATION_MODE_HOME)
|
await self.device.set_ventilation_mode(VENTILATION_MODE_HOME)
|
||||||
except (asyncio.exceptions.TimeoutError, ConnectionError, DecodingError) as exc:
|
except (asyncio.exceptions.TimeoutError, ConnectionError, DecodingError) as exc:
|
||||||
raise HomeAssistantError from exc
|
raise HomeAssistantError(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="set_hvac_mode",
|
||||||
|
translation_placeholders={
|
||||||
|
"mode": str(hvac_mode),
|
||||||
|
},
|
||||||
|
) from exc
|
||||||
finally:
|
finally:
|
||||||
await self.coordinator.async_refresh()
|
await self.coordinator.async_refresh()
|
||||||
|
@ -49,7 +49,11 @@ class FlexitCoordinator(DataUpdateCoordinator[FlexitBACnet]):
|
|||||||
await self.device.update()
|
await self.device.update()
|
||||||
except (asyncio.exceptions.TimeoutError, ConnectionError, DecodingError) as exc:
|
except (asyncio.exceptions.TimeoutError, ConnectionError, DecodingError) as exc:
|
||||||
raise ConfigEntryNotReady(
|
raise ConfigEntryNotReady(
|
||||||
f"Timeout while connecting to {self.config_entry.data[CONF_IP_ADDRESS]}"
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="not_ready",
|
||||||
|
translation_placeholders={
|
||||||
|
"ip": str(self.config_entry.data[CONF_IP_ADDRESS]),
|
||||||
|
},
|
||||||
) from exc
|
) from exc
|
||||||
|
|
||||||
return self.device
|
return self.device
|
||||||
|
@ -18,6 +18,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
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 DOMAIN
|
||||||
from .coordinator import FlexitConfigEntry, FlexitCoordinator
|
from .coordinator import FlexitConfigEntry, FlexitCoordinator
|
||||||
from .entity import FlexitEntity
|
from .entity import FlexitEntity
|
||||||
|
|
||||||
@ -249,6 +250,12 @@ class FlexitNumber(FlexitEntity, NumberEntity):
|
|||||||
try:
|
try:
|
||||||
await set_native_value_fn(int(value))
|
await set_native_value_fn(int(value))
|
||||||
except (asyncio.exceptions.TimeoutError, ConnectionError, DecodingError) as exc:
|
except (asyncio.exceptions.TimeoutError, ConnectionError, DecodingError) as exc:
|
||||||
raise HomeAssistantError from exc
|
raise HomeAssistantError(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="set_value_error",
|
||||||
|
translation_placeholders={
|
||||||
|
"value": str(value),
|
||||||
|
},
|
||||||
|
) from exc
|
||||||
finally:
|
finally:
|
||||||
await self.coordinator.async_refresh()
|
await self.coordinator.async_refresh()
|
||||||
|
@ -62,7 +62,7 @@ rules:
|
|||||||
comment: |
|
comment: |
|
||||||
Device type integration.
|
Device type integration.
|
||||||
diagnostics: todo
|
diagnostics: todo
|
||||||
exception-translations: todo
|
exception-translations: done
|
||||||
icon-translations: done
|
icon-translations: done
|
||||||
reconfiguration-flow: todo
|
reconfiguration-flow: todo
|
||||||
dynamic-devices:
|
dynamic-devices:
|
||||||
|
@ -119,5 +119,22 @@
|
|||||||
"name": "Cooker hood mode"
|
"name": "Cooker hood mode"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"exceptions": {
|
||||||
|
"set_value_error": {
|
||||||
|
"message": "Failed setting the value {value}."
|
||||||
|
},
|
||||||
|
"switch_turn": {
|
||||||
|
"message": "Failed to turn the switch {state}."
|
||||||
|
},
|
||||||
|
"set_preset_mode": {
|
||||||
|
"message": "Failed to set preset mode {preset}."
|
||||||
|
},
|
||||||
|
"set_hvac_mode": {
|
||||||
|
"message": "Failed to set HVAC mode {mode}."
|
||||||
|
},
|
||||||
|
"not_ready": {
|
||||||
|
"message": "Timeout while connecting to {ip}."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
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 DOMAIN
|
||||||
from .coordinator import FlexitConfigEntry, FlexitCoordinator
|
from .coordinator import FlexitConfigEntry, FlexitCoordinator
|
||||||
from .entity import FlexitEntity
|
from .entity import FlexitEntity
|
||||||
|
|
||||||
@ -97,19 +98,31 @@ class FlexitSwitch(FlexitEntity, SwitchEntity):
|
|||||||
return self.entity_description.is_on_fn(self.coordinator.data)
|
return self.entity_description.is_on_fn(self.coordinator.data)
|
||||||
|
|
||||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn electric heater on."""
|
"""Turn switch on."""
|
||||||
try:
|
try:
|
||||||
await self.entity_description.turn_on_fn(self.coordinator.data)
|
await self.entity_description.turn_on_fn(self.coordinator.data)
|
||||||
except (asyncio.exceptions.TimeoutError, ConnectionError, DecodingError) as exc:
|
except (asyncio.exceptions.TimeoutError, ConnectionError, DecodingError) as exc:
|
||||||
raise HomeAssistantError from exc
|
raise HomeAssistantError(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="switch_turn",
|
||||||
|
translation_placeholders={
|
||||||
|
"state": "on",
|
||||||
|
},
|
||||||
|
) from exc
|
||||||
finally:
|
finally:
|
||||||
await self.coordinator.async_refresh()
|
await self.coordinator.async_refresh()
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Turn electric heater off."""
|
"""Turn switch off."""
|
||||||
try:
|
try:
|
||||||
await self.entity_description.turn_off_fn(self.coordinator.data)
|
await self.entity_description.turn_off_fn(self.coordinator.data)
|
||||||
except (asyncio.exceptions.TimeoutError, ConnectionError, DecodingError) as exc:
|
except (asyncio.exceptions.TimeoutError, ConnectionError, DecodingError) as exc:
|
||||||
raise HomeAssistantError from exc
|
raise HomeAssistantError(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="switch_turn",
|
||||||
|
translation_placeholders={
|
||||||
|
"state": "off",
|
||||||
|
},
|
||||||
|
) from exc
|
||||||
finally:
|
finally:
|
||||||
await self.coordinator.async_refresh()
|
await self.coordinator.async_refresh()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user