mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Offload platform specific bluetooth code to bluetooth-adapters (#82196)
* Offload platform specific bluetooth code to bluetooth-adapters * adjust * fix some more patch targets * more test fixes * almost there * may not be setup yet * more fixes * fixes * fix test * fix merge
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"""Tests for the bluetooth component."""
|
||||
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -43,16 +43,6 @@ def mock_operating_system_90():
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(name="bluez_dbus_mock")
|
||||
def bluez_dbus_mock():
|
||||
"""Fixture that mocks out the bluez dbus calls."""
|
||||
# Must patch directly since this is loaded on demand only
|
||||
with patch(
|
||||
"bluetooth_adapters.BlueZDBusObjects", return_value=MagicMock(load=AsyncMock())
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(name="macos_adapter")
|
||||
def macos_adapter():
|
||||
"""Fixture that mocks the macos adapter."""
|
||||
@@ -62,7 +52,7 @@ def macos_adapter():
|
||||
"homeassistant.components.bluetooth.scanner.platform.system",
|
||||
return_value="Darwin",
|
||||
), patch(
|
||||
"homeassistant.components.bluetooth.util.platform.system", return_value="Darwin"
|
||||
"bluetooth_adapters.systems.platform.system", return_value="Darwin"
|
||||
):
|
||||
yield
|
||||
|
||||
@@ -71,14 +61,14 @@ def macos_adapter():
|
||||
def windows_adapter():
|
||||
"""Fixture that mocks the windows adapter."""
|
||||
with patch(
|
||||
"homeassistant.components.bluetooth.util.platform.system",
|
||||
"bluetooth_adapters.systems.platform.system",
|
||||
return_value="Windows",
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(name="no_adapters")
|
||||
def no_adapter_fixture(bluez_dbus_mock):
|
||||
def no_adapter_fixture():
|
||||
"""Fixture that mocks no adapters on Linux."""
|
||||
with patch(
|
||||
"homeassistant.components.bluetooth.platform.system", return_value="Linux"
|
||||
@@ -86,16 +76,18 @@ def no_adapter_fixture(bluez_dbus_mock):
|
||||
"homeassistant.components.bluetooth.scanner.platform.system",
|
||||
return_value="Linux",
|
||||
), patch(
|
||||
"homeassistant.components.bluetooth.util.platform.system", return_value="Linux"
|
||||
"bluetooth_adapters.systems.platform.system", return_value="Linux"
|
||||
), patch(
|
||||
"bluetooth_adapters.get_bluetooth_adapter_details",
|
||||
return_value={},
|
||||
"bluetooth_adapters.systems.linux.LinuxAdapters.refresh"
|
||||
), patch(
|
||||
"bluetooth_adapters.systems.linux.LinuxAdapters.adapters",
|
||||
{},
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(name="one_adapter")
|
||||
def one_adapter_fixture(bluez_dbus_mock):
|
||||
def one_adapter_fixture():
|
||||
"""Fixture that mocks one adapter on Linux."""
|
||||
with patch(
|
||||
"homeassistant.components.bluetooth.platform.system", return_value="Linux"
|
||||
@@ -103,20 +95,17 @@ def one_adapter_fixture(bluez_dbus_mock):
|
||||
"homeassistant.components.bluetooth.scanner.platform.system",
|
||||
return_value="Linux",
|
||||
), patch(
|
||||
"homeassistant.components.bluetooth.util.platform.system", return_value="Linux"
|
||||
"bluetooth_adapters.systems.platform.system", return_value="Linux"
|
||||
), patch(
|
||||
"bluetooth_adapters.get_bluetooth_adapter_details",
|
||||
return_value={
|
||||
"bluetooth_adapters.systems.linux.LinuxAdapters.refresh"
|
||||
), patch(
|
||||
"bluetooth_adapters.systems.linux.LinuxAdapters.adapters",
|
||||
{
|
||||
"hci0": {
|
||||
"org.bluez.Adapter1": {
|
||||
"Address": "00:00:00:00:00:01",
|
||||
"Name": "BlueZ 4.63",
|
||||
"Modalias": "usbid:1234",
|
||||
},
|
||||
"org.bluez.AdvertisementMonitorManager1": {
|
||||
"SupportedMonitorTypes": ["or_patterns"],
|
||||
"SupportedFeatures": [],
|
||||
},
|
||||
"address": "00:00:00:00:00:01",
|
||||
"hw_version": "usb:v1D6Bp0246d053F",
|
||||
"passive_scan": True,
|
||||
"sw_version": "homeassistant",
|
||||
},
|
||||
},
|
||||
):
|
||||
@@ -124,7 +113,7 @@ def one_adapter_fixture(bluez_dbus_mock):
|
||||
|
||||
|
||||
@pytest.fixture(name="two_adapters")
|
||||
def two_adapters_fixture(bluez_dbus_mock):
|
||||
def two_adapters_fixture():
|
||||
"""Fixture that mocks two adapters on Linux."""
|
||||
with patch(
|
||||
"homeassistant.components.bluetooth.platform.system", return_value="Linux"
|
||||
@@ -132,27 +121,23 @@ def two_adapters_fixture(bluez_dbus_mock):
|
||||
"homeassistant.components.bluetooth.scanner.platform.system",
|
||||
return_value="Linux",
|
||||
), patch(
|
||||
"homeassistant.components.bluetooth.util.platform.system", return_value="Linux"
|
||||
"bluetooth_adapters.systems.platform.system", return_value="Linux"
|
||||
), patch(
|
||||
"bluetooth_adapters.get_bluetooth_adapter_details",
|
||||
return_value={
|
||||
"bluetooth_adapters.systems.linux.LinuxAdapters.refresh"
|
||||
), patch(
|
||||
"bluetooth_adapters.systems.linux.LinuxAdapters.adapters",
|
||||
{
|
||||
"hci0": {
|
||||
"org.bluez.Adapter1": {
|
||||
"Address": "00:00:00:00:00:01",
|
||||
"Name": "BlueZ 4.63",
|
||||
"Modalias": "usbid:1234",
|
||||
}
|
||||
"address": "00:00:00:00:00:01",
|
||||
"hw_version": "usb:v1D6Bp0246d053F",
|
||||
"passive_scan": False,
|
||||
"sw_version": "homeassistant",
|
||||
},
|
||||
"hci1": {
|
||||
"org.bluez.Adapter1": {
|
||||
"Address": "00:00:00:00:00:02",
|
||||
"Name": "BlueZ 4.63",
|
||||
"Modalias": "usbid:1234",
|
||||
},
|
||||
"org.bluez.AdvertisementMonitorManager1": {
|
||||
"SupportedMonitorTypes": ["or_patterns"],
|
||||
"SupportedFeatures": [],
|
||||
},
|
||||
"address": "00:00:00:00:00:02",
|
||||
"hw_version": "usb:v1D6Bp0246d053F",
|
||||
"passive_scan": True,
|
||||
"sw_version": "homeassistant",
|
||||
},
|
||||
},
|
||||
):
|
||||
@@ -160,7 +145,7 @@ def two_adapters_fixture(bluez_dbus_mock):
|
||||
|
||||
|
||||
@pytest.fixture(name="one_adapter_old_bluez")
|
||||
def one_adapter_old_bluez(bluez_dbus_mock):
|
||||
def one_adapter_old_bluez():
|
||||
"""Fixture that mocks two adapters on Linux."""
|
||||
with patch(
|
||||
"homeassistant.components.bluetooth.platform.system", return_value="Linux"
|
||||
@@ -168,15 +153,17 @@ def one_adapter_old_bluez(bluez_dbus_mock):
|
||||
"homeassistant.components.bluetooth.scanner.platform.system",
|
||||
return_value="Linux",
|
||||
), patch(
|
||||
"homeassistant.components.bluetooth.util.platform.system", return_value="Linux"
|
||||
"bluetooth_adapters.systems.platform.system", return_value="Linux"
|
||||
), patch(
|
||||
"bluetooth_adapters.get_bluetooth_adapter_details",
|
||||
return_value={
|
||||
"bluetooth_adapters.systems.linux.LinuxAdapters.refresh"
|
||||
), patch(
|
||||
"bluetooth_adapters.systems.linux.LinuxAdapters.adapters",
|
||||
{
|
||||
"hci0": {
|
||||
"org.bluez.Adapter1": {
|
||||
"Address": "00:00:00:00:00:01",
|
||||
"Name": "BlueZ 4.43",
|
||||
}
|
||||
"address": "00:00:00:00:00:01",
|
||||
"hw_version": "usb:v1D6Bp0246d053F",
|
||||
"passive_scan": False,
|
||||
"sw_version": "homeassistant",
|
||||
},
|
||||
},
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user