mirror of
https://github.com/home-assistant/core.git
synced 2026-05-04 11:54:35 +02:00
Improve interview logging in Onkyo (#153095)
This commit is contained in:
@@ -52,10 +52,10 @@ 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
|
||||
except OSError as exc:
|
||||
raise ConfigEntryNotReady(f"Unable to connect to: {host}") from exc
|
||||
if info is None:
|
||||
raise ConfigEntryNotReady(f"Unable to connect to: {host}")
|
||||
raise ConfigEntryNotReady(f"Unexpected exception interviewing: {host}") from exc
|
||||
|
||||
manager = ReceiverManager(hass, entry, info)
|
||||
|
||||
|
||||
@@ -109,24 +109,22 @@ class OnkyoConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
_LOGGER.debug("Config flow manual: %s", host)
|
||||
try:
|
||||
info = await async_interview(host)
|
||||
except TimeoutError:
|
||||
_LOGGER.warning("Timed out interviewing: %s", host)
|
||||
errors["base"] = "cannot_connect"
|
||||
except OSError:
|
||||
_LOGGER.exception("Unexpected exception")
|
||||
_LOGGER.exception("Unexpected exception interviewing: %s", host)
|
||||
errors["base"] = "unknown"
|
||||
else:
|
||||
if info is None:
|
||||
errors["base"] = "cannot_connect"
|
||||
self._receiver_info = info
|
||||
|
||||
await self.async_set_unique_id(info.identifier, raise_on_progress=False)
|
||||
if self.source == SOURCE_RECONFIGURE:
|
||||
self._abort_if_unique_id_mismatch()
|
||||
else:
|
||||
self._receiver_info = info
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
await self.async_set_unique_id(
|
||||
info.identifier, raise_on_progress=False
|
||||
)
|
||||
if self.source == SOURCE_RECONFIGURE:
|
||||
self._abort_if_unique_id_mismatch()
|
||||
else:
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
return await self.async_step_configure_receiver()
|
||||
return await self.async_step_configure_receiver()
|
||||
|
||||
suggested_values = user_input
|
||||
if suggested_values is None and self.source == SOURCE_RECONFIGURE:
|
||||
@@ -214,13 +212,12 @@ class OnkyoConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
try:
|
||||
info = await async_interview(host)
|
||||
except OSError:
|
||||
_LOGGER.exception("Unexpected exception interviewing host %s", host)
|
||||
return self.async_abort(reason="unknown")
|
||||
|
||||
if info is None:
|
||||
_LOGGER.debug("SSDP eiscp is None: %s", host)
|
||||
except TimeoutError:
|
||||
_LOGGER.warning("Timed out interviewing: %s", host)
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
except OSError:
|
||||
_LOGGER.exception("Unexpected exception interviewing: %s", host)
|
||||
return self.async_abort(reason="unknown")
|
||||
|
||||
await self.async_set_unique_id(info.identifier)
|
||||
self._abort_if_unique_id_configured(updates={CONF_HOST: info.host})
|
||||
|
||||
@@ -124,13 +124,10 @@ class ReceiverManager:
|
||||
self.callbacks.clear()
|
||||
|
||||
|
||||
async def async_interview(host: str) -> ReceiverInfo | None:
|
||||
async def async_interview(host: str) -> ReceiverInfo:
|
||||
"""Interview the receiver."""
|
||||
info: ReceiverInfo | None = None
|
||||
with contextlib.suppress(asyncio.TimeoutError):
|
||||
async with asyncio.timeout(DEVICE_INTERVIEW_TIMEOUT):
|
||||
info = await aioonkyo.interview(host)
|
||||
return info
|
||||
async with asyncio.timeout(DEVICE_INTERVIEW_TIMEOUT):
|
||||
return await aioonkyo.interview(host)
|
||||
|
||||
|
||||
async def async_discover(hass: HomeAssistant) -> Iterable[ReceiverInfo]:
|
||||
|
||||
@@ -29,12 +29,12 @@ RECEIVER_INFO_2 = ReceiverInfo(
|
||||
def mock_discovery(receiver_infos: Iterable[ReceiverInfo] | None) -> Generator[None]:
|
||||
"""Mock discovery functions."""
|
||||
|
||||
async def get_info(host: str) -> ReceiverInfo | None:
|
||||
async def get_info(host: str) -> ReceiverInfo:
|
||||
"""Get receiver info by host."""
|
||||
for info in receiver_infos:
|
||||
if info.host == host:
|
||||
return info
|
||||
return None
|
||||
raise TimeoutError
|
||||
|
||||
def get_infos(host: str) -> MagicMock:
|
||||
"""Get receiver infos from broadcast."""
|
||||
|
||||
Reference in New Issue
Block a user