From ff69ceadc4a441acd2d3bd16e671310caef97f08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ab=C3=ADlio=20Costa?= Date: Mon, 30 Nov 2026 17:24:03 +0000 Subject: [PATCH] Use the infrared consumer config flow in Alpha Bidet Infrared (#195082) Co-authored-by: Claude Opus 5.5 --- .../alpha_bidet_infrared/config_flow.py | 96 ++++--------------- .../alpha_bidet_infrared/strings.json | 2 +- .../alpha_bidet_infrared/conftest.py | 1 - .../alpha_bidet_infrared/test_config_flow.py | 11 +-- 4 files changed, 26 insertions(+), 84 deletions(-) diff --git a/homeassistant/components/alpha_bidet_infrared/config_flow.py b/homeassistant/components/alpha_bidet_infrared/config_flow.py index bb0bb981ad07..049ab6bec913 100644 --- a/homeassistant/components/alpha_bidet_infrared/config_flow.py +++ b/homeassistant/components/alpha_bidet_infrared/config_flow.py @@ -4,16 +4,10 @@ from typing import Any, override import probatio -from homeassistant.components.infrared import ( - DOMAIN as INFRARED_DOMAIN, - async_get_emitters, -) -from homeassistant.config_entries import ConfigFlow, ConfigFlowResult +from homeassistant.components.infrared import InfraredConsumerConfigFlow from homeassistant.const import CONF_MODEL from homeassistant.core import callback from homeassistant.helpers.selector import ( - EntitySelector, - EntitySelectorConfig, SelectSelector, SelectSelectorConfig, SelectSelectorMode, @@ -22,78 +16,30 @@ from homeassistant.helpers.selector import ( from .const import CONF_INFRARED_EMITTER_ENTITY_ID, DOMAIN, AlphaBidetModel -@callback -def _emitter_schema(emitter_entity_ids: list[str]) -> probatio.Schema: - """Return the infrared emitter selection schema.""" - return probatio.Schema( - { - probatio.Required(CONF_INFRARED_EMITTER_ENTITY_ID): EntitySelector( - EntitySelectorConfig( - domain=INFRARED_DOMAIN, include_entities=emitter_entity_ids - ) - ), - } - ) - - -class AlphaBidetIrConfigFlow(ConfigFlow, domain=DOMAIN): +class AlphaBidetIrConfigFlow(InfraredConsumerConfigFlow, domain=DOMAIN): """Handle config flow for Alpha Bidet IR.""" VERSION = 1 + INFRARED_EMITTER_KEY = CONF_INFRARED_EMITTER_ENTITY_ID @override - async def async_step_user( - self, user_input: dict[str, Any] | None = None - ) -> ConfigFlowResult: - """Handle the initial step - select IR emitter and bidet model.""" - emitter_entity_ids = async_get_emitters(self.hass) - if not emitter_entity_ids: - return self.async_abort(reason="no_emitters") - - if user_input is not None: - await self.async_set_unique_id(user_input[CONF_INFRARED_EMITTER_ENTITY_ID]) - self._abort_if_unique_id_configured() - - model = AlphaBidetModel(user_input[CONF_MODEL]) - return self.async_create_entry( - title=f"Alpha Bidet {model.value}", data=user_input - ) - - return self.async_show_form( - step_id="user", - data_schema=_emitter_schema(emitter_entity_ids).extend( - { - probatio.Required(CONF_MODEL): SelectSelector( - SelectSelectorConfig( - options=[model.value for model in AlphaBidetModel], - mode=SelectSelectorMode.DROPDOWN, - ) - ), - } - ), + @callback + def _async_infrared_schema(self) -> probatio.Schema: + """Return the emitter and bidet model selection schema.""" + return probatio.Schema( + { + **self._async_infrared_entity_fields(), + probatio.Required(CONF_MODEL): SelectSelector( + SelectSelectorConfig( + options=[model.value for model in AlphaBidetModel], + mode=SelectSelectorMode.DROPDOWN, + ) + ), + } ) - async def async_step_reconfigure( - self, user_input: dict[str, Any] | None = None - ) -> ConfigFlowResult: - """Handle reconfiguration of the infrared emitter.""" - entry = self._get_reconfigure_entry() - emitter_entity_ids = async_get_emitters(self.hass) - if not emitter_entity_ids: - return self.async_abort(reason="no_emitters") - - if user_input is not None: - emitter_entity_id = user_input[CONF_INFRARED_EMITTER_ENTITY_ID] - self._async_abort_entries_match( - {CONF_INFRARED_EMITTER_ENTITY_ID: emitter_entity_id} - ) - return self.async_update_reload_and_abort( - entry, unique_id=emitter_entity_id, data_updates=user_input - ) - - return self.async_show_form( - step_id="reconfigure", - data_schema=self.add_suggested_values_to_schema( - _emitter_schema(emitter_entity_ids), entry.data - ), - ) + @override + async def _async_infrared_entry_title(self, user_input: dict[str, Any]) -> str: + """Return the title of a new entry.""" + model = AlphaBidetModel(user_input[CONF_MODEL]) + return f"Alpha Bidet {model.value}" diff --git a/homeassistant/components/alpha_bidet_infrared/strings.json b/homeassistant/components/alpha_bidet_infrared/strings.json index 48c8510932b5..9a01570bde39 100644 --- a/homeassistant/components/alpha_bidet_infrared/strings.json +++ b/homeassistant/components/alpha_bidet_infrared/strings.json @@ -2,7 +2,7 @@ "config": { "abort": { "already_configured": "This infrared emitter is already configured to control a bidet.", - "no_emitters": "[%key:component::infrared::common::no_infrared_emitters%]" + "no_infrared_emitters": "[%key:component::infrared::common::no_infrared_emitters%]" }, "step": { "reconfigure": { diff --git a/tests/components/alpha_bidet_infrared/conftest.py b/tests/components/alpha_bidet_infrared/conftest.py index 983c157c9b13..72dd271719ae 100644 --- a/tests/components/alpha_bidet_infrared/conftest.py +++ b/tests/components/alpha_bidet_infrared/conftest.py @@ -30,7 +30,6 @@ def mock_config_entry() -> MockConfigEntry: CONF_INFRARED_EMITTER_ENTITY_ID: MOCK_INFRARED_EMITTER_ENTITY_ID, CONF_MODEL: AlphaBidetModel.JX2.value, }, - unique_id=MOCK_INFRARED_EMITTER_ENTITY_ID, ) diff --git a/tests/components/alpha_bidet_infrared/test_config_flow.py b/tests/components/alpha_bidet_infrared/test_config_flow.py index 26ecc2f3a93f..f78bbe665549 100644 --- a/tests/components/alpha_bidet_infrared/test_config_flow.py +++ b/tests/components/alpha_bidet_infrared/test_config_flow.py @@ -54,7 +54,7 @@ async def test_user_flow_success(hass: HomeAssistant) -> None: CONF_INFRARED_EMITTER_ENTITY_ID: MOCK_INFRARED_EMITTER_ENTITY_ID, CONF_MODEL: AlphaBidetModel.JX2.value, } - assert result["result"].unique_id == MOCK_INFRARED_EMITTER_ENTITY_ID + assert result["result"].unique_id is None @pytest.mark.usefixtures("mock_infrared_emitter_entity") @@ -90,7 +90,7 @@ async def test_user_flow_no_emitters(hass: HomeAssistant) -> None: ) assert result["type"] is FlowResultType.ABORT - assert result["reason"] == "no_emitters" + assert result["reason"] == "no_infrared_emitters" @pytest.mark.usefixtures("mock_infrared_emitter_entity") @@ -123,7 +123,7 @@ async def test_reconfigure_flow_suggests_current_emitter( async def test_reconfigure_flow( hass: HomeAssistant, init_integration: MockConfigEntry, emitter_entity_id: str ) -> None: - """Test reconfiguring updates the emitter and unique ID and reloads the entry.""" + """Test reconfiguring updates the emitter and reloads the entry.""" result = await init_integration.start_reconfigure_flow(hass) result = await hass.config_entries.flow.async_configure( result["flow_id"], @@ -137,7 +137,6 @@ async def test_reconfigure_flow( CONF_INFRARED_EMITTER_ENTITY_ID: emitter_entity_id, CONF_MODEL: AlphaBidetModel.JX2.value, } - assert init_integration.unique_id == emitter_entity_id assert init_integration.state is ConfigEntryState.LOADED @@ -153,7 +152,6 @@ async def test_reconfigure_flow_already_configured( CONF_INFRARED_EMITTER_ENTITY_ID: SECOND_EMITTER_ENTITY_ID, CONF_MODEL: AlphaBidetModel.JX2.value, }, - unique_id=SECOND_EMITTER_ENTITY_ID, ).add_to_hass(hass) result = await mock_config_entry.start_reconfigure_flow(hass) @@ -168,7 +166,6 @@ async def test_reconfigure_flow_already_configured( mock_config_entry.data[CONF_INFRARED_EMITTER_ENTITY_ID] == MOCK_INFRARED_EMITTER_ENTITY_ID ) - assert mock_config_entry.unique_id == MOCK_INFRARED_EMITTER_ENTITY_ID @pytest.mark.usefixtures("init_infrared") @@ -181,4 +178,4 @@ async def test_reconfigure_flow_no_emitters( result = await mock_config_entry.start_reconfigure_flow(hass) assert result["type"] is FlowResultType.ABORT - assert result["reason"] == "no_emitters" + assert result["reason"] == "no_infrared_emitters"