Expand coverage for bluetooth GATT services (#742)

This commit is contained in:
J. Nick Koston 2023-11-26 16:34:28 -06:00 committed by GitHub
parent f280efba8a
commit 0fab7a6b99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 8 deletions

View File

@ -78,12 +78,13 @@ class APIModelBase:
def from_dict(
cls: type[_V], data: dict[str, Any], *, ignore_missing: bool = True
) -> _V:
init_args = {
f.name: data[f.name]
for f in cached_fields(cls) # type: ignore[arg-type]
if f.name in data or (not ignore_missing)
}
return cls(**init_args)
return cls(
**{
f.name: data[f.name]
for f in cached_fields(cls) # type: ignore[arg-type]
if f.name in data or (not ignore_missing)
}
)
@classmethod
def from_pb(cls: type[_V], data: Any) -> _V:

View File

@ -19,6 +19,8 @@ from aioesphomeapi.api_pb2 import (
BluetoothDevicePairingResponse,
BluetoothDeviceRequest,
BluetoothDeviceUnpairingResponse,
BluetoothGATTCharacteristic,
BluetoothGATTDescriptor,
BluetoothGATTErrorResponse,
BluetoothGATTGetServicesDoneResponse,
BluetoothGATTGetServicesResponse,
@ -1124,7 +1126,16 @@ async def test_bluetooth_gatt_get_services(
services_task = asyncio.create_task(client.bluetooth_gatt_get_services(1234))
await asyncio.sleep(0)
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(
address=1234, services=[service1]
@ -1134,9 +1145,10 @@ async def test_bluetooth_gatt_get_services(
mock_data_received(protocol, generate_plaintext_packet(done_response))
services = await services_task
service = BluetoothGATTServiceModel.from_pb(service1)
assert services == ESPHomeBluetoothGATTServices(
address=1234,
services=[BluetoothGATTServiceModel(uuid=[1, 1], handle=1, characteristics=[])],
services=[service],
)