mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Mark onvif events as stale when the subscription renewal fails (#91567)
This commit is contained in:
parent
dccef1020c
commit
bba225abc5
@ -211,6 +211,12 @@ class EventManager:
|
|||||||
LOGGER.debug("%s: Switching to webhook for events", self.name)
|
LOGGER.debug("%s: Switching to webhook for events", self.name)
|
||||||
self.pullpoint_manager.async_pause()
|
self.pullpoint_manager.async_pause()
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def async_mark_events_stale(self) -> None:
|
||||||
|
"""Mark all events as stale when the subscriptions fail since we are out of sync."""
|
||||||
|
self._events.clear()
|
||||||
|
self.async_callback_listeners()
|
||||||
|
|
||||||
|
|
||||||
class PullPointManager:
|
class PullPointManager:
|
||||||
"""ONVIF PullPoint Manager.
|
"""ONVIF PullPoint Manager.
|
||||||
@ -316,7 +322,13 @@ class PullPointManager:
|
|||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
started = await self._async_create_pullpoint_subscription()
|
started = await self._async_create_pullpoint_subscription()
|
||||||
except RemoteProtocolError:
|
except RequestError:
|
||||||
|
#
|
||||||
|
# We should only need to retry on RemoteProtocolError but some cameras
|
||||||
|
# are flaky and sometimes do not respond to the Renew request so we
|
||||||
|
# retry on RequestError as well.
|
||||||
|
#
|
||||||
|
# For RemoteProtocolError:
|
||||||
# http://datatracker.ietf.org/doc/html/rfc2616#section-8.1.4 allows the server
|
# http://datatracker.ietf.org/doc/html/rfc2616#section-8.1.4 allows the server
|
||||||
# to close the connection at any time, we treat this as a normal and try again
|
# to close the connection at any time, we treat this as a normal and try again
|
||||||
# once since we do not want to declare the camera as not supporting PullPoint
|
# once since we do not want to declare the camera as not supporting PullPoint
|
||||||
@ -433,10 +445,24 @@ class PullPointManager:
|
|||||||
# The first time we renew, we may get a Fault error so we
|
# The first time we renew, we may get a Fault error so we
|
||||||
# suppress it. The subscription will be restarted in
|
# suppress it. The subscription will be restarted in
|
||||||
# async_restart later.
|
# async_restart later.
|
||||||
await self._pullpoint_subscription.Renew(SUBSCRIPTION_RELATIVE_TIME)
|
try:
|
||||||
|
await self._pullpoint_subscription.Renew(SUBSCRIPTION_RELATIVE_TIME)
|
||||||
|
except RequestError:
|
||||||
|
#
|
||||||
|
# We should only need to retry on RemoteProtocolError but some cameras
|
||||||
|
# are flaky and sometimes do not respond to the Renew request so we
|
||||||
|
# retry on RequestError as well.
|
||||||
|
#
|
||||||
|
# For RemoteProtocolError:
|
||||||
|
# http://datatracker.ietf.org/doc/html/rfc2616#section-8.1.4 allows the server
|
||||||
|
# to close the connection at any time, we treat this as a normal and try again
|
||||||
|
# once since we do not want to mark events as stale
|
||||||
|
# if it just happened to close the connection at the wrong time.
|
||||||
|
await self._pullpoint_subscription.Renew(SUBSCRIPTION_RELATIVE_TIME)
|
||||||
LOGGER.debug("%s: Renewed PullPoint subscription", self._name)
|
LOGGER.debug("%s: Renewed PullPoint subscription", self._name)
|
||||||
return True
|
return True
|
||||||
except RENEW_ERRORS as err:
|
except RENEW_ERRORS as err:
|
||||||
|
self._event_manager.async_mark_events_stale()
|
||||||
LOGGER.debug(
|
LOGGER.debug(
|
||||||
"%s: Failed to renew PullPoint subscription; %s",
|
"%s: Failed to renew PullPoint subscription; %s",
|
||||||
self._name,
|
self._name,
|
||||||
@ -634,7 +660,13 @@ class WebHookManager:
|
|||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
await self._async_create_webhook_subscription()
|
await self._async_create_webhook_subscription()
|
||||||
except RemoteProtocolError:
|
except RequestError:
|
||||||
|
#
|
||||||
|
# We should only need to retry on RemoteProtocolError but some cameras
|
||||||
|
# are flaky and sometimes do not respond to the Renew request so we
|
||||||
|
# retry on RequestError as well.
|
||||||
|
#
|
||||||
|
# For RemoteProtocolError:
|
||||||
# http://datatracker.ietf.org/doc/html/rfc2616#section-8.1.4 allows the server
|
# http://datatracker.ietf.org/doc/html/rfc2616#section-8.1.4 allows the server
|
||||||
# to close the connection at any time, we treat this as a normal and try again
|
# to close the connection at any time, we treat this as a normal and try again
|
||||||
# once since we do not want to declare the camera as not supporting webhooks
|
# once since we do not want to declare the camera as not supporting webhooks
|
||||||
@ -662,10 +694,24 @@ class WebHookManager:
|
|||||||
if not self._webhook_subscription:
|
if not self._webhook_subscription:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
await self._webhook_subscription.Renew(SUBSCRIPTION_RELATIVE_TIME)
|
try:
|
||||||
|
await self._webhook_subscription.Renew(SUBSCRIPTION_RELATIVE_TIME)
|
||||||
|
except RequestError:
|
||||||
|
#
|
||||||
|
# We should only need to retry on RemoteProtocolError but some cameras
|
||||||
|
# are flaky and sometimes do not respond to the Renew request so we
|
||||||
|
# retry on RequestError as well.
|
||||||
|
#
|
||||||
|
# For RemoteProtocolError:
|
||||||
|
# http://datatracker.ietf.org/doc/html/rfc2616#section-8.1.4 allows the server
|
||||||
|
# to close the connection at any time, we treat this as a normal and try again
|
||||||
|
# once since we do not want to mark events as stale
|
||||||
|
# if it just happened to close the connection at the wrong time.
|
||||||
|
await self._webhook_subscription.Renew(SUBSCRIPTION_RELATIVE_TIME)
|
||||||
LOGGER.debug("%s: Renewed Webhook subscription", self._name)
|
LOGGER.debug("%s: Renewed Webhook subscription", self._name)
|
||||||
return True
|
return True
|
||||||
except RENEW_ERRORS as err:
|
except RENEW_ERRORS as err:
|
||||||
|
self._event_manager.async_mark_events_stale()
|
||||||
LOGGER.debug(
|
LOGGER.debug(
|
||||||
"%s: Failed to renew webhook subscription %s",
|
"%s: Failed to renew webhook subscription %s",
|
||||||
self._name,
|
self._name,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user