Skip to content

Commit 5f67e79

Browse files
authored
Bump reolink-aio to 0.2.2 (home-assistant#85848)
1 parent bca4624 commit 5f67e79

File tree

7 files changed

+30
-18
lines changed

7 files changed

+30
-18
lines changed

homeassistant/components/reolink/__init__.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@
99

1010
from aiohttp import ClientConnectorError
1111
import async_timeout
12-
from reolink_aio.exceptions import ApiError, InvalidContentTypeError
12+
from reolink_aio.exceptions import (
13+
ApiError,
14+
InvalidContentTypeError,
15+
NoDataError,
16+
ReolinkError,
17+
)
1318

1419
from homeassistant.config_entries import ConfigEntry
1520
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, Platform
1621
from homeassistant.core import HomeAssistant
1722
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
18-
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
23+
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
1924

2025
from .const import DOMAIN
2126
from .exceptions import UserNotAdmin
@@ -53,6 +58,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
5358
asyncio.TimeoutError,
5459
ApiError,
5560
InvalidContentTypeError,
61+
NoDataError,
5662
) as err:
5763
await host.stop()
5864
raise ConfigEntryNotReady(
@@ -66,8 +72,12 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
6672
async def async_device_config_update():
6773
"""Update the host state cache and renew the ONVIF-subscription."""
6874
async with async_timeout.timeout(host.api.timeout):
69-
# Login session is implicitly updated here
70-
await host.update_states()
75+
try:
76+
await host.update_states()
77+
except ReolinkError as err:
78+
raise UpdateFailed(
79+
f"Error updating Reolink {host.api.nvr_name}"
80+
) from err
7181

7282
coordinator_device_config_update = DataUpdateCoordinator(
7383
hass,

homeassistant/components/reolink/config_flow.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import logging
66
from typing import Any
77

8-
from reolink_aio.exceptions import ApiError, CredentialsInvalidError
8+
from reolink_aio.exceptions import ApiError, CredentialsInvalidError, ReolinkError
99
import voluptuous as vol
1010

1111
from homeassistant import config_entries, exceptions
@@ -108,6 +108,9 @@ async def async_step_user(
108108
except ApiError as err:
109109
placeholders["error"] = str(err)
110110
errors[CONF_HOST] = "api_error"
111+
except ReolinkError as err:
112+
placeholders["error"] = str(err)
113+
errors[CONF_HOST] = "cannot_connect"
111114
except Exception as err: # pylint: disable=broad-except
112115
_LOGGER.exception("Unexpected exception")
113116
placeholders["error"] = str(err)

homeassistant/components/reolink/host.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ async def async_init(self) -> bool:
6363
"""Connect to Reolink host."""
6464
self._api.expire_session()
6565

66-
if not await self._api.get_host_data():
67-
return False
66+
await self._api.get_host_data()
6867

6968
if self._api.mac_address is None:
7069
return False
@@ -123,9 +122,9 @@ async def async_init(self) -> bool:
123122

124123
return True
125124

126-
async def update_states(self) -> bool:
127-
"""Call the API of the camera device to update the states."""
128-
return await self._api.get_states()
125+
async def update_states(self) -> None:
126+
"""Call the API of the camera device to update the internal states."""
127+
await self._api.get_states()
129128

130129
async def disconnect(self):
131130
"""Disconnect from the API, so the connection will be released."""

homeassistant/components/reolink/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"name": "Reolink IP NVR/camera",
44
"config_flow": true,
55
"documentation": "https://www.home-assistant.io/integrations/reolink",
6-
"requirements": ["reolink-aio==0.2.1"],
6+
"requirements": ["reolink-aio==0.2.2"],
77
"codeowners": ["@starkillerOG"],
88
"iot_class": "local_polling",
9-
"loggers": ["reolink-aio"]
9+
"loggers": ["reolink_aio"]
1010
}

requirements_all.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2212,7 +2212,7 @@ regenmaschine==2022.11.0
22122212
renault-api==0.1.11
22132213

22142214
# homeassistant.components.reolink
2215-
reolink-aio==0.2.1
2215+
reolink-aio==0.2.2
22162216

22172217
# homeassistant.components.python_script
22182218
restrictedpython==6.0

requirements_test_all.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ regenmaschine==2022.11.0
15571557
renault-api==0.1.11
15581558

15591559
# homeassistant.components.reolink
1560-
reolink-aio==0.2.1
1560+
reolink-aio==0.2.2
15611561

15621562
# homeassistant.components.python_script
15631563
restrictedpython==6.0

tests/components/reolink/test_config_flow.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from unittest.mock import AsyncMock, Mock, patch
44

55
import pytest
6-
from reolink_aio.exceptions import ApiError, CredentialsInvalidError
6+
from reolink_aio.exceptions import ApiError, CredentialsInvalidError, ReolinkError
77

88
from homeassistant import config_entries, data_entry_flow
99
from homeassistant.components.reolink import const
@@ -24,11 +24,11 @@
2424
TEST_USE_HTTPS = True
2525

2626

27-
def get_mock_info(error=None, host_data_return=True, user_level="admin"):
27+
def get_mock_info(error=None, user_level="admin"):
2828
"""Return a mock gateway info instance."""
2929
host_mock = Mock()
3030
if error is None:
31-
host_mock.get_host_data = AsyncMock(return_value=host_data_return)
31+
host_mock.get_host_data = AsyncMock(return_value=None)
3232
else:
3333
host_mock.get_host_data = AsyncMock(side_effect=error)
3434
host_mock.unsubscribe_all = AsyncMock(return_value=True)
@@ -99,7 +99,7 @@ async def test_config_flow_errors(hass):
9999
assert result["step_id"] == "user"
100100
assert result["errors"] == {}
101101

102-
host_mock = get_mock_info(host_data_return=False)
102+
host_mock = get_mock_info(error=ReolinkError("Test error"))
103103
with patch("homeassistant.components.reolink.host.Host", return_value=host_mock):
104104
result = await hass.config_entries.flow.async_configure(
105105
result["flow_id"],

0 commit comments

Comments
 (0)