mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Automatically set up Bluetooth during onboarding (#75658)
This commit is contained in:
parent
b71e3397fd
commit
8d6247446b
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from homeassistant.components import onboarding
|
||||||
from homeassistant.config_entries import ConfigFlow
|
from homeassistant.config_entries import ConfigFlow
|
||||||
from homeassistant.data_entry_flow import FlowResult
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
|
|
||||||
@ -27,7 +28,7 @@ class BluetoothConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
if self._async_current_entries():
|
if self._async_current_entries():
|
||||||
return self.async_abort(reason="already_configured")
|
return self.async_abort(reason="already_configured")
|
||||||
|
|
||||||
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=DEFAULT_NAME, data={})
|
return self.async_create_entry(title=DEFAULT_NAME, data={})
|
||||||
|
|
||||||
return self.async_show_form(step_id="enable_bluetooth")
|
return self.async_show_form(step_id="enable_bluetooth")
|
||||||
|
@ -64,6 +64,27 @@ async def test_async_step_integration_discovery(hass):
|
|||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
|
async def test_async_step_integration_discovery_during_onboarding(hass):
|
||||||
|
"""Test setting up from integration discovery during onboarding."""
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.bluetooth.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_INTEGRATION_DISCOVERY},
|
||||||
|
data={},
|
||||||
|
)
|
||||||
|
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||||
|
assert result["title"] == "Bluetooth"
|
||||||
|
assert result["data"] == {}
|
||||||
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
assert len(mock_onboarding.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_async_step_integration_discovery_already_exists(hass):
|
async def test_async_step_integration_discovery_already_exists(hass):
|
||||||
"""Test setting up from integration discovery when an entry already exists."""
|
"""Test setting up from integration discovery when an entry already exists."""
|
||||||
entry = MockConfigEntry(domain=DOMAIN)
|
entry = MockConfigEntry(domain=DOMAIN)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user