Tado fix HomeKit flow (#141525)

* Initial commit

* Fix

* Fix

---------

Co-authored-by: Joostlek <joostlek@outlook.com>
This commit is contained in:
Erwin Douna 2025-03-27 16:01:54 +01:00 committed by GitHub
parent e9e95f45d8
commit c30f17f592
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 17 deletions

View File

@ -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

View File

@ -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."
}

View File

@ -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"