Files
homeassistant-core/tests/components/bluetooth/test_usage.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
1.4 KiB
Python
Raw Normal View History

2022-07-08 18:55:31 -05:00
"""Tests for the Bluetooth integration."""
from unittest.mock import patch
2022-07-08 18:55:31 -05:00
import bleak
from habluetooth.usage import (
install_multiple_bleak_catcher,
uninstall_multiple_bleak_catcher,
)
from habluetooth.wrappers import HaBleakClientWrapper, HaBleakScannerWrapper
import pytest
from homeassistant.core import HomeAssistant
2022-07-08 18:55:31 -05:00
2023-07-09 10:06:26 -10:00
from . import generate_ble_device
2023-03-20 01:06:15 -10:00
MOCK_BLE_DEVICE = generate_ble_device(
"00:00:00:00:00:00",
"any",
delegate="",
details={"path": "/dev/hci0/device"},
rssi=-127,
)
2022-07-08 18:55:31 -05:00
async def test_multiple_bleak_scanner_instances(hass: HomeAssistant) -> None:
"""Test creating multiple BleakScanners without an integration."""
install_multiple_bleak_catcher()
2022-07-08 18:55:31 -05:00
instance = bleak.BleakScanner()
assert isinstance(instance, HaBleakScannerWrapper)
uninstall_multiple_bleak_catcher()
with patch("bleak.get_platform_scanner_backend_type"):
instance = bleak.BleakScanner()
assert not isinstance(instance, HaBleakScannerWrapper)
@pytest.mark.usefixtures("enable_bluetooth")
async def test_wrapping_bleak_client(hass: HomeAssistant) -> None:
"""Test we wrap BleakClient."""
install_multiple_bleak_catcher()
instance = bleak.BleakClient(MOCK_BLE_DEVICE)
assert isinstance(instance, HaBleakClientWrapper)
uninstall_multiple_bleak_catcher()
instance = bleak.BleakClient(MOCK_BLE_DEVICE)
assert not isinstance(instance, HaBleakClientWrapper)