Expand coverage for bluetooth GATT services (#742)
This commit is contained in:
parent
f280efba8a
commit
0fab7a6b99
|
@ -78,12 +78,13 @@ class APIModelBase:
|
||||||
def from_dict(
|
def from_dict(
|
||||||
cls: type[_V], data: dict[str, Any], *, ignore_missing: bool = True
|
cls: type[_V], data: dict[str, Any], *, ignore_missing: bool = True
|
||||||
) -> _V:
|
) -> _V:
|
||||||
init_args = {
|
return cls(
|
||||||
f.name: data[f.name]
|
**{
|
||||||
for f in cached_fields(cls) # type: ignore[arg-type]
|
f.name: data[f.name]
|
||||||
if f.name in data or (not ignore_missing)
|
for f in cached_fields(cls) # type: ignore[arg-type]
|
||||||
}
|
if f.name in data or (not ignore_missing)
|
||||||
return cls(**init_args)
|
}
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_pb(cls: type[_V], data: Any) -> _V:
|
def from_pb(cls: type[_V], data: Any) -> _V:
|
||||||
|
|
|
@ -19,6 +19,8 @@ from aioesphomeapi.api_pb2 import (
|
||||||
BluetoothDevicePairingResponse,
|
BluetoothDevicePairingResponse,
|
||||||
BluetoothDeviceRequest,
|
BluetoothDeviceRequest,
|
||||||
BluetoothDeviceUnpairingResponse,
|
BluetoothDeviceUnpairingResponse,
|
||||||
|
BluetoothGATTCharacteristic,
|
||||||
|
BluetoothGATTDescriptor,
|
||||||
BluetoothGATTErrorResponse,
|
BluetoothGATTErrorResponse,
|
||||||
BluetoothGATTGetServicesDoneResponse,
|
BluetoothGATTGetServicesDoneResponse,
|
||||||
BluetoothGATTGetServicesResponse,
|
BluetoothGATTGetServicesResponse,
|
||||||
|
@ -1124,7 +1126,16 @@ async def test_bluetooth_gatt_get_services(
|
||||||
services_task = asyncio.create_task(client.bluetooth_gatt_get_services(1234))
|
services_task = asyncio.create_task(client.bluetooth_gatt_get_services(1234))
|
||||||
await asyncio.sleep(0)
|
await asyncio.sleep(0)
|
||||||
service1: message.Message = BluetoothGATTService(
|
service1: message.Message = BluetoothGATTService(
|
||||||
uuid=[1, 1], handle=1, characteristics=[]
|
uuid=[1, 1],
|
||||||
|
handle=1,
|
||||||
|
characteristics=[
|
||||||
|
BluetoothGATTCharacteristic(
|
||||||
|
uuid=[1, 2],
|
||||||
|
handle=2,
|
||||||
|
properties=1,
|
||||||
|
descriptors=[BluetoothGATTDescriptor(uuid=[1, 3], handle=3)],
|
||||||
|
)
|
||||||
|
],
|
||||||
)
|
)
|
||||||
response: message.Message = BluetoothGATTGetServicesResponse(
|
response: message.Message = BluetoothGATTGetServicesResponse(
|
||||||
address=1234, services=[service1]
|
address=1234, services=[service1]
|
||||||
|
@ -1134,9 +1145,10 @@ async def test_bluetooth_gatt_get_services(
|
||||||
mock_data_received(protocol, generate_plaintext_packet(done_response))
|
mock_data_received(protocol, generate_plaintext_packet(done_response))
|
||||||
|
|
||||||
services = await services_task
|
services = await services_task
|
||||||
|
service = BluetoothGATTServiceModel.from_pb(service1)
|
||||||
assert services == ESPHomeBluetoothGATTServices(
|
assert services == ESPHomeBluetoothGATTServices(
|
||||||
address=1234,
|
address=1234,
|
||||||
services=[BluetoothGATTServiceModel(uuid=[1, 1], handle=1, characteristics=[])],
|
services=[service],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue