Skip to content

Commit

Permalink
fix: discovery error handling during reconnect
Browse files Browse the repository at this point in the history
If anything goes wrong during SSDP discovery and an exception is raised,
the reconnect task would be dead and the integration would no longer
connect to a device.
  • Loading branch information
zehnm committed Nov 15, 2023
1 parent ee997d7 commit b82223e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions intg-denonavr/avr.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ async def _handle_connection_failure(self, connect_duration: float, ex):
_LOG.info("IP address of '%s' changed: %s", self._name, item["host"])
self._receiver._host = item["host"] # pylint: disable=W0212 # seems to be the only way
self.events.emit(Events.IP_ADDRESS_CHANGED, self.id, self._receiver.host)
break
else:
await asyncio.sleep(backoff)

Expand Down
19 changes: 12 additions & 7 deletions intg-denonavr/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ async def denon_avrs() -> list[dict]:
"""
_LOG.debug("Starting discovery")

avrs = await denonavr.async_discover()
if not avrs:
_LOG.info("No AVRs discovered")
# extra safety, if anything goes wrong here the reconnection logic is dead
try:
avrs = await denonavr.async_discover()
if not avrs:
_LOG.info("No AVRs discovered")
return []

_LOG.info("Found AVR(s): %s", avrs)

return avrs
except Exception as ex: # pylint: disable=broad-exception-caught
_LOG.error("Failed to start discovery: %s", ex)
return []

_LOG.info("Found AVR(s): %s", avrs)

return avrs

0 comments on commit b82223e

Please sign in to comment.