diff --git a/aioesphomeapi/model.py b/aioesphomeapi/model.py index 0bbf219..f9826f6 100644 --- a/aioesphomeapi/model.py +++ b/aioesphomeapi/model.py @@ -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: diff --git a/tests/test_client.py b/tests/test_client.py index 533616c..dae4d6f 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -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], )