Fix Reolink DHCP IP update (#103654)
This commit is contained in:
parent
2f26096469
commit
9f6eef7cca
3 changed files with 41 additions and 6 deletions
|
@ -2,7 +2,7 @@
|
|||
from datetime import timedelta
|
||||
import json
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock, MagicMock
|
||||
from unittest.mock import AsyncMock, MagicMock, call
|
||||
|
||||
import pytest
|
||||
from reolink_aio.exceptions import ApiError, CredentialsInvalidError, ReolinkError
|
||||
|
@ -12,6 +12,7 @@ from homeassistant.components import dhcp
|
|||
from homeassistant.components.reolink import DEVICE_UPDATE_INTERVAL, const
|
||||
from homeassistant.components.reolink.config_flow import DEFAULT_PROTOCOL
|
||||
from homeassistant.components.reolink.exceptions import ReolinkWebhookException
|
||||
from homeassistant.components.reolink.host import DEFAULT_TIMEOUT
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
@ -380,41 +381,47 @@ async def test_dhcp_flow(hass: HomeAssistant, mock_setup_entry: MagicMock) -> No
|
|||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("last_update_success", "attr", "value", "expected"),
|
||||
("last_update_success", "attr", "value", "expected", "host_call_list"),
|
||||
[
|
||||
(
|
||||
False,
|
||||
None,
|
||||
None,
|
||||
TEST_HOST2,
|
||||
[TEST_HOST, TEST_HOST2],
|
||||
),
|
||||
(
|
||||
True,
|
||||
None,
|
||||
None,
|
||||
TEST_HOST,
|
||||
[TEST_HOST],
|
||||
),
|
||||
(
|
||||
False,
|
||||
"get_state",
|
||||
AsyncMock(side_effect=ReolinkError("Test error")),
|
||||
TEST_HOST,
|
||||
[TEST_HOST, TEST_HOST2],
|
||||
),
|
||||
(
|
||||
False,
|
||||
"mac_address",
|
||||
"aa:aa:aa:aa:aa:aa",
|
||||
TEST_HOST,
|
||||
[TEST_HOST, TEST_HOST2],
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_dhcp_ip_update(
|
||||
hass: HomeAssistant,
|
||||
reolink_connect_class: MagicMock,
|
||||
reolink_connect: MagicMock,
|
||||
last_update_success: bool,
|
||||
attr: str,
|
||||
value: Any,
|
||||
expected: str,
|
||||
host_call_list: list[str],
|
||||
) -> None:
|
||||
"""Test dhcp discovery aborts if already configured where the IP is updated if appropriate."""
|
||||
config_entry = MockConfigEntry(
|
||||
|
@ -459,6 +466,22 @@ async def test_dhcp_ip_update(
|
|||
const.DOMAIN, context={"source": config_entries.SOURCE_DHCP}, data=dhcp_data
|
||||
)
|
||||
|
||||
expected_calls = []
|
||||
for host in host_call_list:
|
||||
expected_calls.append(
|
||||
call(
|
||||
host,
|
||||
TEST_USERNAME,
|
||||
TEST_PASSWORD,
|
||||
port=TEST_PORT,
|
||||
use_https=TEST_USE_HTTPS,
|
||||
protocol=DEFAULT_PROTOCOL,
|
||||
timeout=DEFAULT_TIMEOUT,
|
||||
)
|
||||
)
|
||||
|
||||
assert reolink_connect_class.call_args_list == expected_calls
|
||||
|
||||
assert result["type"] is data_entry_flow.FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue