Skip to content

Commit

Permalink
Add reconfigure flow
Browse files Browse the repository at this point in the history
  • Loading branch information
VandeurenGlenn committed Dec 25, 2024
1 parent 60774c6 commit 2b508f1
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
19 changes: 19 additions & 0 deletions homeassistant/components/niko_home_control/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,25 @@ class NikoHomeControlConfigFlow(ConfigFlow, domain=DOMAIN):

MINOR_VERSION = 2

async def async_step_reconfigure(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle reconfiguration of the integration."""
errors: dict[str, str] = {}
if user_input:
self._async_abort_entries_match({CONF_HOST: user_input[CONF_HOST]})
error = await test_connection(user_input[CONF_HOST])
if not error:
return self.async_update_reload_and_abort(

Check warning on line 47 in homeassistant/components/niko_home_control/config_flow.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/config_flow.py#L44-L47

Added lines #L44 - L47 were not covered by tests
self._get_reconfigure_entry(),
data_updates=user_input,
)
errors["base"] = error

Check warning on line 51 in homeassistant/components/niko_home_control/config_flow.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/niko_home_control/config_flow.py#L51

Added line #L51 was not covered by tests

return self.async_show_form(
step_id="user", data_schema=DATA_SCHEMA, errors=errors
)

async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
Expand Down
46 changes: 46 additions & 0 deletions tests/components/niko_home_control/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,49 @@ async def test_duplicate_import_entry(

assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"


async def test_reconfigure_duplicate_config(
hass: HomeAssistant, mock_setup_entry: AsyncMock, mock_config_entry: MockConfigEntry
) -> None:
"""Test the reconfigure flow."""
mock_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()

result = await mock_config_entry.start_reconfigure_flow(hass)

assert result["type"] is FlowResultType.FORM
assert set(result["data_schema"].schema) == {CONF_HOST}

result = await hass.config_entries.flow.async_configure(
result["flow_id"], {CONF_HOST: "192.168.0.123"}
)
await hass.async_block_till_done()

assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"


async def test_reconfigure(
hass: HomeAssistant,
mock_niko_home_control_connection: AsyncMock,
mock_setup_entry: AsyncMock,
mock_config_entry: MockConfigEntry,
) -> None:
"""Test the reconfigure flow."""
mock_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()

result = await mock_config_entry.start_reconfigure_flow(hass)

assert result["type"] is FlowResultType.FORM
assert set(result["data_schema"].schema) == {CONF_HOST}

result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_HOST: "192.168.0.122"},
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.CREATE_ENTRY

0 comments on commit 2b508f1

Please sign in to comment.