Bump reolink-aio to 0.2.2 (#85848)

pull/85798/head
starkillerOG 2023-01-14 02:25:22 +01:00 committed by GitHub
parent bca462401c
commit 5f67e79ad9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 18 deletions

View File

@ -9,13 +9,18 @@ import logging
from aiohttp import ClientConnectorError from aiohttp import ClientConnectorError
import async_timeout 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.config_entries import ConfigEntry
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, Platform from homeassistant.const import EVENT_HOMEASSISTANT_STOP, Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady 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 .const import DOMAIN
from .exceptions import UserNotAdmin from .exceptions import UserNotAdmin
@ -53,6 +58,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
asyncio.TimeoutError, asyncio.TimeoutError,
ApiError, ApiError,
InvalidContentTypeError, InvalidContentTypeError,
NoDataError,
) as err: ) as err:
await host.stop() await host.stop()
raise ConfigEntryNotReady( raise ConfigEntryNotReady(
@ -66,8 +72,12 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
async def async_device_config_update(): async def async_device_config_update():
"""Update the host state cache and renew the ONVIF-subscription.""" """Update the host state cache and renew the ONVIF-subscription."""
async with async_timeout.timeout(host.api.timeout): async with async_timeout.timeout(host.api.timeout):
# Login session is implicitly updated here try:
await host.update_states() 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( coordinator_device_config_update = DataUpdateCoordinator(
hass, hass,

View File

@ -5,7 +5,7 @@ from collections.abc import Mapping
import logging import logging
from typing import Any from typing import Any
from reolink_aio.exceptions import ApiError, CredentialsInvalidError from reolink_aio.exceptions import ApiError, CredentialsInvalidError, ReolinkError
import voluptuous as vol import voluptuous as vol
from homeassistant import config_entries, exceptions from homeassistant import config_entries, exceptions
@ -108,6 +108,9 @@ class ReolinkFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
except ApiError as err: except ApiError as err:
placeholders["error"] = str(err) placeholders["error"] = str(err)
errors[CONF_HOST] = "api_error" 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 except Exception as err: # pylint: disable=broad-except
_LOGGER.exception("Unexpected exception") _LOGGER.exception("Unexpected exception")
placeholders["error"] = str(err) placeholders["error"] = str(err)

View File

@ -63,8 +63,7 @@ class ReolinkHost:
"""Connect to Reolink host.""" """Connect to Reolink host."""
self._api.expire_session() self._api.expire_session()
if not await self._api.get_host_data(): await self._api.get_host_data()
return False
if self._api.mac_address is None: if self._api.mac_address is None:
return False return False
@ -123,9 +122,9 @@ class ReolinkHost:
return True return True
async def update_states(self) -> bool: async def update_states(self) -> None:
"""Call the API of the camera device to update the states.""" """Call the API of the camera device to update the internal states."""
return await self._api.get_states() await self._api.get_states()
async def disconnect(self): async def disconnect(self):
"""Disconnect from the API, so the connection will be released.""" """Disconnect from the API, so the connection will be released."""

View File

@ -3,8 +3,8 @@
"name": "Reolink IP NVR/camera", "name": "Reolink IP NVR/camera",
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/reolink", "documentation": "https://www.home-assistant.io/integrations/reolink",
"requirements": ["reolink-aio==0.2.1"], "requirements": ["reolink-aio==0.2.2"],
"codeowners": ["@starkillerOG"], "codeowners": ["@starkillerOG"],
"iot_class": "local_polling", "iot_class": "local_polling",
"loggers": ["reolink-aio"] "loggers": ["reolink_aio"]
} }

View File

@ -2212,7 +2212,7 @@ regenmaschine==2022.11.0
renault-api==0.1.11 renault-api==0.1.11
# homeassistant.components.reolink # homeassistant.components.reolink
reolink-aio==0.2.1 reolink-aio==0.2.2
# homeassistant.components.python_script # homeassistant.components.python_script
restrictedpython==6.0 restrictedpython==6.0

View File

@ -1557,7 +1557,7 @@ regenmaschine==2022.11.0
renault-api==0.1.11 renault-api==0.1.11
# homeassistant.components.reolink # homeassistant.components.reolink
reolink-aio==0.2.1 reolink-aio==0.2.2
# homeassistant.components.python_script # homeassistant.components.python_script
restrictedpython==6.0 restrictedpython==6.0

View File

@ -3,7 +3,7 @@ import json
from unittest.mock import AsyncMock, Mock, patch from unittest.mock import AsyncMock, Mock, patch
import pytest 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 import config_entries, data_entry_flow
from homeassistant.components.reolink import const from homeassistant.components.reolink import const
@ -24,11 +24,11 @@ TEST_NVR_NAME = "test_reolink_name"
TEST_USE_HTTPS = True 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.""" """Return a mock gateway info instance."""
host_mock = Mock() host_mock = Mock()
if error is None: 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: else:
host_mock.get_host_data = AsyncMock(side_effect=error) host_mock.get_host_data = AsyncMock(side_effect=error)
host_mock.unsubscribe_all = AsyncMock(return_value=True) 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["step_id"] == "user"
assert result["errors"] == {} 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): with patch("homeassistant.components.reolink.host.Host", return_value=host_mock):
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],