mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Fix update port and api key on deconz discovery config entry u… (#30088)
* Fix update port and api key on discovery config entry update * Remove coroutine from _update_entry
This commit is contained in:
parent
3a610edb78
commit
eb0aed3653
@ -159,12 +159,17 @@ class DeconzFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
title="deCONZ-" + self.deconz_config[CONF_BRIDGEID], data=self.deconz_config
|
title="deCONZ-" + self.deconz_config[CONF_BRIDGEID], data=self.deconz_config
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _update_entry(self, entry, host):
|
def _update_entry(self, entry, host, port, api_key=None):
|
||||||
"""Update existing entry."""
|
"""Update existing entry."""
|
||||||
if entry.data[CONF_HOST] == host:
|
if entry.data[CONF_HOST] == host:
|
||||||
return self.async_abort(reason="already_configured")
|
return self.async_abort(reason="already_configured")
|
||||||
|
|
||||||
entry.data[CONF_HOST] = host
|
entry.data[CONF_HOST] = host
|
||||||
|
entry.data[CONF_PORT] = port
|
||||||
|
|
||||||
|
if api_key is not None:
|
||||||
|
entry.data[CONF_API_KEY] = api_key
|
||||||
|
|
||||||
self.hass.config_entries.async_update_entry(entry)
|
self.hass.config_entries.async_update_entry(entry)
|
||||||
return self.async_abort(reason="updated_instance")
|
return self.async_abort(reason="updated_instance")
|
||||||
|
|
||||||
@ -181,7 +186,7 @@ class DeconzFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
for entry in self.hass.config_entries.async_entries(DOMAIN):
|
for entry in self.hass.config_entries.async_entries(DOMAIN):
|
||||||
if uuid == entry.data.get(CONF_UUID):
|
if uuid == entry.data.get(CONF_UUID):
|
||||||
return await self._update_entry(entry, parsed_url.hostname)
|
return self._update_entry(entry, parsed_url.hostname, parsed_url.port)
|
||||||
|
|
||||||
bridgeid = discovery_info[ssdp.ATTR_UPNP_SERIAL]
|
bridgeid = discovery_info[ssdp.ATTR_UPNP_SERIAL]
|
||||||
if any(
|
if any(
|
||||||
@ -211,7 +216,12 @@ class DeconzFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
if bridgeid in gateway_entries:
|
if bridgeid in gateway_entries:
|
||||||
entry = gateway_entries[bridgeid]
|
entry = gateway_entries[bridgeid]
|
||||||
return await self._update_entry(entry, user_input[CONF_HOST])
|
return self._update_entry(
|
||||||
|
entry,
|
||||||
|
user_input[CONF_HOST],
|
||||||
|
user_input[CONF_PORT],
|
||||||
|
user_input[CONF_API_KEY],
|
||||||
|
)
|
||||||
|
|
||||||
self._hassio_discovery = user_input
|
self._hassio_discovery = user_input
|
||||||
|
|
||||||
|
@ -322,32 +322,53 @@ async def test_hassio_update_instance(hass):
|
|||||||
"""Test we can update an existing config entry."""
|
"""Test we can update an existing config entry."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=config_flow.DOMAIN,
|
domain=config_flow.DOMAIN,
|
||||||
data={config_flow.CONF_BRIDGEID: "id", config_flow.CONF_HOST: "1.2.3.4"},
|
data={
|
||||||
|
config_flow.CONF_BRIDGEID: "id",
|
||||||
|
config_flow.CONF_HOST: "1.2.3.4",
|
||||||
|
config_flow.CONF_PORT: 40850,
|
||||||
|
config_flow.CONF_API_KEY: "secret",
|
||||||
|
},
|
||||||
)
|
)
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
config_flow.DOMAIN,
|
config_flow.DOMAIN,
|
||||||
data={config_flow.CONF_HOST: "mock-deconz", config_flow.CONF_SERIAL: "id"},
|
data={
|
||||||
|
config_flow.CONF_HOST: "mock-deconz",
|
||||||
|
config_flow.CONF_PORT: 8080,
|
||||||
|
config_flow.CONF_API_KEY: "updated",
|
||||||
|
config_flow.CONF_SERIAL: "id",
|
||||||
|
},
|
||||||
context={"source": "hassio"},
|
context={"source": "hassio"},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "abort"
|
assert result["type"] == "abort"
|
||||||
assert result["reason"] == "updated_instance"
|
assert result["reason"] == "updated_instance"
|
||||||
assert entry.data[config_flow.CONF_HOST] == "mock-deconz"
|
assert entry.data[config_flow.CONF_HOST] == "mock-deconz"
|
||||||
|
assert entry.data[config_flow.CONF_PORT] == 8080
|
||||||
|
assert entry.data[config_flow.CONF_API_KEY] == "updated"
|
||||||
|
|
||||||
|
|
||||||
async def test_hassio_dont_update_instance(hass):
|
async def test_hassio_dont_update_instance(hass):
|
||||||
"""Test we can update an existing config entry."""
|
"""Test we can update an existing config entry."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=config_flow.DOMAIN,
|
domain=config_flow.DOMAIN,
|
||||||
data={config_flow.CONF_BRIDGEID: "id", config_flow.CONF_HOST: "1.2.3.4"},
|
data={
|
||||||
|
config_flow.CONF_BRIDGEID: "id",
|
||||||
|
config_flow.CONF_HOST: "1.2.3.4",
|
||||||
|
config_flow.CONF_PORT: 8080,
|
||||||
|
config_flow.CONF_API_KEY: "secret",
|
||||||
|
},
|
||||||
)
|
)
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
config_flow.DOMAIN,
|
config_flow.DOMAIN,
|
||||||
data={config_flow.CONF_HOST: "1.2.3.4", config_flow.CONF_SERIAL: "id"},
|
data={
|
||||||
|
config_flow.CONF_HOST: "1.2.3.4",
|
||||||
|
config_flow.CONF_PORT: 8080,
|
||||||
|
config_flow.CONF_API_KEY: "secret",
|
||||||
|
config_flow.CONF_SERIAL: "id",
|
||||||
|
},
|
||||||
context={"source": "hassio"},
|
context={"source": "hassio"},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user