From 9daf2ee65d617055b7b17783a369e4b5f5fe4006 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sun, 31 Oct 2021 20:19:51 +0100 Subject: [PATCH] Fix Plugwise not updating config entry with discovery information (#58819) --- .../components/plugwise/config_flow.py | 2 +- tests/components/plugwise/test_config_flow.py | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/plugwise/config_flow.py b/homeassistant/components/plugwise/config_flow.py index 450388b6f42..1dbf4324590 100644 --- a/homeassistant/components/plugwise/config_flow.py +++ b/homeassistant/components/plugwise/config_flow.py @@ -109,7 +109,7 @@ class PlugwiseConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): # unique_id is needed here, to be able to determine whether the discovered device is known, or not. unique_id = self.discovery_info.get("hostname").split(".")[0] await self.async_set_unique_id(unique_id) - self._abort_if_unique_id_configured() + self._abort_if_unique_id_configured({CONF_HOST: self.discovery_info[CONF_HOST]}) if DEFAULT_USERNAME not in unique_id: self.discovery_info[CONF_USERNAME] = STRETCH_USERNAME diff --git a/tests/components/plugwise/test_config_flow.py b/tests/components/plugwise/test_config_flow.py index 75851f5c15a..7f270e23cc1 100644 --- a/tests/components/plugwise/test_config_flow.py +++ b/tests/components/plugwise/test_config_flow.py @@ -203,6 +203,29 @@ async def test_zeroconf_stretch_form(hass): assert len(mock_setup_entry.mock_calls) == 1 +async def test_zercoconf_discovery_update_configuration(hass): + """Test if a discovered device is configured and updated with new host.""" + entry = MockConfigEntry( + domain=DOMAIN, + title=CONF_NAME, + data={CONF_HOST: "0.0.0.0", CONF_PASSWORD: TEST_PASSWORD}, + unique_id=TEST_HOSTNAME, + ) + entry.add_to_hass(hass) + + assert entry.data[CONF_HOST] == "0.0.0.0" + + result = await hass.config_entries.flow.async_init( + DOMAIN, + context={CONF_SOURCE: SOURCE_ZEROCONF}, + data=TEST_DISCOVERY, + ) + + assert result["type"] == "abort" + assert result["reason"] == "already_configured" + assert entry.data[CONF_HOST] == "1.1.1.1" + + async def test_form_username(hass): """Test we get the username data back."""