hass-core/tests/components/bluetooth/test_usage.py
J. Nick Koston e890671192
Relocate Bluetooth manager to habluetooth library (#105110)
* Relocate Bluetooth manager to habluetooth library

* Relocate Bluetooth manager to habluetooth library

* Relocate Bluetooth manager to habluetooth library

* fixes

* fix patching time

* fix more tests

* fix more tests

* split

* Bump habluetooth to 0.7.0

changelog: https://github.com/Bluetooth-Devices/habluetooth/compare/v0.6.1...v0.7.0

This is the big change that will move the manager so the HA
PR that will follow this will be a bit larger than the rest of them
since the manager is connected to everything

* fix types

* fix types

* fix types

* fix patch targets

* fix flakey logbook tests (will need another PR)

* mock shutdown

* bump again

* value can be a float now

* Revert "value can be a float now"

This reverts commit b7e7127143.

* float
2023-12-11 15:42:00 -05:00

54 lines
1.4 KiB
Python

"""Tests for the Bluetooth integration."""
from unittest.mock import patch
import bleak
from habluetooth.usage import (
install_multiple_bleak_catcher,
uninstall_multiple_bleak_catcher,
)
from habluetooth.wrappers import HaBleakClientWrapper, HaBleakScannerWrapper
from homeassistant.core import HomeAssistant
from . import generate_ble_device
MOCK_BLE_DEVICE = generate_ble_device(
"00:00:00:00:00:00",
"any",
delegate="",
details={"path": "/dev/hci0/device"},
rssi=-127,
)
async def test_multiple_bleak_scanner_instances(hass: HomeAssistant) -> None:
"""Test creating multiple BleakScanners without an integration."""
install_multiple_bleak_catcher()
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)
async def test_wrapping_bleak_client(
hass: HomeAssistant, enable_bluetooth: None
) -> 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)