Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deconz SSDP updating Hassio config entry #30153

Merged
merged 1 commit into from
Dec 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion homeassistant/components/deconz/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ async def _create_entry(self):

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would updating the api key happen?

Copy link
Member Author

@frenck frenck Dec 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-install the add-on? Reset the gateway?
It is part of the discovery protocol from Hass.io, so it should handle that properly IMHO.

):
return self.async_abort(reason="already_configured")

entry.data[CONF_HOST] = host
Expand All @@ -186,6 +190,8 @@ async def async_step_ssdp(self, discovery_info):

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]
Expand Down
33 changes: 33 additions & 0 deletions tests/components/deconz/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down