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
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,

View File

@ -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)

View File

@ -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."""

View File

@ -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"]
}

View File

@ -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

View File

@ -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

View File

@ -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"],