Fix Plugwise not updating config entry with discovery information (#58819)

pull/58845/head
Franck Nijhof 2021-10-31 20:19:51 +01:00 committed by GitHub
parent ccad6a8f07
commit 9daf2ee65d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -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

View File

@ -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."""