mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Automatically set up Awair during onboarding (#78632)
This commit is contained in:
parent
9acea07d31
commit
24df3574bc
@ -10,7 +10,7 @@ from python_awair.exceptions import AuthError, AwairError
|
|||||||
from python_awair.user import AwairUser
|
from python_awair.user import AwairUser
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components import zeroconf
|
from homeassistant.components import onboarding, zeroconf
|
||||||
from homeassistant.config_entries import SOURCE_ZEROCONF, ConfigFlow
|
from homeassistant.config_entries import SOURCE_ZEROCONF, ConfigFlow
|
||||||
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_DEVICE, CONF_HOST
|
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_DEVICE, CONF_HOST
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
@ -60,7 +60,7 @@ class AwairFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Confirm discovery."""
|
"""Confirm discovery."""
|
||||||
if user_input is not None:
|
if user_input is not None or not onboarding.async_is_onboarded(self.hass):
|
||||||
title = f"{self._device.model} ({self._device.device_id})"
|
title = f"{self._device.model} ({self._device.device_id})"
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=title,
|
title=title,
|
||||||
|
@ -399,3 +399,29 @@ async def test_zeroconf_discovery_update_configuration(
|
|||||||
|
|
||||||
assert config_entry.data[CONF_HOST] == ZEROCONF_DISCOVERY.host
|
assert config_entry.data[CONF_HOST] == ZEROCONF_DISCOVERY.host
|
||||||
assert mock_setup_entry.call_count == 0
|
assert mock_setup_entry.call_count == 0
|
||||||
|
|
||||||
|
|
||||||
|
async def test_zeroconf_during_onboarding(
|
||||||
|
hass: HomeAssistant, local_devices: Any
|
||||||
|
) -> None:
|
||||||
|
"""Test the zeroconf creates an entry during onboarding."""
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.awair.async_setup_entry",
|
||||||
|
return_value=True,
|
||||||
|
) as mock_setup_entry, patch(
|
||||||
|
"python_awair.AwairClient.query", side_effect=[local_devices]
|
||||||
|
), patch(
|
||||||
|
"homeassistant.components.onboarding.async_is_onboarded",
|
||||||
|
return_value=False,
|
||||||
|
):
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": SOURCE_ZEROCONF}, data=ZEROCONF_DISCOVERY
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result.get("type") == data_entry_flow.FlowResultType.CREATE_ENTRY
|
||||||
|
assert result.get("title") == "Awair Element (24947)"
|
||||||
|
assert "data" in result
|
||||||
|
assert result["data"][CONF_HOST] == ZEROCONF_DISCOVERY.host
|
||||||
|
assert "result" in result
|
||||||
|
assert result["result"].unique_id == LOCAL_UNIQUE_ID
|
||||||
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user