From 5f67e79ad9db4c7067d2c6cac261eb55cc7c2c56 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sat, 14 Jan 2023 02:25:22 +0100 Subject: [PATCH] Bump reolink-aio to 0.2.2 (#85848) --- homeassistant/components/reolink/__init__.py | 18 ++++++++++++++---- .../components/reolink/config_flow.py | 5 ++++- homeassistant/components/reolink/host.py | 9 ++++----- homeassistant/components/reolink/manifest.json | 4 ++-- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/reolink/test_config_flow.py | 8 ++++---- 7 files changed, 30 insertions(+), 18 deletions(-) diff --git a/homeassistant/components/reolink/__init__.py b/homeassistant/components/reolink/__init__.py index 6f7ab9d68b7..bd521d74777 100644 --- a/homeassistant/components/reolink/__init__.py +++ b/homeassistant/components/reolink/__init__.py @@ -9,13 +9,18 @@ import logging from aiohttp import ClientConnectorError import async_timeout -from reolink_aio.exceptions import ApiError, InvalidContentTypeError +from reolink_aio.exceptions import ( + ApiError, + InvalidContentTypeError, + NoDataError, + ReolinkError, +) from homeassistant.config_entries import ConfigEntry from homeassistant.const import EVENT_HOMEASSISTANT_STOP, Platform from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady -from homeassistant.helpers.update_coordinator import DataUpdateCoordinator +from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from .const import DOMAIN from .exceptions import UserNotAdmin @@ -53,6 +58,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b asyncio.TimeoutError, ApiError, InvalidContentTypeError, + NoDataError, ) as err: await host.stop() raise ConfigEntryNotReady( @@ -66,8 +72,12 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b async def async_device_config_update(): """Update the host state cache and renew the ONVIF-subscription.""" async with async_timeout.timeout(host.api.timeout): - # Login session is implicitly updated here - await host.update_states() + try: + await host.update_states() + except ReolinkError as err: + raise UpdateFailed( + f"Error updating Reolink {host.api.nvr_name}" + ) from err coordinator_device_config_update = DataUpdateCoordinator( hass, diff --git a/homeassistant/components/reolink/config_flow.py b/homeassistant/components/reolink/config_flow.py index 64b786da901..e8f1fe3abe9 100644 --- a/homeassistant/components/reolink/config_flow.py +++ b/homeassistant/components/reolink/config_flow.py @@ -5,7 +5,7 @@ from collections.abc import Mapping import logging from typing import Any -from reolink_aio.exceptions import ApiError, CredentialsInvalidError +from reolink_aio.exceptions import ApiError, CredentialsInvalidError, ReolinkError import voluptuous as vol from homeassistant import config_entries, exceptions @@ -108,6 +108,9 @@ class ReolinkFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): except ApiError as err: placeholders["error"] = str(err) errors[CONF_HOST] = "api_error" + except ReolinkError as err: + placeholders["error"] = str(err) + errors[CONF_HOST] = "cannot_connect" except Exception as err: # pylint: disable=broad-except _LOGGER.exception("Unexpected exception") placeholders["error"] = str(err) diff --git a/homeassistant/components/reolink/host.py b/homeassistant/components/reolink/host.py index 5c744f0c5fd..dcf1f5e526e 100644 --- a/homeassistant/components/reolink/host.py +++ b/homeassistant/components/reolink/host.py @@ -63,8 +63,7 @@ class ReolinkHost: """Connect to Reolink host.""" self._api.expire_session() - if not await self._api.get_host_data(): - return False + await self._api.get_host_data() if self._api.mac_address is None: return False @@ -123,9 +122,9 @@ class ReolinkHost: return True - async def update_states(self) -> bool: - """Call the API of the camera device to update the states.""" - return await self._api.get_states() + async def update_states(self) -> None: + """Call the API of the camera device to update the internal states.""" + await self._api.get_states() async def disconnect(self): """Disconnect from the API, so the connection will be released.""" diff --git a/homeassistant/components/reolink/manifest.json b/homeassistant/components/reolink/manifest.json index 6fb26ea60fe..b65400ad952 100644 --- a/homeassistant/components/reolink/manifest.json +++ b/homeassistant/components/reolink/manifest.json @@ -3,8 +3,8 @@ "name": "Reolink IP NVR/camera", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/reolink", - "requirements": ["reolink-aio==0.2.1"], + "requirements": ["reolink-aio==0.2.2"], "codeowners": ["@starkillerOG"], "iot_class": "local_polling", - "loggers": ["reolink-aio"] + "loggers": ["reolink_aio"] } diff --git a/requirements_all.txt b/requirements_all.txt index 128e96811bb..f5d8c9a6f3b 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2212,7 +2212,7 @@ regenmaschine==2022.11.0 renault-api==0.1.11 # homeassistant.components.reolink -reolink-aio==0.2.1 +reolink-aio==0.2.2 # homeassistant.components.python_script restrictedpython==6.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 0d45a5313ad..e3a8e3fa8b0 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1557,7 +1557,7 @@ regenmaschine==2022.11.0 renault-api==0.1.11 # homeassistant.components.reolink -reolink-aio==0.2.1 +reolink-aio==0.2.2 # homeassistant.components.python_script restrictedpython==6.0 diff --git a/tests/components/reolink/test_config_flow.py b/tests/components/reolink/test_config_flow.py index fc6672718b9..013c399d17b 100644 --- a/tests/components/reolink/test_config_flow.py +++ b/tests/components/reolink/test_config_flow.py @@ -3,7 +3,7 @@ import json from unittest.mock import AsyncMock, Mock, patch import pytest -from reolink_aio.exceptions import ApiError, CredentialsInvalidError +from reolink_aio.exceptions import ApiError, CredentialsInvalidError, ReolinkError from homeassistant import config_entries, data_entry_flow from homeassistant.components.reolink import const @@ -24,11 +24,11 @@ TEST_NVR_NAME = "test_reolink_name" TEST_USE_HTTPS = True -def get_mock_info(error=None, host_data_return=True, user_level="admin"): +def get_mock_info(error=None, user_level="admin"): """Return a mock gateway info instance.""" host_mock = Mock() if error is None: - host_mock.get_host_data = AsyncMock(return_value=host_data_return) + host_mock.get_host_data = AsyncMock(return_value=None) else: host_mock.get_host_data = AsyncMock(side_effect=error) host_mock.unsubscribe_all = AsyncMock(return_value=True) @@ -99,7 +99,7 @@ async def test_config_flow_errors(hass): assert result["step_id"] == "user" assert result["errors"] == {} - host_mock = get_mock_info(host_data_return=False) + host_mock = get_mock_info(error=ReolinkError("Test error")) with patch("homeassistant.components.reolink.host.Host", return_value=host_mock): result = await hass.config_entries.flow.async_configure( result["flow_id"],