Skip to content

Commit

Permalink
Add second confirmation ping
Browse files Browse the repository at this point in the history
  • Loading branch information
peteS-UK committed Jan 13, 2025
1 parent 44f1947 commit b9aa3e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion custom_components/sonyavr/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"requirements": [
"asyncping3"
],
"version": "1.6.0b2"
"version": "1.6.0b4"
}
20 changes: 15 additions & 5 deletions custom_components/sonyavr/sonyavr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,16 +1115,26 @@ def __init__(self, hass, config_entry, host):
self._stop = False

async def start(self):
while await ping(self._host, timeout=4) and not self._stop:
while not self._stop:
if int(self._config_entry.options.get(CONF_PING_INTERVAL)) == 0:
# Disable the listener
_LOGGER.info("Ping Watcher disabled. Reload config to re-enable")
self._stop = True
break
# Ping succeeded - wait and retry
await asyncio.sleep(
int(self._config_entry.options.get(CONF_PING_INTERVAL, 60))
)
# Ping the AVR
_ping = await ping(self._host, timeout=4)
if not _ping:
# Pause and try again
await asyncio.sleep(2)
_ping = await ping(self._host, timeout=4)
if _ping:
# Ping succeeded - wait and retry
await asyncio.sleep(
int(self._config_entry.options.get(CONF_PING_INTERVAL, 60))
)
else:
# Both attempts failed, so break
break
# Ping failed, so wait until it succeeds again
if not self._stop:
_LOGGER.error(
Expand Down

0 comments on commit b9aa3e8

Please sign in to comment.