mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Use translated exceptions for Cambridge Audio (#129177)
This commit is contained in:
parent
4b63829eef
commit
bb36dd3893
@ -13,7 +13,7 @@ from homeassistant.const import CONF_HOST, Platform
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
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]
|
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):
|
async with asyncio.timeout(CONNECT_TIMEOUT):
|
||||||
await client.connect()
|
await client.connect()
|
||||||
except STREAM_MAGIC_EXCEPTIONS as err:
|
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
|
entry.runtime_data = client
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
@ -26,7 +26,12 @@ def command[_EntityT: CambridgeAudioEntity, **_P](
|
|||||||
await func(self, *args, **kwargs)
|
await func(self, *args, **kwargs)
|
||||||
except STREAM_MAGIC_EXCEPTIONS as exc:
|
except STREAM_MAGIC_EXCEPTIONS as exc:
|
||||||
raise HomeAssistantError(
|
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
|
) from exc
|
||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
@ -52,6 +52,12 @@
|
|||||||
},
|
},
|
||||||
"preset_non_integer": {
|
"preset_non_integer": {
|
||||||
"message": "Preset must be an integer, got: {preset_id}"
|
"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…
x
Reference in New Issue
Block a user