mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Tado fix HomeKit flow (#141525)
* Initial commit * Fix * Fix --------- Co-authored-by: Joostlek <joostlek@outlook.com>
This commit is contained in:
parent
e9e95f45d8
commit
c30f17f592
@ -22,10 +22,7 @@ from homeassistant.config_entries import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.service_info.zeroconf import (
|
from homeassistant.helpers.service_info.zeroconf import ZeroconfServiceInfo
|
||||||
ATTR_PROPERTIES_ID,
|
|
||||||
ZeroconfServiceInfo,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_FALLBACK,
|
CONF_FALLBACK,
|
||||||
@ -164,12 +161,16 @@ class TadoConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, discovery_info: ZeroconfServiceInfo
|
self, discovery_info: ZeroconfServiceInfo
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle HomeKit discovery."""
|
"""Handle HomeKit discovery."""
|
||||||
self._async_abort_entries_match()
|
await self._async_handle_discovery_without_unique_id()
|
||||||
properties = {
|
return await self.async_step_homekit_confirm()
|
||||||
key.lower(): value for key, value in discovery_info.properties.items()
|
|
||||||
}
|
async def async_step_homekit_confirm(
|
||||||
await self.async_set_unique_id(properties[ATTR_PROPERTIES_ID])
|
self, user_input: dict[str, Any] | None = None
|
||||||
self._abort_if_unique_id_configured()
|
) -> ConfigFlowResult:
|
||||||
|
"""Prepare for Homekit."""
|
||||||
|
if user_input is None:
|
||||||
|
return self.async_show_form(step_id="homekit_confirm")
|
||||||
|
|
||||||
return await self.async_step_user()
|
return await self.async_step_user()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -16,6 +16,10 @@
|
|||||||
"title": "Authenticate with Tado",
|
"title": "Authenticate with Tado",
|
||||||
"description": "You need to reauthenticate with Tado. Press `Submit` to start the authentication process."
|
"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": {
|
"timeout": {
|
||||||
"description": "The authentication process timed out. Please try again."
|
"description": "The authentication process timed out. Please try again."
|
||||||
}
|
}
|
||||||
|
@ -234,13 +234,19 @@ async def test_homekit(hass: HomeAssistant, mock_tado_api: MagicMock) -> None:
|
|||||||
type="mock_type",
|
type="mock_type",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
assert result["type"] is FlowResultType.SHOW_PROGRESS_DONE
|
assert result["type"] is FlowResultType.FORM
|
||||||
flow = next(
|
assert result["step_id"] == "homekit_confirm"
|
||||||
flow
|
|
||||||
for flow in hass.config_entries.flow.async_progress()
|
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
||||||
if flow["flow_id"] == result["flow_id"]
|
|
||||||
)
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||||
assert flow["context"]["unique_id"] == "AA:BB:CC:DD:EE:FF"
|
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(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN, data={CONF_USERNAME: "mock", CONF_PASSWORD: "mock"}
|
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["type"] is FlowResultType.ABORT
|
||||||
|
assert result["reason"] == "already_configured"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user