Skip to content

Commit

Permalink
Reolink long poll recover (home-assistant#97465)
Browse files Browse the repository at this point in the history
  • Loading branch information
starkillerOG authored Jul 30, 2023
1 parent 1f11ce6 commit c32b15c
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions homeassistant/components/reolink/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,19 @@ async def disconnect(self):
async def _async_start_long_polling(self):
"""Start ONVIF long polling task."""
if self._long_poll_task is None:
await self._api.subscribe(sub_type=SubType.long_poll)
try:
await self._api.subscribe(sub_type=SubType.long_poll)
except ReolinkError as err:
# make sure the long_poll_task is always created to try again later
if not self._lost_subscription:
self._lost_subscription = True
_LOGGER.error(
"Reolink %s event long polling subscription lost: %s",
self._api.nvr_name,
str(err),
)
else:
self._lost_subscription = False
self._long_poll_task = asyncio.create_task(self._async_long_polling())

async def _async_stop_long_polling(self):
Expand Down Expand Up @@ -319,7 +331,13 @@ async def renew(self) -> None:
try:
await self._renew(SubType.push)
if self._long_poll_task is not None:
await self._renew(SubType.long_poll)
if not self._api.subscribed(SubType.long_poll):
_LOGGER.debug("restarting long polling task")
# To prevent 5 minute request timeout
await self._async_stop_long_polling()
await self._async_start_long_polling()
else:
await self._renew(SubType.long_poll)
except SubscriptionError as err:
if not self._lost_subscription:
self._lost_subscription = True
Expand Down

0 comments on commit c32b15c

Please sign in to comment.