mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2024-11-26 12:45:26 +01:00
Add coverage for bluetooth connection free responses (#673)
This commit is contained in:
parent
96781616b8
commit
0347302222
@ -618,20 +618,23 @@ class APIClient:
|
||||
|
||||
return unsub
|
||||
|
||||
def _on_bluetooth_connections_free_response(
|
||||
self,
|
||||
on_bluetooth_connections_free_update: Callable[[int, int], None],
|
||||
msg: BluetoothConnectionsFreeResponse,
|
||||
) -> None:
|
||||
on_bluetooth_connections_free_update(msg.free, msg.limit)
|
||||
|
||||
async def subscribe_bluetooth_connections_free(
|
||||
self, on_bluetooth_connections_free_update: Callable[[int, int], None]
|
||||
) -> Callable[[], None]:
|
||||
msg_types = (BluetoothConnectionsFreeResponse,)
|
||||
|
||||
def _on_bluetooth_connections_free_response(
|
||||
msg: BluetoothConnectionsFreeResponse,
|
||||
) -> None:
|
||||
on_bluetooth_connections_free_update(msg.free, msg.limit)
|
||||
|
||||
return self._get_connection().send_message_callback_response(
|
||||
SubscribeBluetoothConnectionsFreeRequest(),
|
||||
_on_bluetooth_connections_free_response,
|
||||
msg_types,
|
||||
partial(
|
||||
self._on_bluetooth_connections_free_response,
|
||||
on_bluetooth_connections_free_update,
|
||||
),
|
||||
(BluetoothConnectionsFreeResponse,),
|
||||
)
|
||||
|
||||
def _handle_timeout(self, fut: asyncio.Future[None]) -> None:
|
||||
|
@ -12,6 +12,7 @@ from aioesphomeapi._frame_helper.plain_text import APIPlaintextFrameHelper
|
||||
from aioesphomeapi.api_pb2 import (
|
||||
AlarmControlPanelCommandRequest,
|
||||
BinarySensorStateResponse,
|
||||
BluetoothConnectionsFreeResponse,
|
||||
BluetoothDeviceClearCacheResponse,
|
||||
BluetoothDeviceConnectionResponse,
|
||||
BluetoothDevicePairingResponse,
|
||||
@ -1298,6 +1299,30 @@ async def test_subscribe_bluetooth_le_raw_advertisements(
|
||||
unsub()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_subscribe_bluetooth_connections_free(
|
||||
api_client: tuple[
|
||||
APIClient, APIConnection, asyncio.Transport, APIPlaintextFrameHelper
|
||||
],
|
||||
) -> None:
|
||||
"""Test subscribe_bluetooth_connections_free."""
|
||||
client, connection, transport, protocol = api_client
|
||||
connections = []
|
||||
|
||||
def on_bluetooth_connections_free(free: int, limit: int) -> None:
|
||||
connections.append((free, limit))
|
||||
|
||||
unsub = await client.subscribe_bluetooth_connections_free(
|
||||
on_bluetooth_connections_free
|
||||
)
|
||||
await asyncio.sleep(0)
|
||||
response: message.Message = BluetoothConnectionsFreeResponse(free=2, limit=3)
|
||||
protocol.data_received(generate_plaintext_packet(response))
|
||||
|
||||
assert connections == [(2, 3)]
|
||||
unsub()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_subscribe_logs(auth_client: APIClient) -> None:
|
||||
send = patch_response_callback(auth_client)
|
||||
|
Loading…
Reference in New Issue
Block a user