mirror of
https://github.com/home-assistant/core.git
synced 2026-09-25 17:04:04 -04:00
Translate Onkyo setup exceptions (#182532)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
282725da9a
commit
918ef53bc9
@@ -53,9 +53,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: OnkyoConfigEntry) -> boo
|
||||
try:
|
||||
info = await async_interview(host)
|
||||
except TimeoutError as exc:
|
||||
raise ConfigEntryNotReady(f"Timed out interviewing: {host}") from exc
|
||||
raise ConfigEntryNotReady(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="interview_timeout",
|
||||
translation_placeholders={"host": host},
|
||||
) from exc
|
||||
except OSError as exc:
|
||||
raise ConfigEntryNotReady(f"Unexpected exception interviewing: {host}") from exc
|
||||
raise ConfigEntryNotReady(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="interview_error",
|
||||
translation_placeholders={"host": host},
|
||||
) from exc
|
||||
|
||||
manager = ReceiverManager(hass, entry, info)
|
||||
|
||||
@@ -75,7 +83,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: OnkyoConfigEntry) -> boo
|
||||
try:
|
||||
await error
|
||||
except OSError as exc:
|
||||
raise ConfigEntryNotReady(f"Unable to connect to: {host}") from exc
|
||||
raise ConfigEntryNotReady(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="cannot_connect",
|
||||
translation_placeholders={"host": host},
|
||||
) from exc
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ rules:
|
||||
entity-device-class: todo
|
||||
entity-disabled-by-default: done
|
||||
entity-translations: todo
|
||||
exception-translations: todo
|
||||
exception-translations: done
|
||||
icon-translations: todo
|
||||
reconfiguration-flow: done
|
||||
repair-issues: done
|
||||
|
||||
@@ -51,6 +51,15 @@
|
||||
}
|
||||
},
|
||||
"exceptions": {
|
||||
"cannot_connect": {
|
||||
"message": "Could not connect to the receiver at {host}."
|
||||
},
|
||||
"interview_error": {
|
||||
"message": "Unexpected error while interviewing the receiver at {host}."
|
||||
},
|
||||
"interview_timeout": {
|
||||
"message": "Timed out while interviewing the receiver at {host}."
|
||||
},
|
||||
"invalid_sound_mode": {
|
||||
"message": "Cannot select sound mode \"{invalid_sound_mode}\" for entity: {entity_id}."
|
||||
},
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
import asyncio
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from aioonkyo import Status
|
||||
from aioonkyo import ReceiverInfo, Status
|
||||
import pytest
|
||||
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import mock_discovery, setup_integration
|
||||
from . import RECEIVER_INFO, mock_discovery, setup_integration
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
@@ -31,22 +31,27 @@ async def test_load_unload_entry(
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"receiver_infos",
|
||||
("receiver_infos", "translation_key"),
|
||||
[
|
||||
None,
|
||||
[],
|
||||
pytest.param(None, "interview_error", id="interview_error"),
|
||||
pytest.param([], "interview_timeout", id="interview_timeout"),
|
||||
],
|
||||
)
|
||||
async def test_initialization_failure(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
receiver_infos,
|
||||
receiver_infos: list[ReceiverInfo] | None,
|
||||
translation_key: str,
|
||||
) -> None:
|
||||
"""Test initialization failure."""
|
||||
with mock_discovery(receiver_infos):
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||
assert mock_config_entry.error_reason_translation_key == translation_key
|
||||
assert mock_config_entry.error_reason_translation_placeholders == {
|
||||
"host": RECEIVER_INFO.host
|
||||
}
|
||||
|
||||
|
||||
async def test_connection_failure(
|
||||
@@ -60,6 +65,10 @@ async def test_connection_failure(
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||
assert mock_config_entry.error_reason_translation_key == "cannot_connect"
|
||||
assert mock_config_entry.error_reason_translation_placeholders == {
|
||||
"host": RECEIVER_INFO.host
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_receiver")
|
||||
|
||||
Reference in New Issue
Block a user