mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 05:37:44 +00:00
Automatically set up Xiaomi BLE during onboarding (#75748)
This commit is contained in:
parent
b57e0d13b4
commit
5e45b0baf9
@ -8,6 +8,7 @@ import voluptuous as vol
|
||||
from xiaomi_ble import XiaomiBluetoothDeviceData as DeviceData
|
||||
from xiaomi_ble.parser import EncryptionScheme
|
||||
|
||||
from homeassistant.components import onboarding
|
||||
from homeassistant.components.bluetooth import (
|
||||
BluetoothServiceInfo,
|
||||
async_discovered_service_info,
|
||||
@ -139,7 +140,7 @@ class XiaomiConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> FlowResult:
|
||||
"""Confirm discovery."""
|
||||
if user_input is not None:
|
||||
if user_input is not None or not onboarding.async_is_onboarded(self.hass):
|
||||
return self.async_create_entry(
|
||||
title=self.context["title_placeholders"]["name"],
|
||||
data={},
|
||||
|
@ -38,6 +38,28 @@ async def test_async_step_bluetooth_valid_device(hass):
|
||||
assert result2["result"].unique_id == "00:81:F9:DD:6F:C1"
|
||||
|
||||
|
||||
async def test_async_step_bluetooth_during_onboarding(hass):
|
||||
"""Test discovery via bluetooth during onboarding."""
|
||||
with patch(
|
||||
"homeassistant.components.xiaomi_ble.async_setup_entry", return_value=True
|
||||
) as mock_setup_entry, patch(
|
||||
"homeassistant.components.onboarding.async_is_onboarded",
|
||||
return_value=False,
|
||||
) as mock_onboarding:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_BLUETOOTH},
|
||||
data=MMC_T201_1_SERVICE_INFO,
|
||||
)
|
||||
|
||||
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "MMC_T201_1"
|
||||
assert result["data"] == {}
|
||||
assert result["result"].unique_id == "00:81:F9:DD:6F:C1"
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
assert len(mock_onboarding.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_async_step_bluetooth_valid_device_legacy_encryption(hass):
|
||||
"""Test discovery via bluetooth with a valid device, with legacy encryption."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
Loading…
x
Reference in New Issue
Block a user