diff --git a/homeassistant/components/konnected/config_flow.py b/homeassistant/components/konnected/config_flow.py index 6a3631a8c0d..a6b01560c50 100644 --- a/homeassistant/components/konnected/config_flow.py +++ b/homeassistant/components/konnected/config_flow.py @@ -283,11 +283,6 @@ class KonnectedFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): # build config info and wait for user confirmation self.data[CONF_HOST] = user_input[CONF_HOST] self.data[CONF_PORT] = user_input[CONF_PORT] - self.data[CONF_ACCESS_TOKEN] = self.hass.data.get(DOMAIN, {}).get( - CONF_ACCESS_TOKEN - ) or "".join( - random.choices(f"{string.ascii_uppercase}{string.digits}", k=20) - ) # brief delay to allow processing of recent status req await asyncio.sleep(0.1) @@ -343,8 +338,12 @@ class KonnectedFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): }, ) - # Attach default options and create entry + # Create access token, attach default options and create entry self.data[CONF_DEFAULT_OPTIONS] = self.options + self.data[CONF_ACCESS_TOKEN] = self.hass.data.get(DOMAIN, {}).get( + CONF_ACCESS_TOKEN + ) or "".join(random.choices(f"{string.ascii_uppercase}{string.digits}", k=20)) + return self.async_create_entry( title=KONN_PANEL_MODEL_NAMES[self.data[CONF_MODEL]], data=self.data, ) diff --git a/tests/components/konnected/test_config_flow.py b/tests/components/konnected/test_config_flow.py index 917afc5357a..0bf6e7846ae 100644 --- a/tests/components/konnected/test_config_flow.py +++ b/tests/components/konnected/test_config_flow.py @@ -362,10 +362,11 @@ async def test_ssdp_host_update(hass, mock_panel): ) assert result["type"] == "abort" - # confirm the host value was updated + # confirm the host value was updated, access_token was not entry = hass.config_entries.async_entries(config_flow.DOMAIN)[0] assert entry.data["host"] == "1.1.1.1" assert entry.data["port"] == 1234 + assert entry.data["access_token"] == "11223344556677889900" async def test_import_existing_config(hass, mock_panel): @@ -494,6 +495,7 @@ async def test_import_existing_config_entry(hass, mock_panel): data={ "host": "0.0.0.0", "port": 1111, + "access_token": "ORIGINALTOKEN", "id": "112233445566", "extra": "something", }, @@ -546,14 +548,14 @@ async def test_import_existing_config_entry(hass, mock_panel): assert result["type"] == "abort" - # We should have updated the entry + # We should have updated the host info but not the access token assert len(hass.config_entries.async_entries("konnected")) == 1 assert hass.config_entries.async_entries("konnected")[0].data == { "host": "1.2.3.4", "port": 1234, + "access_token": "ORIGINALTOKEN", "id": "112233445566", "model": "Konnected Pro", - "access_token": "SUPERSECRETTOKEN", "extra": "something", }