Use reconfigure_confirm in vallox config flow (#127214)
This commit is contained in:
parent
8e6b6269a7
commit
c654d3283e
3 changed files with 19 additions and 10 deletions
|
@ -2,13 +2,14 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Mapping
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from vallox_websocket_api import Vallox, ValloxApiException
|
from vallox_websocket_api import Vallox, ValloxApiException
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
|
||||||
from homeassistant.const import CONF_HOST, CONF_NAME
|
from homeassistant.const import CONF_HOST, CONF_NAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
|
@ -40,6 +41,8 @@ class ValloxConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
|
_context_entry: ConfigEntry
|
||||||
|
|
||||||
async def async_step_user(
|
async def async_step_user(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
|
@ -83,23 +86,29 @@ class ValloxConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_reconfigure(
|
async def async_step_reconfigure(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle reconfiguration of the Vallox device host address."""
|
"""Handle reconfiguration of the Vallox device host address."""
|
||||||
entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
|
entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
|
||||||
assert entry
|
assert entry
|
||||||
|
self._context_entry = entry
|
||||||
|
return await self.async_step_reconfigure_confirm()
|
||||||
|
|
||||||
|
async def async_step_reconfigure_confirm(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> ConfigFlowResult:
|
||||||
|
"""Handle reconfiguration of the Vallox device host address."""
|
||||||
if not user_input:
|
if not user_input:
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="reconfigure",
|
step_id="reconfigure_confirm",
|
||||||
data_schema=self.add_suggested_values_to_schema(
|
data_schema=self.add_suggested_values_to_schema(
|
||||||
CONFIG_SCHEMA, {CONF_HOST: entry.data.get(CONF_HOST)}
|
CONFIG_SCHEMA, {CONF_HOST: self._context_entry.data.get(CONF_HOST)}
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
updated_host = user_input[CONF_HOST]
|
updated_host = user_input[CONF_HOST]
|
||||||
|
|
||||||
if entry.data.get(CONF_HOST) != updated_host:
|
if self._context_entry.data.get(CONF_HOST) != updated_host:
|
||||||
self._async_abort_entries_match({CONF_HOST: updated_host})
|
self._async_abort_entries_match({CONF_HOST: updated_host})
|
||||||
|
|
||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
|
@ -115,13 +124,13 @@ class ValloxConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
errors[CONF_HOST] = "unknown"
|
errors[CONF_HOST] = "unknown"
|
||||||
else:
|
else:
|
||||||
return self.async_update_reload_and_abort(
|
return self.async_update_reload_and_abort(
|
||||||
entry,
|
self._context_entry,
|
||||||
data={**entry.data, CONF_HOST: updated_host},
|
data={**self._context_entry.data, CONF_HOST: updated_host},
|
||||||
reason="reconfigure_successful",
|
reason="reconfigure_successful",
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="reconfigure",
|
step_id="reconfigure_confirm",
|
||||||
data_schema=self.add_suggested_values_to_schema(
|
data_schema=self.add_suggested_values_to_schema(
|
||||||
CONFIG_SCHEMA, {CONF_HOST: updated_host}
|
CONFIG_SCHEMA, {CONF_HOST: updated_host}
|
||||||
),
|
),
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
"host": "Hostname or IP address of your Vallox device."
|
"host": "Hostname or IP address of your Vallox device."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"reconfigure": {
|
"reconfigure_confirm": {
|
||||||
"data": {
|
"data": {
|
||||||
"host": "[%key:common::config_flow::data::host%]"
|
"host": "[%key:common::config_flow::data::host%]"
|
||||||
},
|
},
|
||||||
|
|
|
@ -88,7 +88,7 @@ async def init_reconfigure_flow(
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "reconfigure"
|
assert result["step_id"] == "reconfigure_confirm"
|
||||||
|
|
||||||
# original entry
|
# original entry
|
||||||
assert mock_entry.data["host"] == "192.168.100.50"
|
assert mock_entry.data["host"] == "192.168.100.50"
|
||||||
|
|
Loading…
Add table
Reference in a new issue