Use translated errors in Russound RIO (#129820)
This commit is contained in:
parent
9c8d8fef16
commit
0278735dbf
3 changed files with 23 additions and 3 deletions
|
@ -11,7 +11,7 @@ from homeassistant.const import CONF_HOST, CONF_PORT, Platform
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
|
||||
from .const import CONNECT_TIMEOUT, RUSSOUND_RIO_EXCEPTIONS
|
||||
from .const import CONNECT_TIMEOUT, DOMAIN, RUSSOUND_RIO_EXCEPTIONS
|
||||
|
||||
PLATFORMS = [Platform.MEDIA_PLAYER]
|
||||
|
||||
|
@ -43,7 +43,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: RussoundConfigEntry) ->
|
|||
async with asyncio.timeout(CONNECT_TIMEOUT):
|
||||
await client.connect()
|
||||
except RUSSOUND_RIO_EXCEPTIONS as err:
|
||||
raise ConfigEntryNotReady(f"Error while connecting to {host}:{port}") from err
|
||||
raise ConfigEntryNotReady(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="entry_cannot_connect",
|
||||
translation_placeholders={
|
||||
"host": host,
|
||||
"port": port,
|
||||
},
|
||||
) from err
|
||||
entry.runtime_data = client
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
|
|
|
@ -26,7 +26,12 @@ def command[_EntityT: RussoundBaseEntity, **_P](
|
|||
await func(self, *args, **kwargs)
|
||||
except RUSSOUND_RIO_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
|
||||
|
|
|
@ -33,5 +33,13 @@
|
|||
"title": "[%key:component::russound_rio::issues::deprecated_yaml_import_issue_cannot_connect::title%]",
|
||||
"description": "[%key:component::russound_rio::issues::deprecated_yaml_import_issue_cannot_connect::description%]"
|
||||
}
|
||||
},
|
||||
"exceptions": {
|
||||
"entry_cannot_connect": {
|
||||
"message": "Error while connecting to {host}:{port}"
|
||||
},
|
||||
"command_error": {
|
||||
"message": "Error executing {function_name} on entity {entity_id}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue