1
mirror of https://github.com/home-assistant/core synced 2024-07-30 21:18:57 +02:00
ha-core/homeassistant/components/esphome/bluetooth/service.py
J. Nick Koston 7042d6d35b
Add ESPHome BleakClient (#78911)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2022-09-28 08:06:30 -10:00

41 lines
1.3 KiB
Python

"""BleakGATTServiceESPHome."""
from __future__ import annotations
from aioesphomeapi.model import BluetoothGATTService
from bleak.backends.characteristic import BleakGATTCharacteristic
from bleak.backends.service import BleakGATTService
class BleakGATTServiceESPHome(BleakGATTService):
"""GATT Characteristic implementation for the ESPHome backend."""
obj: BluetoothGATTService
def __init__(self, obj: BluetoothGATTService) -> None:
"""Init a BleakGATTServiceESPHome."""
super().__init__(obj) # type: ignore[no-untyped-call]
self.__characteristics: list[BleakGATTCharacteristic] = []
self.__handle: int = self.obj.handle
@property
def handle(self) -> int:
"""Integer handle of this service."""
return self.__handle
@property
def uuid(self) -> str:
"""UUID for this service."""
return self.obj.uuid
@property
def characteristics(self) -> list[BleakGATTCharacteristic]:
"""List of characteristics for this service."""
return self.__characteristics
def add_characteristic(self, characteristic: BleakGATTCharacteristic) -> None:
"""Add a :py:class:`~BleakGATTCharacteristicESPHome` to the service.
Should not be used by end user, but rather by `bleak` itself.
"""
self.__characteristics.append(characteristic)