Use reconfigure_confirm in vallox config flow (#127214)

pull/127219/head
epenet 2024-10-01 14:25:32 +02:00 committed by GitHub
parent 8e6b6269a7
commit c654d3283e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 10 deletions

View File

@ -2,13 +2,14 @@
from __future__ import annotations
from collections.abc import Mapping
import logging
from typing import Any
from vallox_websocket_api import Vallox, ValloxApiException
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.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
@ -40,6 +41,8 @@ class ValloxConfigFlow(ConfigFlow, domain=DOMAIN):
VERSION = 1
_context_entry: ConfigEntry
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
@ -83,23 +86,29 @@ class ValloxConfigFlow(ConfigFlow, domain=DOMAIN):
)
async def async_step_reconfigure(
self, user_input: dict[str, Any] | None = None
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""Handle reconfiguration of the Vallox device host address."""
entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
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:
return self.async_show_form(
step_id="reconfigure",
step_id="reconfigure_confirm",
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]
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})
errors: dict[str, str] = {}
@ -115,13 +124,13 @@ class ValloxConfigFlow(ConfigFlow, domain=DOMAIN):
errors[CONF_HOST] = "unknown"
else:
return self.async_update_reload_and_abort(
entry,
data={**entry.data, CONF_HOST: updated_host},
self._context_entry,
data={**self._context_entry.data, CONF_HOST: updated_host},
reason="reconfigure_successful",
)
return self.async_show_form(
step_id="reconfigure",
step_id="reconfigure_confirm",
data_schema=self.add_suggested_values_to_schema(
CONFIG_SCHEMA, {CONF_HOST: updated_host}
),

View File

@ -9,7 +9,7 @@
"host": "Hostname or IP address of your Vallox device."
}
},
"reconfigure": {
"reconfigure_confirm": {
"data": {
"host": "[%key:common::config_flow::data::host%]"
},

View File

@ -88,7 +88,7 @@ async def init_reconfigure_flow(
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure"
assert result["step_id"] == "reconfigure_confirm"
# original entry
assert mock_entry.data["host"] == "192.168.100.50"