Fix zwave_js manual reconfiguration of add-on managed entry (#47364)

This commit is contained in:
Martin Hjelmare
2021-03-04 22:11:07 +01:00
committed by GitHub
parent cea4808db8
commit d64fe6ea32
2 changed files with 23 additions and 3 deletions

View File

@@ -117,7 +117,15 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
await self.async_set_unique_id( await self.async_set_unique_id(
version_info.home_id, raise_on_progress=False version_info.home_id, raise_on_progress=False
) )
self._abort_if_unique_id_configured(user_input) # Make sure we disable any add-on handling
# if the controller is reconfigured in a manual step.
self._abort_if_unique_id_configured(
updates={
**user_input,
CONF_USE_ADDON: False,
CONF_INTEGRATION_CREATED_ADDON: False,
}
)
self.ws_address = user_input[CONF_URL] self.ws_address = user_input[CONF_URL]
return self._async_create_entry_from_vars() return self._async_create_entry_from_vars()

View File

@@ -184,7 +184,16 @@ async def test_manual_errors(
async def test_manual_already_configured(hass): async def test_manual_already_configured(hass):
"""Test that only one unique instance is allowed.""" """Test that only one unique instance is allowed."""
entry = MockConfigEntry(domain=DOMAIN, data={}, title=TITLE, unique_id=1234) entry = MockConfigEntry(
domain=DOMAIN,
data={
"url": "ws://localhost:3000",
"use_addon": True,
"integration_created_addon": True,
},
title=TITLE,
unique_id=1234,
)
entry.add_to_hass(hass) entry.add_to_hass(hass)
await setup.async_setup_component(hass, "persistent_notification", {}) await setup.async_setup_component(hass, "persistent_notification", {})
@@ -198,12 +207,15 @@ async def test_manual_already_configured(hass):
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
{ {
"url": "ws://localhost:3000", "url": "ws://1.1.1.1:3001",
}, },
) )
assert result["type"] == "abort" assert result["type"] == "abort"
assert result["reason"] == "already_configured" assert result["reason"] == "already_configured"
assert entry.data["url"] == "ws://1.1.1.1:3001"
assert entry.data["use_addon"] is False
assert entry.data["integration_created_addon"] is False
@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) @pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}])