Skip to content

Commit

Permalink
Reolink onvif not supported fix (#99714)
Browse files Browse the repository at this point in the history
* only subscibe to ONVIF if supported

* Catch NotSupportedError when ONVIF is not supported

* fix styling
  • Loading branch information
starkillerOG authored and bramkragten committed Sep 6, 2023
1 parent 9889683 commit 107ca83
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions homeassistant/components/reolink/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from aiohttp.web import Request
from reolink_aio.api import Host
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.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
Expand Down Expand Up @@ -61,6 +61,7 @@ def __init__(
)

self.webhook_id: str | None = None
self._onvif_supported: bool = True
self._base_url: str = ""
self._webhook_url: str = ""
self._webhook_reachable: bool = False
Expand Down Expand Up @@ -96,6 +97,8 @@ async def async_init(self) -> None:
f"'{self._api.user_level}', only admin users can change camera settings"
)

self._onvif_supported = self._api.supported(None, "ONVIF")

enable_rtsp = None
enable_onvif = None
enable_rtmp = None
Expand All @@ -106,7 +109,7 @@ async def async_init(self) -> None:
)
enable_rtsp = True

if not self._api.onvif_enabled:
if not self._api.onvif_enabled and self._onvif_supported:
_LOGGER.debug(
"ONVIF is disabled on %s, trying to enable it", self._api.nvr_name
)
Expand Down Expand Up @@ -154,21 +157,34 @@ async def async_init(self) -> None:

self._unique_id = format_mac(self._api.mac_address)

await self.subscribe()

if self._api.supported(None, "initial_ONVIF_state"):
_LOGGER.debug(
"Waiting for initial ONVIF state on webhook '%s'", self._webhook_url
)
else:
if self._onvif_supported:
try:
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"):
_LOGGER.debug(
"Waiting for initial ONVIF state on webhook '%s'",
self._webhook_url,
)
else:
_LOGGER.debug(
"Camera model %s most likely does not push its initial state"
" upon ONVIF subscription, do not check",
self._api.model,
)
self._cancel_onvif_check = async_call_later(
self._hass, FIRST_ONVIF_TIMEOUT, self._async_check_onvif
)
if not self._onvif_supported:
_LOGGER.debug(
"Camera model %s most likely does not push its initial state"
" upon ONVIF subscription, do not check",
"Camera model %s does not support ONVIF, using fast polling instead",
self._api.model,
)
self._cancel_onvif_check = async_call_later(
self._hass, FIRST_ONVIF_TIMEOUT, self._async_check_onvif
)
await self._async_poll_all_motion()

if self._api.sw_version_update_required:
ir.async_create_issue(
Expand Down Expand Up @@ -365,6 +381,9 @@ async def subscribe(self) -> None:

async def renew(self) -> None:
"""Renew the subscription of motion events (lease time is 15 minutes)."""
if not self._onvif_supported:
return

try:
await self._renew(SubType.push)
if self._long_poll_task is not None:
Expand Down

0 comments on commit 107ca83

Please sign in to comment.