Import bluetooth in the executor to avoid blocking the event loop (#111596)
parent
f622ddef47
commit
e25b097376
|
@ -5,6 +5,7 @@
|
|||
"config_flow": true,
|
||||
"dependencies": ["usb"],
|
||||
"documentation": "https://www.home-assistant.io/integrations/bluetooth",
|
||||
"import_executor": true,
|
||||
"iot_class": "local_push",
|
||||
"loggers": [
|
||||
"btsocket",
|
||||
|
|
|
@ -2,9 +2,33 @@
|
|||
|
||||
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
|
||||
|
||||
|
||||
@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")
|
||||
def mock_operating_system_85():
|
||||
"""Mock running Home Assistant Operating system 8.5."""
|
||||
|
|
|
@ -47,6 +47,7 @@ from . import (
|
|||
FakeScanner,
|
||||
_get_manager,
|
||||
async_setup_with_default_adapter,
|
||||
async_setup_with_one_adapter,
|
||||
generate_advertisement_data,
|
||||
generate_ble_device,
|
||||
inject_advertisement,
|
||||
|
@ -178,7 +179,7 @@ async def test_setup_and_stop_old_bluez(
|
|||
|
||||
|
||||
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:
|
||||
"""Test we fail gracefully when bluetooth is not available."""
|
||||
mock_bt = [
|
||||
|
@ -189,8 +190,8 @@ async def test_setup_and_stop_no_bluetooth(
|
|||
side_effect=BleakError,
|
||||
) as mock_ha_bleak_scanner, patch(
|
||||
"homeassistant.components.bluetooth.async_get_bluetooth", return_value=mock_bt
|
||||
):
|
||||
await async_setup_with_default_adapter(hass)
|
||||
), patch("homeassistant.components.bluetooth.discovery_flow.async_create_flow"):
|
||||
await async_setup_with_one_adapter(hass)
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
|
Loading…
Reference in New Issue