Add 5x reconnect attempts on poll

This commit is contained in:
SupaFlav committed 2023-09-08 19:56:12 -04:00
1 parent c3afdcfe89
commit 3d8cf4b98f
1 file changed
+10
@@ -191,8 +191,18 @@ class PollingCoordinator(DataUpdateCoordinator):
async with async_timeout.timeout(30):
# Reconnect if not connected
max_retries = 5
for attempt in range(1,max_retries + 1):
try:
if not self.client.is_connected:
await self.client.connect()
break
except Exception as e:
if attempt == max_retries:
raise # pass exception on max_retries attempt
else:
self.logger.debug(f"Connect unsucessful (attempt {attempt}): {e}. Retrying...")
await asyncio.sleep(2)
# Attach notifier if needed
if not self.has_notifier: