mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Fix deconz SSDP updating Hassio discovery (#30153)
This commit is contained in:
parent
fdaaabf070
commit
d101d4449f
@ -161,7 +161,11 @@ class DeconzFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
|
||||
def _update_entry(self, entry, host, port, api_key=None):
|
||||
"""Update existing entry."""
|
||||
if entry.data[CONF_HOST] == host:
|
||||
if (
|
||||
entry.data[CONF_HOST] == host
|
||||
and entry.data[CONF_PORT] == port
|
||||
and (api_key is None or entry.data[CONF_API_KEY] == api_key)
|
||||
):
|
||||
return self.async_abort(reason="already_configured")
|
||||
|
||||
entry.data[CONF_HOST] = host
|
||||
@ -186,6 +190,8 @@ class DeconzFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
|
||||
for entry in self.hass.config_entries.async_entries(DOMAIN):
|
||||
if uuid == entry.data.get(CONF_UUID):
|
||||
if entry.source == "hassio":
|
||||
return self.async_abort(reason="already_configured")
|
||||
return self._update_entry(entry, parsed_url.hostname, parsed_url.port)
|
||||
|
||||
bridgeid = discovery_info[ssdp.ATTR_UPNP_SERIAL]
|
||||
|
@ -269,6 +269,39 @@ async def test_bridge_discovery_update_existing_entry(hass):
|
||||
assert entry.data[config_flow.CONF_HOST] == "mock-deconz"
|
||||
|
||||
|
||||
async def test_bridge_discovery_dont_update_existing_hassio_entry(hass):
|
||||
"""Test to ensure the SSDP discovery does not update an Hass.io entry."""
|
||||
entry = MockConfigEntry(
|
||||
domain=config_flow.DOMAIN,
|
||||
source="hassio",
|
||||
data={
|
||||
config_flow.CONF_HOST: "core-deconz",
|
||||
config_flow.CONF_BRIDGEID: "123ABC",
|
||||
config_flow.CONF_UUID: "456DEF",
|
||||
},
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
gateway = Mock()
|
||||
gateway.config_entry = entry
|
||||
hass.data[config_flow.DOMAIN] = {"123ABC": gateway}
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
config_flow.DOMAIN,
|
||||
data={
|
||||
ssdp.ATTR_SSDP_LOCATION: "http://mock-deconz/",
|
||||
ssdp.ATTR_UPNP_MANUFACTURER_URL: config_flow.DECONZ_MANUFACTURERURL,
|
||||
ssdp.ATTR_UPNP_SERIAL: "123ABC",
|
||||
ssdp.ATTR_UPNP_UDN: "uuid:456DEF",
|
||||
},
|
||||
context={"source": "ssdp"},
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "already_configured"
|
||||
assert entry.data[config_flow.CONF_HOST] == "core-deconz"
|
||||
|
||||
|
||||
async def test_create_entry(hass, aioclient_mock):
|
||||
"""Test that _create_entry work and that bridgeid can be requested."""
|
||||
aioclient_mock.get(
|
||||
|
Loading…
x
Reference in New Issue
Block a user