mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2025-02-17 01:51:23 +01:00
Add test coverage for bluetooth GATT notify (#668)
This commit is contained in:
parent
b8427c4cbb
commit
cf2fd3c92a
@ -18,6 +18,8 @@ from aioesphomeapi.api_pb2 import (
|
|||||||
BluetoothGATTErrorResponse,
|
BluetoothGATTErrorResponse,
|
||||||
BluetoothGATTGetServicesDoneResponse,
|
BluetoothGATTGetServicesDoneResponse,
|
||||||
BluetoothGATTGetServicesResponse,
|
BluetoothGATTGetServicesResponse,
|
||||||
|
BluetoothGATTNotifyDataResponse,
|
||||||
|
BluetoothGATTNotifyResponse,
|
||||||
BluetoothGATTReadResponse,
|
BluetoothGATTReadResponse,
|
||||||
BluetoothGATTService,
|
BluetoothGATTService,
|
||||||
BluetoothGATTWriteResponse,
|
BluetoothGATTWriteResponse,
|
||||||
@ -1128,6 +1130,45 @@ async def test_bluetooth_gatt_get_services_errors(
|
|||||||
await services_task
|
await services_task
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.xfail(reason="There is a race condition here")
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_bluetooth_gatt_start_notify(
|
||||||
|
api_client: tuple[
|
||||||
|
APIClient, APIConnection, asyncio.Transport, APIPlaintextFrameHelper
|
||||||
|
],
|
||||||
|
) -> None:
|
||||||
|
"""Test bluetooth_gatt_start_notify."""
|
||||||
|
client, connection, transport, protocol = api_client
|
||||||
|
notifies = []
|
||||||
|
|
||||||
|
def on_bluetooth_gatt_notify(handle: int, data: bytearray) -> None:
|
||||||
|
notifies.append((handle, data))
|
||||||
|
|
||||||
|
notify_task = asyncio.create_task(
|
||||||
|
client.bluetooth_gatt_start_notify(1234, 1, on_bluetooth_gatt_notify)
|
||||||
|
)
|
||||||
|
await asyncio.sleep(0)
|
||||||
|
notify_response: message.Message = BluetoothGATTNotifyResponse(
|
||||||
|
address=1234, handle=1
|
||||||
|
)
|
||||||
|
data_response: message.Message = BluetoothGATTNotifyDataResponse(
|
||||||
|
address=1234, handle=1, data=b"gotit"
|
||||||
|
)
|
||||||
|
protocol.data_received(
|
||||||
|
generate_plaintext_packet(notify_response)
|
||||||
|
+ generate_plaintext_packet(data_response)
|
||||||
|
)
|
||||||
|
|
||||||
|
await notify_task
|
||||||
|
assert notifies == [(1, b"gotit")]
|
||||||
|
|
||||||
|
second_data_response: message.Message = BluetoothGATTNotifyDataResponse(
|
||||||
|
address=1234, handle=1, data=b"after finished"
|
||||||
|
)
|
||||||
|
protocol.data_received(generate_plaintext_packet(second_data_response))
|
||||||
|
assert notifies == [(1, b"gotit"), (1, b"after finished")]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_subscribe_logs(auth_client: APIClient) -> None:
|
async def test_subscribe_logs(auth_client: APIClient) -> None:
|
||||||
send = patch_response_callback(auth_client)
|
send = patch_response_callback(auth_client)
|
||||||
|
Loading…
Reference in New Issue
Block a user