mirror of
https://github.com/home-assistant/core.git
synced 2026-12-04 12:50:45 -04:00
Retry denonavr setup when the receiver is not fully identified (#193612)
This commit is contained in:
@@ -46,6 +46,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: DenonavrConfigEntry) -> None:
|
||||
"""Set up the denonavr components from a config entry."""
|
||||
use_telnet = entry.options.get(CONF_USE_TELNET, DEFAULT_USE_TELNET)
|
||||
# Connect to receiver
|
||||
connect_denonavr = ConnectDenonAVR(
|
||||
entry.data[CONF_HOST],
|
||||
@@ -53,20 +54,22 @@ async def async_setup_entry(hass: HomeAssistant, entry: DenonavrConfigEntry) ->
|
||||
entry.options.get(CONF_SHOW_ALL_SOURCES, DEFAULT_SHOW_SOURCES),
|
||||
entry.options.get(CONF_ZONE2, DEFAULT_ZONE2),
|
||||
entry.options.get(CONF_ZONE3, DEFAULT_ZONE3),
|
||||
entry.options.get(CONF_USE_TELNET, DEFAULT_USE_TELNET),
|
||||
use_telnet,
|
||||
entry.options.get(CONF_UPDATE_AUDYSSEY, DEFAULT_UPDATE_AUDYSSEY),
|
||||
lambda: get_async_client(hass),
|
||||
)
|
||||
try:
|
||||
await connect_denonavr.async_connect_receiver()
|
||||
connected = await connect_denonavr.async_connect_receiver()
|
||||
except AvrRequestError as ex:
|
||||
raise ConfigEntryNotReady from ex
|
||||
receiver = connect_denonavr.receiver
|
||||
if not connected:
|
||||
if use_telnet and receiver is not None:
|
||||
await receiver.async_telnet_disconnect()
|
||||
raise ConfigEntryNotReady("Receiver identification is incomplete")
|
||||
|
||||
entry.runtime_data = receiver
|
||||
|
||||
use_telnet = entry.options.get(CONF_USE_TELNET, DEFAULT_USE_TELNET)
|
||||
|
||||
async def _async_disconnect(event: Event) -> None:
|
||||
"""Disconnect from Telnet."""
|
||||
if use_telnet and receiver is not None:
|
||||
|
||||
@@ -177,6 +177,49 @@ async def test_setup_retry_on_request_error(
|
||||
assert entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"attribute", ["manufacturer", "name", "model_name", "receiver_type"]
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
("use_telnet", "disconnects"),
|
||||
[
|
||||
pytest.param(True, 1, id="telnet"),
|
||||
pytest.param(False, 0, id="no_telnet"),
|
||||
],
|
||||
)
|
||||
async def test_setup_retry_on_missing_receiver_info(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
client: MagicMock,
|
||||
attribute: str,
|
||||
use_telnet: bool,
|
||||
disconnects: int,
|
||||
) -> None:
|
||||
"""Test that a receiver missing identification retries the config entry."""
|
||||
setattr(client, attribute, None)
|
||||
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id=TEST_UNIQUE_ID,
|
||||
data={
|
||||
CONF_HOST: TEST_HOST,
|
||||
CONF_MODEL: TEST_MODEL,
|
||||
CONF_TYPE: TEST_RECEIVER_TYPE,
|
||||
CONF_MANUFACTURER: TEST_MANUFACTURER,
|
||||
CONF_SERIAL_NUMBER: TEST_SERIALNUMBER,
|
||||
},
|
||||
options={CONF_USE_TELNET: use_telnet},
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert entry.state is ConfigEntryState.SETUP_RETRY
|
||||
assert not er.async_entries_for_config_entry(entity_registry, entry.entry_id)
|
||||
assert client.async_telnet_disconnect.await_count == disconnects
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"exception",
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user