Improve error reporting in onvif in config flow (#91876)

This commit is contained in:
J. Nick Koston 2023-04-24 08:20:37 -05:00 committed by GitHub
parent 1c3e1d2e13
commit e25885b943
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 376 additions and 60 deletions

View file

@ -28,6 +28,7 @@ from homeassistant.helpers.network import NoURLAvailableError, get_url
from .const import DOMAIN, LOGGER
from .models import Event, PullPointManagerState, WebHookManagerState
from .parsers import PARSERS
from .util import stringify_onvif_error
# Topics in this list are ignored because we do not want to create
# entities for them.
@ -60,13 +61,6 @@ PULLPOINT_MESSAGE_LIMIT = 100
PULLPOINT_COOLDOWN_TIME = 0.75
def _stringify_onvif_error(error: Exception) -> str:
"""Stringify ONVIF error."""
if isinstance(error, Fault):
return error.message or str(error) or "Device sent empty error"
return str(error)
class EventManager:
"""ONVIF Event Manager."""
@ -349,7 +343,7 @@ class PullPointManager:
LOGGER.debug(
"%s: Device does not support PullPoint service or has too many subscriptions: %s",
self._name,
_stringify_onvif_error(err),
stringify_onvif_error(err),
)
return False
@ -447,7 +441,7 @@ class PullPointManager:
" This is normal if the device restarted: %s"
),
self._name,
_stringify_onvif_error(err),
stringify_onvif_error(err),
)
self._pullpoint_subscription = None
@ -483,7 +477,7 @@ class PullPointManager:
LOGGER.debug(
"%s: Failed to renew PullPoint subscription; %s",
self._name,
_stringify_onvif_error(err),
stringify_onvif_error(err),
)
return False
@ -522,7 +516,7 @@ class PullPointManager:
"%s: PullPoint subscription encountered a remote protocol error "
"(this is normal for some cameras): %s",
self._name,
_stringify_onvif_error(err),
stringify_onvif_error(err),
)
return True
except (XMLParseError, *SUBSCRIPTION_ERRORS) as err:
@ -531,7 +525,7 @@ class PullPointManager:
LOGGER.debug(
"%s: Failed to fetch PullPoint subscription messages: %s",
self._name,
_stringify_onvif_error(err),
stringify_onvif_error(err),
)
# Treat errors as if the camera restarted. Assume that the pullpoint
# subscription is no longer valid.
@ -694,7 +688,7 @@ class WebHookManager:
LOGGER.debug(
"%s: Device does not support notification service or too many subscriptions: %s",
self._name,
_stringify_onvif_error(err),
stringify_onvif_error(err),
)
return False
@ -735,7 +729,7 @@ class WebHookManager:
LOGGER.debug(
"%s: Failed to renew webhook subscription %s",
self._name,
_stringify_onvif_error(err),
stringify_onvif_error(err),
)
return False
@ -863,6 +857,6 @@ class WebHookManager:
" This is normal if the device restarted: %s"
),
self._name,
_stringify_onvif_error(err),
stringify_onvif_error(err),
)
self._webhook_subscription = None