forked from platypush/platypush
Fabio Manganiello
2411b961e8
- Merged together Bluetooth legacy and BLE plugins and scanners. - Introduced Theengs as a dependency to infer BLE device types and create sub-entities appropriately. - Using `BluetoothDevice` and `BluetoothService` entities as the bread and butter for all the Bluetooth plugin's components. - Using a shared cache of devices and services between the legacy and BLE integrations, with merging/coalescing logic included. - Extended list of discoverable services to include all those officially supported by the Bluetooth specs. - Instantiate a separate pool of workers to discover services. - Refactor of the Bluetooth events - all of them are now instantiated from a single `BluetoothDevice` object.
41 lines
938 B
Python
41 lines
938 B
Python
from typing import Dict, Iterable, Optional, Tuple
|
|
from typing_extensions import override
|
|
|
|
from bleak.backends.device import BLEDevice
|
|
|
|
from .._cache import BaseCache
|
|
|
|
|
|
class DeviceCache(BaseCache):
|
|
"""
|
|
Cache used to store scanned Bluetooth devices as :class:`BLEDevice`.
|
|
"""
|
|
|
|
_by_address: Dict[str, BLEDevice]
|
|
_by_name: Dict[str, BLEDevice]
|
|
|
|
@property
|
|
@override
|
|
def _address_field(self) -> str:
|
|
return 'address'
|
|
|
|
@property
|
|
@override
|
|
def _name_field(self) -> str:
|
|
return 'name'
|
|
|
|
@override
|
|
def get(self, device: str) -> Optional[BLEDevice]:
|
|
return super().get(device)
|
|
|
|
@override
|
|
def add(self, device: BLEDevice) -> BLEDevice:
|
|
return super().add(device)
|
|
|
|
@override
|
|
def values(self) -> Iterable[BLEDevice]:
|
|
return super().values()
|
|
|
|
@override
|
|
def items(self) -> Iterable[Tuple[str, BLEDevice]]:
|
|
return super().items()
|