mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2024-09-27 04:22:46 +02:00
Small refactor to GATT read to reduce code (#773)
This commit is contained in:
parent
5ba404df48
commit
7c7bdfc585
@ -782,7 +782,7 @@ class APIClient:
|
|||||||
timeout: float = DEFAULT_BLE_TIMEOUT,
|
timeout: float = DEFAULT_BLE_TIMEOUT,
|
||||||
) -> bytearray:
|
) -> bytearray:
|
||||||
return await self._bluetooth_gatt_read(
|
return await self._bluetooth_gatt_read(
|
||||||
BluetoothGATTReadRequest(),
|
BluetoothGATTReadRequest,
|
||||||
address,
|
address,
|
||||||
handle,
|
handle,
|
||||||
timeout,
|
timeout,
|
||||||
@ -796,7 +796,7 @@ class APIClient:
|
|||||||
) -> bytearray:
|
) -> bytearray:
|
||||||
"""Read a GATT descriptor."""
|
"""Read a GATT descriptor."""
|
||||||
return await self._bluetooth_gatt_read(
|
return await self._bluetooth_gatt_read(
|
||||||
BluetoothGATTReadDescriptorRequest(),
|
BluetoothGATTReadDescriptorRequest,
|
||||||
address,
|
address,
|
||||||
handle,
|
handle,
|
||||||
timeout,
|
timeout,
|
||||||
@ -804,18 +804,17 @@ class APIClient:
|
|||||||
|
|
||||||
async def _bluetooth_gatt_read(
|
async def _bluetooth_gatt_read(
|
||||||
self,
|
self,
|
||||||
req: BluetoothGATTReadDescriptorRequest | BluetoothGATTReadRequest,
|
req_type: type[BluetoothGATTReadDescriptorRequest]
|
||||||
|
| type[BluetoothGATTReadRequest],
|
||||||
address: int,
|
address: int,
|
||||||
handle: int,
|
handle: int,
|
||||||
timeout: float,
|
timeout: float,
|
||||||
) -> bytearray:
|
) -> bytearray:
|
||||||
"""Perform a GATT read."""
|
"""Perform a GATT read."""
|
||||||
req.address = address
|
|
||||||
req.handle = handle
|
|
||||||
resp = await self._send_bluetooth_message_await_response(
|
resp = await self._send_bluetooth_message_await_response(
|
||||||
address,
|
address,
|
||||||
handle,
|
handle,
|
||||||
req,
|
req_type(address=address, handle=handle),
|
||||||
BluetoothGATTReadResponse,
|
BluetoothGATTReadResponse,
|
||||||
timeout,
|
timeout,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user