mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Add reconfigure flow to slide_local (#133669)
This commit is contained in:
parent
b1f6563fb2
commit
07322c6992
@ -103,7 +103,7 @@ class SlideConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle the user step."""
|
"""Handle the user step."""
|
||||||
errors = {}
|
errors: dict[str, str] = {}
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
if not (errors := await self.async_test_connection(user_input)):
|
if not (errors := await self.async_test_connection(user_input)):
|
||||||
await self.async_set_unique_id(self._mac)
|
await self.async_set_unique_id(self._mac)
|
||||||
@ -136,6 +136,45 @@ class SlideConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
errors=errors,
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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 is not None:
|
||||||
|
if not (errors := await self.async_test_connection(user_input)):
|
||||||
|
await self.async_set_unique_id(self._mac)
|
||||||
|
self._abort_if_unique_id_mismatch(
|
||||||
|
description_placeholders={CONF_MAC: self._mac}
|
||||||
|
)
|
||||||
|
user_input |= {
|
||||||
|
CONF_API_VERSION: self._api_version,
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.async_update_reload_and_abort(
|
||||||
|
self._get_reconfigure_entry(),
|
||||||
|
data_updates=user_input,
|
||||||
|
)
|
||||||
|
|
||||||
|
entry: SlideConfigEntry = self._get_reconfigure_entry()
|
||||||
|
|
||||||
|
return self.async_show_form(
|
||||||
|
step_id="reconfigure",
|
||||||
|
data_schema=self.add_suggested_values_to_schema(
|
||||||
|
vol.Schema(
|
||||||
|
{
|
||||||
|
vol.Required(CONF_HOST): str,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
{
|
||||||
|
CONF_HOST: entry.data[CONF_HOST],
|
||||||
|
CONF_PASSWORD: entry.data.get(CONF_PASSWORD, ""),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
errors=errors,
|
||||||
|
)
|
||||||
|
|
||||||
async def async_step_zeroconf(
|
async def async_step_zeroconf(
|
||||||
self, discovery_info: ZeroconfServiceInfo
|
self, discovery_info: ZeroconfServiceInfo
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
|
@ -50,12 +50,12 @@ rules:
|
|||||||
diagnostics: done
|
diagnostics: done
|
||||||
exception-translations: done
|
exception-translations: done
|
||||||
icon-translations: done
|
icon-translations: done
|
||||||
reconfiguration-flow: todo
|
reconfiguration-flow: done
|
||||||
dynamic-devices:
|
dynamic-devices:
|
||||||
status: exempt
|
status: exempt
|
||||||
comment: |
|
comment: |
|
||||||
Slide_local represents a single physical device, no dynamic changes of devices possible (besides removal of instance itself).
|
Slide_local represents a single physical device, no dynamic changes of devices possible (besides removal of instance itself).
|
||||||
discovery-update-info: todo
|
discovery-update-info: done
|
||||||
repair-issues: todo
|
repair-issues: todo
|
||||||
docs-use-cases: done
|
docs-use-cases: done
|
||||||
docs-supported-devices: done
|
docs-supported-devices: done
|
||||||
|
@ -12,6 +12,17 @@
|
|||||||
"password": "The device code of your Slide (inside of the Slide or in the box, length is 8 characters). If your Slide runs firmware version 2 this is optional, as it is not used by the local API."
|
"password": "The device code of your Slide (inside of the Slide or in the box, length is 8 characters). If your Slide runs firmware version 2 this is optional, as it is not used by the local API."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"reconfigure": {
|
||||||
|
"description": "Reconfigure the information for your Slide device",
|
||||||
|
"data": {
|
||||||
|
"host": "[%key:common::config_flow::data::host%]",
|
||||||
|
"password": "[%key:common::config_flow::data::password%]"
|
||||||
|
},
|
||||||
|
"data_description": {
|
||||||
|
"host": "[%key:component::slide_local::config::step::user::data_description::host%]",
|
||||||
|
"password": "[%key:component::slide_local::config::step::user::data_description::password%]"
|
||||||
|
}
|
||||||
|
},
|
||||||
"zeroconf_confirm": {
|
"zeroconf_confirm": {
|
||||||
"title": "Confirm setup for Slide",
|
"title": "Confirm setup for Slide",
|
||||||
"description": "Do you want to setup {host}?"
|
"description": "Do you want to setup {host}?"
|
||||||
@ -19,7 +30,9 @@
|
|||||||
},
|
},
|
||||||
"abort": {
|
"abort": {
|
||||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
|
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
|
||||||
"discovery_connection_failed": "The setup of the discovered device failed with the following error: {error}. Please try to set it up manually."
|
"discovery_connection_failed": "The setup of the discovered device failed with the following error: {error}. Please try to set it up manually.",
|
||||||
|
"reconfigure_successful": "[%key:common::config_flow::abort::reconfigure_successful%]",
|
||||||
|
"unique_id_mismatch": "The mac address of the device ({mac}) does not match the previous mac address."
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||||
|
@ -282,6 +282,36 @@ async def test_abort_if_already_setup(
|
|||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_reconfigure(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mock_slide_api: AsyncMock,
|
||||||
|
mock_config_entry: AsyncMock,
|
||||||
|
mock_setup_entry: AsyncMock,
|
||||||
|
) -> None:
|
||||||
|
"""Test reconfigure flow options."""
|
||||||
|
|
||||||
|
mock_config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
result = await mock_config_entry.start_reconfigure_flow(hass)
|
||||||
|
assert result["type"] is FlowResultType.FORM
|
||||||
|
assert result["step_id"] == "reconfigure"
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
{
|
||||||
|
CONF_HOST: "127.0.0.3",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] is FlowResultType.ABORT
|
||||||
|
assert result["reason"] == "reconfigure_successful"
|
||||||
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
entry = hass.config_entries.async_get_entry(mock_config_entry.entry_id)
|
||||||
|
assert entry
|
||||||
|
assert entry.data[CONF_HOST] == "127.0.0.3"
|
||||||
|
|
||||||
|
|
||||||
async def test_zeroconf(
|
async def test_zeroconf(
|
||||||
hass: HomeAssistant, mock_slide_api: AsyncMock, mock_setup_entry: AsyncMock
|
hass: HomeAssistant, mock_slide_api: AsyncMock, mock_setup_entry: AsyncMock
|
||||||
) -> None:
|
) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user