2022-07-08 23:55:31 +00:00
|
|
|
"""Tests for the bluetooth component."""
|
2022-08-19 01:41:07 +00:00
|
|
|
|
2022-11-17 19:34:19 +00:00
|
|
|
from unittest.mock import patch
|
2022-08-19 01:41:07 +00:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
2022-09-20 01:02:13 +00:00
|
|
|
@pytest.fixture(name="operating_system_85")
|
|
|
|
def mock_operating_system_85():
|
|
|
|
"""Mock running Home Assistant Operating system 8.5."""
|
|
|
|
with patch("homeassistant.components.hassio.is_hassio", return_value=True), patch(
|
|
|
|
"homeassistant.components.hassio.get_os_info",
|
|
|
|
return_value={
|
|
|
|
"version": "8.5",
|
|
|
|
"version_latest": "10.0.dev20220912",
|
|
|
|
"update_available": False,
|
|
|
|
"board": "odroid-n2",
|
|
|
|
"boot": "B",
|
|
|
|
"data_disk": "/dev/mmcblk1p4",
|
|
|
|
},
|
|
|
|
), patch("homeassistant.components.hassio.get_info", return_value={}), patch(
|
|
|
|
"homeassistant.components.hassio.get_host_info", return_value={}
|
|
|
|
):
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="operating_system_90")
|
|
|
|
def mock_operating_system_90():
|
|
|
|
"""Mock running Home Assistant Operating system 9.0."""
|
|
|
|
with patch("homeassistant.components.hassio.is_hassio", return_value=True), patch(
|
|
|
|
"homeassistant.components.hassio.get_os_info",
|
|
|
|
return_value={
|
|
|
|
"version": "9.0.dev20220912",
|
|
|
|
"version_latest": "10.0.dev20220912",
|
|
|
|
"update_available": False,
|
|
|
|
"board": "odroid-n2",
|
|
|
|
"boot": "B",
|
|
|
|
"data_disk": "/dev/mmcblk1p4",
|
|
|
|
},
|
|
|
|
), patch("homeassistant.components.hassio.get_info", return_value={}), patch(
|
|
|
|
"homeassistant.components.hassio.get_host_info", return_value={}
|
|
|
|
):
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
2022-08-19 01:41:07 +00:00
|
|
|
@pytest.fixture(name="macos_adapter")
|
|
|
|
def macos_adapter():
|
|
|
|
"""Fixture that mocks the macos adapter."""
|
2022-09-24 01:09:28 +00:00
|
|
|
with patch("bleak.get_platform_scanner_backend_type"), patch(
|
2022-09-20 00:58:18 +00:00
|
|
|
"homeassistant.components.bluetooth.platform.system", return_value="Darwin"
|
|
|
|
), patch(
|
|
|
|
"homeassistant.components.bluetooth.scanner.platform.system",
|
|
|
|
return_value="Darwin",
|
|
|
|
), patch(
|
2022-11-17 19:34:19 +00:00
|
|
|
"bluetooth_adapters.systems.platform.system", return_value="Darwin"
|
2022-08-19 01:41:07 +00:00
|
|
|
):
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="windows_adapter")
|
|
|
|
def windows_adapter():
|
|
|
|
"""Fixture that mocks the windows adapter."""
|
|
|
|
with patch(
|
2022-11-17 19:34:19 +00:00
|
|
|
"bluetooth_adapters.systems.platform.system",
|
2022-08-19 01:41:07 +00:00
|
|
|
return_value="Windows",
|
|
|
|
):
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
2022-09-20 01:02:13 +00:00
|
|
|
@pytest.fixture(name="no_adapters")
|
2022-11-17 19:34:19 +00:00
|
|
|
def no_adapter_fixture():
|
2022-09-20 01:02:13 +00:00
|
|
|
"""Fixture that mocks no adapters on Linux."""
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.bluetooth.platform.system", return_value="Linux"
|
|
|
|
), patch(
|
|
|
|
"homeassistant.components.bluetooth.scanner.platform.system",
|
|
|
|
return_value="Linux",
|
|
|
|
), patch(
|
2022-11-17 19:34:19 +00:00
|
|
|
"bluetooth_adapters.systems.platform.system", return_value="Linux"
|
|
|
|
), patch(
|
|
|
|
"bluetooth_adapters.systems.linux.LinuxAdapters.refresh"
|
2022-09-20 01:02:13 +00:00
|
|
|
), patch(
|
2022-11-17 19:34:19 +00:00
|
|
|
"bluetooth_adapters.systems.linux.LinuxAdapters.adapters",
|
|
|
|
{},
|
2022-09-20 01:02:13 +00:00
|
|
|
):
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
2022-08-19 01:41:07 +00:00
|
|
|
@pytest.fixture(name="one_adapter")
|
2022-11-17 19:34:19 +00:00
|
|
|
def one_adapter_fixture():
|
2022-08-19 01:41:07 +00:00
|
|
|
"""Fixture that mocks one adapter on Linux."""
|
|
|
|
with patch(
|
2022-08-24 17:17:28 +00:00
|
|
|
"homeassistant.components.bluetooth.platform.system", return_value="Linux"
|
|
|
|
), patch(
|
|
|
|
"homeassistant.components.bluetooth.scanner.platform.system",
|
|
|
|
return_value="Linux",
|
|
|
|
), patch(
|
2022-11-17 19:34:19 +00:00
|
|
|
"bluetooth_adapters.systems.platform.system", return_value="Linux"
|
2022-08-19 01:41:07 +00:00
|
|
|
), patch(
|
2022-11-17 19:34:19 +00:00
|
|
|
"bluetooth_adapters.systems.linux.LinuxAdapters.refresh"
|
|
|
|
), patch(
|
|
|
|
"bluetooth_adapters.systems.linux.LinuxAdapters.adapters",
|
|
|
|
{
|
2022-08-19 01:41:07 +00:00
|
|
|
"hci0": {
|
2022-11-17 19:34:19 +00:00
|
|
|
"address": "00:00:00:00:00:01",
|
|
|
|
"hw_version": "usb:v1D6Bp0246d053F",
|
|
|
|
"passive_scan": True,
|
|
|
|
"sw_version": "homeassistant",
|
2022-11-27 20:44:44 +00:00
|
|
|
"manufacturer": "ACME",
|
|
|
|
"product": "Bluetooth Adapter 5.0",
|
|
|
|
"product_id": "aa01",
|
|
|
|
"vendor_id": "cc01",
|
2022-08-19 01:41:07 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
):
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="two_adapters")
|
2022-11-17 19:34:19 +00:00
|
|
|
def two_adapters_fixture():
|
2022-08-19 01:41:07 +00:00
|
|
|
"""Fixture that mocks two adapters on Linux."""
|
|
|
|
with patch(
|
2022-08-27 21:41:49 +00:00
|
|
|
"homeassistant.components.bluetooth.platform.system", return_value="Linux"
|
|
|
|
), patch(
|
|
|
|
"homeassistant.components.bluetooth.scanner.platform.system",
|
|
|
|
return_value="Linux",
|
|
|
|
), patch(
|
2022-11-17 19:34:19 +00:00
|
|
|
"bluetooth_adapters.systems.platform.system", return_value="Linux"
|
2022-08-19 01:41:07 +00:00
|
|
|
), patch(
|
2022-11-17 19:34:19 +00:00
|
|
|
"bluetooth_adapters.systems.linux.LinuxAdapters.refresh"
|
|
|
|
), patch(
|
|
|
|
"bluetooth_adapters.systems.linux.LinuxAdapters.adapters",
|
|
|
|
{
|
2022-08-19 01:41:07 +00:00
|
|
|
"hci0": {
|
2022-11-17 19:34:19 +00:00
|
|
|
"address": "00:00:00:00:00:01",
|
|
|
|
"hw_version": "usb:v1D6Bp0246d053F",
|
|
|
|
"passive_scan": False,
|
|
|
|
"sw_version": "homeassistant",
|
2022-11-27 20:44:44 +00:00
|
|
|
"manufacturer": "ACME",
|
|
|
|
"product": "Bluetooth Adapter 5.0",
|
|
|
|
"product_id": "aa01",
|
|
|
|
"vendor_id": "cc01",
|
2022-12-23 18:58:33 +00:00
|
|
|
"connection_slots": 1,
|
2022-08-19 01:41:07 +00:00
|
|
|
},
|
|
|
|
"hci1": {
|
2022-11-17 19:34:19 +00:00
|
|
|
"address": "00:00:00:00:00:02",
|
|
|
|
"hw_version": "usb:v1D6Bp0246d053F",
|
|
|
|
"passive_scan": True,
|
|
|
|
"sw_version": "homeassistant",
|
2022-11-27 20:44:44 +00:00
|
|
|
"manufacturer": "ACME",
|
|
|
|
"product": "Bluetooth Adapter 5.0",
|
|
|
|
"product_id": "aa01",
|
|
|
|
"vendor_id": "cc01",
|
2022-12-23 18:58:33 +00:00
|
|
|
"connection_slots": 2,
|
2022-08-19 01:41:07 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
):
|
|
|
|
yield
|
2022-09-19 01:09:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="one_adapter_old_bluez")
|
2022-11-17 19:34:19 +00:00
|
|
|
def one_adapter_old_bluez():
|
2022-09-19 01:09:45 +00:00
|
|
|
"""Fixture that mocks two adapters on Linux."""
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.bluetooth.platform.system", return_value="Linux"
|
|
|
|
), patch(
|
|
|
|
"homeassistant.components.bluetooth.scanner.platform.system",
|
|
|
|
return_value="Linux",
|
|
|
|
), patch(
|
2022-11-17 19:34:19 +00:00
|
|
|
"bluetooth_adapters.systems.platform.system", return_value="Linux"
|
2022-09-19 01:09:45 +00:00
|
|
|
), patch(
|
2022-11-17 19:34:19 +00:00
|
|
|
"bluetooth_adapters.systems.linux.LinuxAdapters.refresh"
|
|
|
|
), patch(
|
|
|
|
"bluetooth_adapters.systems.linux.LinuxAdapters.adapters",
|
|
|
|
{
|
2022-09-19 01:09:45 +00:00
|
|
|
"hci0": {
|
2022-11-17 19:34:19 +00:00
|
|
|
"address": "00:00:00:00:00:01",
|
|
|
|
"hw_version": "usb:v1D6Bp0246d053F",
|
|
|
|
"passive_scan": False,
|
|
|
|
"sw_version": "homeassistant",
|
2022-11-27 20:44:44 +00:00
|
|
|
"manufacturer": "ACME",
|
|
|
|
"product": "Bluetooth Adapter 5.0",
|
|
|
|
"product_id": "aa01",
|
|
|
|
"vendor_id": "cc01",
|
2022-09-19 01:09:45 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
):
|
|
|
|
yield
|