From 164fad112cea274ef7b349d57f9bd87ab94e63a6 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Sat, 21 Jan 2023 23:22:13 +0100 Subject: [PATCH] React on IP changes in devolo Home Network (#86195) --- .../devolo_home_network/config_flow.py | 4 ++- tests/components/devolo_home_network/const.py | 24 ++++++++++++++- .../devolo_home_network/test_config_flow.py | 30 +++++++++---------- 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/devolo_home_network/config_flow.py b/homeassistant/components/devolo_home_network/config_flow.py index 23ae1602d96..08892e19e4e 100644 --- a/homeassistant/components/devolo_home_network/config_flow.py +++ b/homeassistant/components/devolo_home_network/config_flow.py @@ -85,7 +85,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): return self.async_abort(reason="home_control") await self.async_set_unique_id(discovery_info.properties["SN"]) - self._abort_if_unique_id_configured() + self._abort_if_unique_id_configured( + updates={CONF_IP_ADDRESS: discovery_info.host} + ) self.context[CONF_HOST] = discovery_info.host self.context["title_placeholders"] = { diff --git a/tests/components/devolo_home_network/const.py b/tests/components/devolo_home_network/const.py index 1672c701e66..75e6a57e1d4 100644 --- a/tests/components/devolo_home_network/const.py +++ b/tests/components/devolo_home_network/const.py @@ -12,7 +12,8 @@ from devolo_plc_api.plcnet_api import LogicalNetwork from homeassistant.components.zeroconf import ZeroconfServiceInfo -IP = "1.1.1.1" +IP = "192.0.2.1" +IP_ALT = "192.0.2.2" CONNECTED_STATIONS = [ ConnectedStationInfo( @@ -47,6 +48,27 @@ DISCOVERY_INFO = ZeroconfServiceInfo( }, ) +DISCOVERY_INFO_CHANGED = ZeroconfServiceInfo( + host=IP_ALT, + addresses=[IP_ALT], + port=14791, + hostname="test.local.", + type="_dvl-deviceapi._tcp.local.", + name="dLAN pro 1200+ WiFi ac._dvl-deviceapi._tcp.local.", + properties={ + "Path": "abcdefghijkl/deviceapi", + "Version": "v0", + "Product": "dLAN pro 1200+ WiFi ac", + "Features": "reset,update,led,intmtg,wifi1", + "MT": "2730", + "SN": "1234567890", + "FirmwareVersion": "5.6.1", + "FirmwareDate": "2020-10-23", + "PS": "", + "PlcMacAddress": "AA:BB:CC:DD:EE:FF", + }, +) + DISCOVERY_INFO_WRONG_DEVICE = ZeroconfServiceInfo( host="mock_host", addresses=["mock_host"], diff --git a/tests/components/devolo_home_network/test_config_flow.py b/tests/components/devolo_home_network/test_config_flow.py index 0d35630407e..223f0a84204 100644 --- a/tests/components/devolo_home_network/test_config_flow.py +++ b/tests/components/devolo_home_network/test_config_flow.py @@ -19,9 +19,17 @@ from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType from . import configure_integration -from .const import DISCOVERY_INFO, DISCOVERY_INFO_WRONG_DEVICE, IP +from .const import ( + DISCOVERY_INFO, + DISCOVERY_INFO_CHANGED, + DISCOVERY_INFO_WRONG_DEVICE, + IP, + IP_ALT, +) from .mock import MockDevice +from tests.common import MockConfigEntry + async def test_form(hass: HomeAssistant, info: dict[str, Any]): """Test we get the form.""" @@ -132,20 +140,11 @@ async def test_abort_zeroconf_wrong_device(hass: HomeAssistant): @pytest.mark.usefixtures("info") async def test_abort_if_configued(hass: HomeAssistant): """Test we abort config flow if already configured.""" - result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": config_entries.SOURCE_USER} + serial_number = DISCOVERY_INFO.properties["SN"] + entry = MockConfigEntry( + domain=DOMAIN, unique_id=serial_number, data={CONF_IP_ADDRESS: IP} ) - with patch( - "homeassistant.components.devolo_home_network.async_setup_entry", - return_value=True, - ): - await hass.config_entries.flow.async_configure( - result["flow_id"], - { - CONF_IP_ADDRESS: IP, - }, - ) - await hass.async_block_till_done() + entry.add_to_hass(hass) # Abort on concurrent user flow result = await hass.config_entries.flow.async_init( @@ -165,10 +164,11 @@ async def test_abort_if_configued(hass: HomeAssistant): result3 = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_ZEROCONF}, - data=DISCOVERY_INFO, + data=DISCOVERY_INFO_CHANGED, ) assert result3["type"] == FlowResultType.ABORT assert result3["reason"] == "already_configured" + assert entry.data[CONF_IP_ADDRESS] == IP_ALT @pytest.mark.usefixtures("mock_device")