platypush/platypush/plugins/bluetooth/_ble/_cache.py
Fabio Manganiello 2411b961e8
[WIP] Big, big refactor of the Bluetooth integration.
- 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.
2023-03-13 02:31:21 +01:00

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()