mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add reconfigure flow to Axis integration (#114067)
This commit is contained in:
parent
579084a21e
commit
2e2b40f77e
@ -146,6 +146,14 @@ class AxisFlowHandler(ConfigFlow, domain=AXIS_DOMAIN):
|
|||||||
title = f"{model} - {serial}"
|
title = f"{model} - {serial}"
|
||||||
return self.async_create_entry(title=title, data=self.config)
|
return self.async_create_entry(title=title, data=self.config)
|
||||||
|
|
||||||
|
async def async_step_reconfigure(
|
||||||
|
self, user_input: Mapping[str, Any] | None = None
|
||||||
|
) -> ConfigFlowResult:
|
||||||
|
"""Trigger a reconfiguration flow."""
|
||||||
|
entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
|
||||||
|
assert entry
|
||||||
|
return await self._redo_configuration(entry.data, keep_password=True)
|
||||||
|
|
||||||
async def async_step_reauth(
|
async def async_step_reauth(
|
||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
@ -154,14 +162,22 @@ class AxisFlowHandler(ConfigFlow, domain=AXIS_DOMAIN):
|
|||||||
CONF_NAME: entry_data[CONF_NAME],
|
CONF_NAME: entry_data[CONF_NAME],
|
||||||
CONF_HOST: entry_data[CONF_HOST],
|
CONF_HOST: entry_data[CONF_HOST],
|
||||||
}
|
}
|
||||||
|
return await self._redo_configuration(entry_data, keep_password=False)
|
||||||
|
|
||||||
|
async def _redo_configuration(
|
||||||
|
self, entry_data: Mapping[str, Any], keep_password: bool
|
||||||
|
) -> ConfigFlowResult:
|
||||||
|
"""Re-run configuration step."""
|
||||||
self.discovery_schema = {
|
self.discovery_schema = {
|
||||||
vol.Required(
|
vol.Required(
|
||||||
CONF_PROTOCOL, default=entry_data.get(CONF_PROTOCOL, DEFAULT_PROTOCOL)
|
CONF_PROTOCOL, default=entry_data.get(CONF_PROTOCOL, "http")
|
||||||
): str,
|
): str,
|
||||||
vol.Required(CONF_HOST, default=entry_data[CONF_HOST]): str,
|
vol.Required(CONF_HOST, default=entry_data[CONF_HOST]): str,
|
||||||
vol.Required(CONF_USERNAME, default=entry_data[CONF_USERNAME]): str,
|
vol.Required(CONF_USERNAME, default=entry_data[CONF_USERNAME]): str,
|
||||||
vol.Required(CONF_PASSWORD): str,
|
vol.Required(
|
||||||
|
CONF_PASSWORD,
|
||||||
|
default=entry_data[CONF_PASSWORD] if keep_password else "",
|
||||||
|
): str,
|
||||||
vol.Required(CONF_PORT, default=entry_data[CONF_PORT]): int,
|
vol.Required(CONF_PORT, default=entry_data[CONF_PORT]): int,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ from homeassistant.config_entries import (
|
|||||||
SOURCE_DHCP,
|
SOURCE_DHCP,
|
||||||
SOURCE_IGNORE,
|
SOURCE_IGNORE,
|
||||||
SOURCE_REAUTH,
|
SOURCE_REAUTH,
|
||||||
|
SOURCE_RECONFIGURE,
|
||||||
SOURCE_SSDP,
|
SOURCE_SSDP,
|
||||||
SOURCE_USER,
|
SOURCE_USER,
|
||||||
SOURCE_ZEROCONF,
|
SOURCE_ZEROCONF,
|
||||||
@ -259,6 +260,44 @@ async def test_reauth_flow_update_configuration(
|
|||||||
assert mock_config_entry.data[CONF_PASSWORD] == "pass2"
|
assert mock_config_entry.data[CONF_PASSWORD] == "pass2"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_reconfiguration_flow_update_configuration(
|
||||||
|
hass: HomeAssistant, mock_config_entry, mock_vapix_requests
|
||||||
|
) -> None:
|
||||||
|
"""Test that config flow reconfiguration updates configured device."""
|
||||||
|
assert mock_config_entry.data[CONF_HOST] == "1.2.3.4"
|
||||||
|
assert mock_config_entry.data[CONF_USERNAME] == "root"
|
||||||
|
assert mock_config_entry.data[CONF_PASSWORD] == "pass"
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
AXIS_DOMAIN,
|
||||||
|
context={
|
||||||
|
"source": SOURCE_RECONFIGURE,
|
||||||
|
"entry_id": mock_config_entry.entry_id,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] == FlowResultType.FORM
|
||||||
|
assert result["step_id"] == "user"
|
||||||
|
|
||||||
|
mock_vapix_requests("2.3.4.5")
|
||||||
|
result = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
user_input={
|
||||||
|
CONF_HOST: "2.3.4.5",
|
||||||
|
CONF_USERNAME: "user",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert result["type"] == FlowResultType.ABORT
|
||||||
|
assert result["reason"] == "already_configured"
|
||||||
|
assert mock_config_entry.data[CONF_PROTOCOL] == "http"
|
||||||
|
assert mock_config_entry.data[CONF_HOST] == "2.3.4.5"
|
||||||
|
assert mock_config_entry.data[CONF_PORT] == 80
|
||||||
|
assert mock_config_entry.data[CONF_USERNAME] == "user"
|
||||||
|
assert mock_config_entry.data[CONF_PASSWORD] == "pass"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("source", "discovery_info"),
|
("source", "discovery_info"),
|
||||||
[
|
[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user