From c654d3283ed06999e41ff40be7bbbd269d64960a Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 1 Oct 2024 14:25:32 +0200 Subject: [PATCH] Use reconfigure_confirm in vallox config flow (#127214) --- .../components/vallox/config_flow.py | 25 +++++++++++++------ homeassistant/components/vallox/strings.json | 2 +- tests/components/vallox/conftest.py | 2 +- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/vallox/config_flow.py b/homeassistant/components/vallox/config_flow.py index 3660c641b7c..a413a641d18 100644 --- a/homeassistant/components/vallox/config_flow.py +++ b/homeassistant/components/vallox/config_flow.py @@ -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} ), diff --git a/homeassistant/components/vallox/strings.json b/homeassistant/components/vallox/strings.json index 8a30ed4ad01..608a5eb1782 100644 --- a/homeassistant/components/vallox/strings.json +++ b/homeassistant/components/vallox/strings.json @@ -9,7 +9,7 @@ "host": "Hostname or IP address of your Vallox device." } }, - "reconfigure": { + "reconfigure_confirm": { "data": { "host": "[%key:common::config_flow::data::host%]" }, diff --git a/tests/components/vallox/conftest.py b/tests/components/vallox/conftest.py index a6ea95944b3..114728599e6 100644 --- a/tests/components/vallox/conftest.py +++ b/tests/components/vallox/conftest.py @@ -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"