diff --git a/homeassistant/components/reolink/__init__.py b/homeassistant/components/reolink/__init__.py index c20aff637ec..56974d9ed83 100644 --- a/homeassistant/components/reolink/__init__.py +++ b/homeassistant/components/reolink/__init__.py @@ -9,14 +9,7 @@ import logging from aiohttp import ClientConnectorError import async_timeout -from reolink_aio.exceptions import ( - ApiError, - InvalidContentTypeError, - LoginError, - NoDataError, - ReolinkError, - UnexpectedDataError, -) +from reolink_aio.exceptions import CredentialsInvalidError, ReolinkError from homeassistant.config_entries import ConfigEntry from homeassistant.const import EVENT_HOMEASSISTANT_STOP, Platform @@ -48,17 +41,14 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b try: await host.async_init() - except UserNotAdmin as err: + except (UserNotAdmin, CredentialsInvalidError) as err: + await host.stop() raise ConfigEntryAuthFailed(err) from err except ( ClientConnectorError, asyncio.TimeoutError, - ApiError, - InvalidContentTypeError, - LoginError, - NoDataError, ReolinkException, - UnexpectedDataError, + ReolinkError, ) as err: await host.stop() raise ConfigEntryNotReady( diff --git a/homeassistant/components/reolink/host.py b/homeassistant/components/reolink/host.py index 3e0731ac8ce..582a52ae1ba 100644 --- a/homeassistant/components/reolink/host.py +++ b/homeassistant/components/reolink/host.py @@ -9,7 +9,7 @@ from typing import Any import aiohttp from aiohttp.web import Request from reolink_aio.api import Host -from reolink_aio.exceptions import ReolinkError +from reolink_aio.exceptions import ReolinkError, SubscriptionError from homeassistant.components import webhook from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME @@ -76,7 +76,6 @@ class ReolinkHost: raise ReolinkSetupException("Could not get mac address") if not self._api.is_admin: - await self.stop() raise UserNotAdmin( f"User '{self._api.username}' has authorization level " f"'{self._api.user_level}', only admin users can change camera settings" @@ -182,22 +181,19 @@ class ReolinkHost: ) return - if await self._api.subscribe(self._webhook_url): - _LOGGER.debug( - "Host %s: subscribed successfully to webhook %s", - self._api.host, - self._webhook_url, - ) - else: - raise ReolinkWebhookException( - f"Host {self._api.host}: webhook subscription failed" - ) + await self._api.subscribe(self._webhook_url) + + _LOGGER.debug( + "Host %s: subscribed successfully to webhook %s", + self._api.host, + self._webhook_url, + ) async def renew(self) -> None: """Renew the subscription of motion events (lease time is 15 minutes).""" try: await self._renew() - except ReolinkWebhookException as err: + except SubscriptionError as err: if not self._lost_subscription: self._lost_subscription = True _LOGGER.error( @@ -220,25 +216,33 @@ class ReolinkHost: return timer = self._api.renewtimer + _LOGGER.debug( + "Host %s:%s should renew subscription in: %i seconds", + self._api.host, + self._api.port, + timer, + ) if timer > SUBSCRIPTION_RENEW_THRESHOLD: return if timer > 0: - if await self._api.renew(): + try: + await self._api.renew() + except SubscriptionError as err: + _LOGGER.debug( + "Host %s: error renewing Reolink subscription, " + "trying to subscribe again: %s", + self._api.host, + err, + ) + else: _LOGGER.debug( "Host %s successfully renewed Reolink subscription", self._api.host ) return - _LOGGER.debug( - "Host %s: error renewing Reolink subscription, " - "trying to subscribe again", - self._api.host, - ) - if not await self._api.subscribe(self._webhook_url): - raise ReolinkWebhookException( - f"Host {self._api.host}: webhook re-subscription failed" - ) + await self._api.subscribe(self._webhook_url) + _LOGGER.debug( "Host %s: Reolink re-subscription successful after it was expired", self._api.host, diff --git a/homeassistant/components/reolink/manifest.json b/homeassistant/components/reolink/manifest.json index 3516241feec..ab944314054 100644 --- a/homeassistant/components/reolink/manifest.json +++ b/homeassistant/components/reolink/manifest.json @@ -3,7 +3,7 @@ "name": "Reolink IP NVR/camera", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/reolink", - "requirements": ["reolink-aio==0.3.1"], + "requirements": ["reolink-aio==0.3.2"], "dependencies": ["webhook"], "codeowners": ["@starkillerOG"], "iot_class": "local_polling", diff --git a/requirements_all.txt b/requirements_all.txt index 7c44269a097..f8abf9d975b 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2227,7 +2227,7 @@ regenmaschine==2022.11.0 renault-api==0.1.11 # homeassistant.components.reolink -reolink-aio==0.3.1 +reolink-aio==0.3.2 # homeassistant.components.python_script restrictedpython==6.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index e1a21fcf16d..18071e51a33 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1572,7 +1572,7 @@ regenmaschine==2022.11.0 renault-api==0.1.11 # homeassistant.components.reolink -reolink-aio==0.3.1 +reolink-aio==0.3.2 # homeassistant.components.python_script restrictedpython==6.0