Use translated exceptions for Cambridge Audio (#129177)
parent
4b63829eef
commit
bb36dd3893
|
@ -13,7 +13,7 @@ from homeassistant.const import CONF_HOST, Platform
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
|
||||
from .const import CONNECT_TIMEOUT, STREAM_MAGIC_EXCEPTIONS
|
||||
from .const import CONNECT_TIMEOUT, DOMAIN, STREAM_MAGIC_EXCEPTIONS
|
||||
|
||||
PLATFORMS: list[Platform] = [Platform.MEDIA_PLAYER, Platform.SELECT, Platform.SWITCH]
|
||||
|
||||
|
@ -45,7 +45,13 @@ async def async_setup_entry(
|
|||
async with asyncio.timeout(CONNECT_TIMEOUT):
|
||||
await client.connect()
|
||||
except STREAM_MAGIC_EXCEPTIONS as err:
|
||||
raise ConfigEntryNotReady(f"Error while connecting to {client.host}") from err
|
||||
raise ConfigEntryNotReady(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="entry_cannot_connect",
|
||||
translation_placeholders={
|
||||
"host": client.host,
|
||||
},
|
||||
) from err
|
||||
entry.runtime_data = client
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
|
|
|
@ -26,7 +26,12 @@ def command[_EntityT: CambridgeAudioEntity, **_P](
|
|||
await func(self, *args, **kwargs)
|
||||
except STREAM_MAGIC_EXCEPTIONS as exc:
|
||||
raise HomeAssistantError(
|
||||
f"Error executing {func.__name__} on entity {self.entity_id},"
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="command_error",
|
||||
translation_placeholders={
|
||||
"function_name": func.__name__,
|
||||
"entity_id": self.entity_id,
|
||||
},
|
||||
) from exc
|
||||
|
||||
return decorator
|
||||
|
|
|
@ -52,6 +52,12 @@
|
|||
},
|
||||
"preset_non_integer": {
|
||||
"message": "Preset must be an integer, got: {preset_id}"
|
||||
},
|
||||
"entry_cannot_connect": {
|
||||
"message": "Error while connecting to {host}"
|
||||
},
|
||||
"command_error": {
|
||||
"message": "Error executing {function_name} on entity {entity_id}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue