From faf1f229e1117090df69c0af526c1320f2e495c3 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Fri, 25 Mar 2022 21:10:04 +0100 Subject: [PATCH] Motion allow changing ip (#68589) Co-authored-by: J. Nick Koston --- .../components/motion_blinds/config_flow.py | 8 +++- .../components/motion_blinds/strings.json | 2 +- .../motion_blinds/translations/en.json | 2 +- .../motion_blinds/test_config_flow.py | 47 +++++++++++++++++++ 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/motion_blinds/config_flow.py b/homeassistant/components/motion_blinds/config_flow.py index 90ee92ccff3..d93a1abd865 100644 --- a/homeassistant/components/motion_blinds/config_flow.py +++ b/homeassistant/components/motion_blinds/config_flow.py @@ -138,7 +138,13 @@ class MotionBlindsFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): mac_address = motion_gateway.mac await self.async_set_unique_id(mac_address) - self._abort_if_unique_id_configured() + self._abort_if_unique_id_configured( + updates={ + CONF_HOST: self._host, + CONF_API_KEY: key, + CONF_INTERFACE: multicast_interface, + } + ) return self.async_create_entry( title=DEFAULT_GATEWAY_NAME, diff --git a/homeassistant/components/motion_blinds/strings.json b/homeassistant/components/motion_blinds/strings.json index e5c86c2a45e..627ae72ffe3 100644 --- a/homeassistant/components/motion_blinds/strings.json +++ b/homeassistant/components/motion_blinds/strings.json @@ -29,7 +29,7 @@ "invalid_interface": "Invalid network interface" }, "abort": { - "already_configured": "[%key:common::config_flow::abort::already_configured_device%]", + "already_configured": "[%key:common::config_flow::abort::already_configured_device%], connection settings are updated", "already_in_progress": "[%key:common::config_flow::abort::already_in_progress%]", "connection_error": "[%key:common::config_flow::error::cannot_connect%]" } diff --git a/homeassistant/components/motion_blinds/translations/en.json b/homeassistant/components/motion_blinds/translations/en.json index 8f0d21addce..5e111278a8d 100644 --- a/homeassistant/components/motion_blinds/translations/en.json +++ b/homeassistant/components/motion_blinds/translations/en.json @@ -1,7 +1,7 @@ { "config": { "abort": { - "already_configured": "Device is already configured", + "already_configured": "Device is already configured, connection settings are updated", "already_in_progress": "Configuration flow is already in progress", "connection_error": "Failed to connect" }, diff --git a/tests/components/motion_blinds/test_config_flow.py b/tests/components/motion_blinds/test_config_flow.py index b5e2f8fb717..77f5e242974 100644 --- a/tests/components/motion_blinds/test_config_flow.py +++ b/tests/components/motion_blinds/test_config_flow.py @@ -14,7 +14,9 @@ from tests.common import MockConfigEntry TEST_HOST = "1.2.3.4" TEST_HOST2 = "5.6.7.8" TEST_HOST_HA = "9.10.11.12" +TEST_HOST_ANY = "any" TEST_API_KEY = "12ab345c-d67e-8f" +TEST_API_KEY2 = "f8e76dc5-43ba-21" TEST_MAC = "ab:cd:ef:gh" TEST_MAC2 = "ij:kl:mn:op" TEST_DEVICE_LIST = {TEST_MAC: Mock()} @@ -76,6 +78,9 @@ def motion_blinds_connect_fixture(mock_get_source_ip): ), patch( "homeassistant.components.motion_blinds.gateway.MotionGateway.device_list", TEST_DEVICE_LIST, + ), patch( + "homeassistant.components.motion_blinds.gateway.MotionGateway.mac", + TEST_MAC, ), patch( "homeassistant.components.motion_blinds.config_flow.MotionDiscovery.discover", return_value=TEST_DISCOVERY_1, @@ -362,3 +367,45 @@ async def test_options_flow(hass): assert config_entry.options == { const.CONF_WAIT_FOR_PUSH: False, } + + +async def test_change_connection_settings(hass): + """Test changing connection settings by issuing a second user config flow.""" + config_entry = MockConfigEntry( + domain=const.DOMAIN, + unique_id=TEST_MAC, + data={ + CONF_HOST: TEST_HOST, + CONF_API_KEY: TEST_API_KEY, + const.CONF_INTERFACE: TEST_HOST_HA, + }, + title=DEFAULT_GATEWAY_NAME, + ) + config_entry.add_to_hass(hass) + + result = await hass.config_entries.flow.async_init( + const.DOMAIN, context={"source": config_entries.SOURCE_USER} + ) + + assert result["type"] == "form" + assert result["step_id"] == "user" + assert result["errors"] == {} + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + {CONF_HOST: TEST_HOST2}, + ) + + assert result["type"] == "form" + assert result["step_id"] == "connect" + assert result["errors"] == {} + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + {CONF_API_KEY: TEST_API_KEY2, const.CONF_INTERFACE: TEST_HOST_ANY}, + ) + + assert result["type"] == "abort" + assert config_entry.data[CONF_HOST] == TEST_HOST2 + assert config_entry.data[CONF_API_KEY] == TEST_API_KEY2 + assert config_entry.data[const.CONF_INTERFACE] == TEST_HOST_ANY