core/homeassistant/components/bluetooth/usage.py

20 lines
582 B
Python
Raw Normal View History

"""bluetooth usage utility to handle multiple instances."""
2022-07-30 00:53:33 +00:00
from __future__ import annotations
import bleak
from .models import HaBleakScannerWrapper
ORIGINAL_BLEAK_SCANNER = bleak.BleakScanner
def install_multiple_bleak_catcher() -> None:
"""Wrap the bleak classes to return the shared instance if multiple instances are detected."""
2022-07-30 00:53:33 +00:00
bleak.BleakScanner = HaBleakScannerWrapper # type: ignore[misc, assignment]
def uninstall_multiple_bleak_catcher() -> None:
"""Unwrap the bleak classes."""
2022-07-30 00:53:33 +00:00
bleak.BleakScanner = ORIGINAL_BLEAK_SCANNER # type: ignore[misc]