Reolink onvif not supported fix (#99714)

* only subscibe to ONVIF if supported

* Catch NotSupportedError when ONVIF is not supported

* fix styling
This commit is contained in:
starkillerOG 2023-09-06 14:46:24 +02:00 committed by Bram Kragten
parent 98896834cd
commit 107ca83d42

View File

@ -10,7 +10,7 @@ import aiohttp
from aiohttp.web import Request from aiohttp.web import Request
from reolink_aio.api import Host from reolink_aio.api import Host
from reolink_aio.enums import SubType from reolink_aio.enums import SubType
from reolink_aio.exceptions import ReolinkError, SubscriptionError from reolink_aio.exceptions import NotSupportedError, ReolinkError, SubscriptionError
from homeassistant.components import webhook from homeassistant.components import webhook
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
@ -61,6 +61,7 @@ class ReolinkHost:
) )
self.webhook_id: str | None = None self.webhook_id: str | None = None
self._onvif_supported: bool = True
self._base_url: str = "" self._base_url: str = ""
self._webhook_url: str = "" self._webhook_url: str = ""
self._webhook_reachable: bool = False self._webhook_reachable: bool = False
@ -96,6 +97,8 @@ class ReolinkHost:
f"'{self._api.user_level}', only admin users can change camera settings" f"'{self._api.user_level}', only admin users can change camera settings"
) )
self._onvif_supported = self._api.supported(None, "ONVIF")
enable_rtsp = None enable_rtsp = None
enable_onvif = None enable_onvif = None
enable_rtmp = None enable_rtmp = None
@ -106,7 +109,7 @@ class ReolinkHost:
) )
enable_rtsp = True enable_rtsp = True
if not self._api.onvif_enabled: if not self._api.onvif_enabled and self._onvif_supported:
_LOGGER.debug( _LOGGER.debug(
"ONVIF is disabled on %s, trying to enable it", self._api.nvr_name "ONVIF is disabled on %s, trying to enable it", self._api.nvr_name
) )
@ -154,11 +157,18 @@ class ReolinkHost:
self._unique_id = format_mac(self._api.mac_address) self._unique_id = format_mac(self._api.mac_address)
if self._onvif_supported:
try:
await self.subscribe() await self.subscribe()
except NotSupportedError:
self._onvif_supported = False
self.unregister_webhook()
await self._api.unsubscribe()
else:
if self._api.supported(None, "initial_ONVIF_state"): if self._api.supported(None, "initial_ONVIF_state"):
_LOGGER.debug( _LOGGER.debug(
"Waiting for initial ONVIF state on webhook '%s'", self._webhook_url "Waiting for initial ONVIF state on webhook '%s'",
self._webhook_url,
) )
else: else:
_LOGGER.debug( _LOGGER.debug(
@ -169,6 +179,12 @@ class ReolinkHost:
self._cancel_onvif_check = async_call_later( self._cancel_onvif_check = async_call_later(
self._hass, FIRST_ONVIF_TIMEOUT, self._async_check_onvif self._hass, FIRST_ONVIF_TIMEOUT, self._async_check_onvif
) )
if not self._onvif_supported:
_LOGGER.debug(
"Camera model %s does not support ONVIF, using fast polling instead",
self._api.model,
)
await self._async_poll_all_motion()
if self._api.sw_version_update_required: if self._api.sw_version_update_required:
ir.async_create_issue( ir.async_create_issue(
@ -365,6 +381,9 @@ class ReolinkHost:
async def renew(self) -> None: async def renew(self) -> None:
"""Renew the subscription of motion events (lease time is 15 minutes).""" """Renew the subscription of motion events (lease time is 15 minutes)."""
if not self._onvif_supported:
return
try: try:
await self._renew(SubType.push) await self._renew(SubType.push)
if self._long_poll_task is not None: if self._long_poll_task is not None: