Skip to content

Commit 5299690

Browse files
authored
Portainer expand reconfigure check (home-assistant#155544)
1 parent 98c1dca commit 5299690

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

homeassistant/components/portainer/config_flow.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ async def async_step_reconfigure(
159159
_LOGGER.exception("Unexpected exception")
160160
errors["base"] = "unknown"
161161
else:
162+
await self.async_set_unique_id(user_input[CONF_API_TOKEN])
163+
self._abort_if_unique_id_configured()
162164
return self.async_update_reload_and_abort(
163165
reconf_entry,
164166
data_updates={

tests/components/portainer/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def mock_config_entry() -> MockConfigEntry:
7373
domain=DOMAIN,
7474
title="Portainer test",
7575
data=MOCK_TEST_CONFIG,
76+
unique_id=MOCK_TEST_CONFIG[CONF_API_TOKEN],
7677
entry_id="portainer_test_entry_123",
7778
version=2,
7879
)

tests/components/portainer/snapshots/test_diagnostics.ambr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
'subentries': list([
2222
]),
2323
'title': 'Portainer test',
24-
'unique_id': None,
24+
'unique_id': 'test_api_token',
2525
'version': 2,
2626
}),
2727
'coordinator': dict({

tests/components/portainer/test_config_flow.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,31 @@ async def test_full_flow_reconfigure(
255255
assert len(mock_setup_entry.mock_calls) == 1
256256

257257

258+
async def test_full_flow_reconfigure_unique_id(
259+
hass: HomeAssistant,
260+
mock_portainer_client: AsyncMock,
261+
mock_setup_entry: MagicMock,
262+
mock_config_entry: MockConfigEntry,
263+
) -> None:
264+
"""Test the full flow of the config flow, this time with a known unique ID."""
265+
mock_config_entry.add_to_hass(hass)
266+
result = await mock_config_entry.start_reconfigure_flow(hass)
267+
assert result["type"] is FlowResultType.FORM
268+
assert result["step_id"] == "reconfigure"
269+
270+
result = await hass.config_entries.flow.async_configure(
271+
result["flow_id"],
272+
user_input=MOCK_USER_SETUP,
273+
)
274+
275+
assert result["type"] is FlowResultType.ABORT
276+
assert result["reason"] == "already_configured"
277+
assert mock_config_entry.data[CONF_API_TOKEN] == "test_api_token"
278+
assert mock_config_entry.data[CONF_URL] == "https://127.0.0.1:9000/"
279+
assert mock_config_entry.data[CONF_VERIFY_SSL] is True
280+
assert len(mock_setup_entry.mock_calls) == 0
281+
282+
258283
@pytest.mark.parametrize(
259284
("exception", "reason"),
260285
[

0 commit comments

Comments
 (0)