From 7c7bdfc58572436c762bffe4290a93b449a7b4e6 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 28 Nov 2023 08:28:00 -0600 Subject: [PATCH] Small refactor to GATT read to reduce code (#773) --- aioesphomeapi/client.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/aioesphomeapi/client.py b/aioesphomeapi/client.py index 536a925..c7b6607 100644 --- a/aioesphomeapi/client.py +++ b/aioesphomeapi/client.py @@ -782,7 +782,7 @@ class APIClient: timeout: float = DEFAULT_BLE_TIMEOUT, ) -> bytearray: return await self._bluetooth_gatt_read( - BluetoothGATTReadRequest(), + BluetoothGATTReadRequest, address, handle, timeout, @@ -796,7 +796,7 @@ class APIClient: ) -> bytearray: """Read a GATT descriptor.""" return await self._bluetooth_gatt_read( - BluetoothGATTReadDescriptorRequest(), + BluetoothGATTReadDescriptorRequest, address, handle, timeout, @@ -804,18 +804,17 @@ class APIClient: async def _bluetooth_gatt_read( self, - req: BluetoothGATTReadDescriptorRequest | BluetoothGATTReadRequest, + req_type: type[BluetoothGATTReadDescriptorRequest] + | type[BluetoothGATTReadRequest], address: int, handle: int, timeout: float, ) -> bytearray: """Perform a GATT read.""" - req.address = address - req.handle = handle resp = await self._send_bluetooth_message_await_response( address, handle, - req, + req_type(address=address, handle=handle), BluetoothGATTReadResponse, timeout, )