diff --git a/homeassistant/components/tado/config_flow.py b/homeassistant/components/tado/config_flow.py index 64763469885..48c3d30cb2b 100644 --- a/homeassistant/components/tado/config_flow.py +++ b/homeassistant/components/tado/config_flow.py @@ -22,10 +22,7 @@ from homeassistant.config_entries import ( ) from homeassistant.core import callback from homeassistant.exceptions import HomeAssistantError -from homeassistant.helpers.service_info.zeroconf import ( - ATTR_PROPERTIES_ID, - ZeroconfServiceInfo, -) +from homeassistant.helpers.service_info.zeroconf import ZeroconfServiceInfo from .const import ( CONF_FALLBACK, @@ -164,12 +161,16 @@ class TadoConfigFlow(ConfigFlow, domain=DOMAIN): self, discovery_info: ZeroconfServiceInfo ) -> ConfigFlowResult: """Handle HomeKit discovery.""" - self._async_abort_entries_match() - properties = { - key.lower(): value for key, value in discovery_info.properties.items() - } - await self.async_set_unique_id(properties[ATTR_PROPERTIES_ID]) - self._abort_if_unique_id_configured() + await self._async_handle_discovery_without_unique_id() + return await self.async_step_homekit_confirm() + + async def async_step_homekit_confirm( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: + """Prepare for Homekit.""" + if user_input is None: + return self.async_show_form(step_id="homekit_confirm") + return await self.async_step_user() @staticmethod diff --git a/homeassistant/components/tado/strings.json b/homeassistant/components/tado/strings.json index c7aef7eb51c..53de3969998 100644 --- a/homeassistant/components/tado/strings.json +++ b/homeassistant/components/tado/strings.json @@ -16,6 +16,10 @@ "title": "Authenticate with Tado", "description": "You need to reauthenticate with Tado. Press `Submit` to start the authentication process." }, + "homekit": { + "title": "Authenticate with Tado", + "description": "Your device has been discovered and needs to authenticate with Tado. Press `Submit` to start the authentication process." + }, "timeout": { "description": "The authentication process timed out. Please try again." } diff --git a/tests/components/tado/test_config_flow.py b/tests/components/tado/test_config_flow.py index f7418309d46..2fd8e6a0468 100644 --- a/tests/components/tado/test_config_flow.py +++ b/tests/components/tado/test_config_flow.py @@ -234,13 +234,19 @@ async def test_homekit(hass: HomeAssistant, mock_tado_api: MagicMock) -> None: type="mock_type", ), ) - assert result["type"] is FlowResultType.SHOW_PROGRESS_DONE - flow = next( - flow - for flow in hass.config_entries.flow.async_progress() - if flow["flow_id"] == result["flow_id"] - ) - assert flow["context"]["unique_id"] == "AA:BB:CC:DD:EE:FF" + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "homekit_confirm" + + result = await hass.config_entries.flow.async_configure(result["flow_id"], {}) + + assert result["type"] is FlowResultType.CREATE_ENTRY + assert result["result"].unique_id == "1" + + +async def test_homekit_already_setup( + hass: HomeAssistant, mock_tado_api: MagicMock +) -> None: + """Test that we abort from homekit if tado is already setup.""" entry = MockConfigEntry( domain=DOMAIN, data={CONF_USERNAME: "mock", CONF_PASSWORD: "mock"} @@ -261,3 +267,4 @@ async def test_homekit(hass: HomeAssistant, mock_tado_api: MagicMock) -> None: ), ) assert result["type"] is FlowResultType.ABORT + assert result["reason"] == "already_configured"