mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Import bluetooth in the executor to avoid blocking the event loop (#111596)
This commit is contained in:
parent
f622ddef47
commit
e25b097376
@ -5,6 +5,7 @@
|
|||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"dependencies": ["usb"],
|
"dependencies": ["usb"],
|
||||||
"documentation": "https://www.home-assistant.io/integrations/bluetooth",
|
"documentation": "https://www.home-assistant.io/integrations/bluetooth",
|
||||||
|
"import_executor": true,
|
||||||
"iot_class": "local_push",
|
"iot_class": "local_push",
|
||||||
"loggers": [
|
"loggers": [
|
||||||
"btsocket",
|
"btsocket",
|
||||||
|
@ -2,9 +2,33 @@
|
|||||||
|
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from bleak_retry_connector import bleak_manager
|
||||||
|
from dbus_fast.aio import message_bus
|
||||||
|
import habluetooth.util as habluetooth_utils
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(name="disable_bluez_manager_socket", autouse=True, scope="session")
|
||||||
|
def disable_bluez_manager_socket():
|
||||||
|
"""Mock the bluez manager socket."""
|
||||||
|
with patch.object(bleak_manager, "get_global_bluez_manager_with_timeout"):
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(name="disable_dbus_socket", autouse=True, scope="session")
|
||||||
|
def disable_dbus_socket():
|
||||||
|
"""Mock the dbus message bus to avoid creating a socket."""
|
||||||
|
with patch.object(message_bus, "MessageBus"):
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(name="disable_bluetooth_auto_recovery", autouse=True, scope="session")
|
||||||
|
def disable_bluetooth_auto_recovery():
|
||||||
|
"""Mock out auto recovery."""
|
||||||
|
with patch.object(habluetooth_utils, "recover_adapter"):
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="operating_system_85")
|
@pytest.fixture(name="operating_system_85")
|
||||||
def mock_operating_system_85():
|
def mock_operating_system_85():
|
||||||
"""Mock running Home Assistant Operating system 8.5."""
|
"""Mock running Home Assistant Operating system 8.5."""
|
||||||
|
@ -47,6 +47,7 @@ from . import (
|
|||||||
FakeScanner,
|
FakeScanner,
|
||||||
_get_manager,
|
_get_manager,
|
||||||
async_setup_with_default_adapter,
|
async_setup_with_default_adapter,
|
||||||
|
async_setup_with_one_adapter,
|
||||||
generate_advertisement_data,
|
generate_advertisement_data,
|
||||||
generate_ble_device,
|
generate_ble_device,
|
||||||
inject_advertisement,
|
inject_advertisement,
|
||||||
@ -178,7 +179,7 @@ async def test_setup_and_stop_old_bluez(
|
|||||||
|
|
||||||
|
|
||||||
async def test_setup_and_stop_no_bluetooth(
|
async def test_setup_and_stop_no_bluetooth(
|
||||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, macos_adapter: None
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, one_adapter: None
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test we fail gracefully when bluetooth is not available."""
|
"""Test we fail gracefully when bluetooth is not available."""
|
||||||
mock_bt = [
|
mock_bt = [
|
||||||
@ -189,8 +190,8 @@ async def test_setup_and_stop_no_bluetooth(
|
|||||||
side_effect=BleakError,
|
side_effect=BleakError,
|
||||||
) as mock_ha_bleak_scanner, patch(
|
) as mock_ha_bleak_scanner, patch(
|
||||||
"homeassistant.components.bluetooth.async_get_bluetooth", return_value=mock_bt
|
"homeassistant.components.bluetooth.async_get_bluetooth", return_value=mock_bt
|
||||||
):
|
), patch("homeassistant.components.bluetooth.discovery_flow.async_create_flow"):
|
||||||
await async_setup_with_default_adapter(hass)
|
await async_setup_with_one_adapter(hass)
|
||||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user