Skip to content
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
11 changes: 5 additions & 6 deletions homeassistant/components/konnected/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,6 @@ async def async_step_user(self, user_input=None):
# 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)
Expand Down Expand Up @@ -343,8 +338,12 @@ async def async_step_confirm(self, user_input=None):
},
)

# 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,
)
Expand Down
8 changes: 5 additions & 3 deletions tests/components/konnected/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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",
}

Expand Down