Skip to content

Commit

Permalink
Include Bluetooth connection slot allocations in connections free mes…
Browse files Browse the repository at this point in the history
…sage (#1038)
  • Loading branch information
bdraco authored Jan 28, 2025
1 parent 13c71fc commit a775831
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 159 deletions.
1 change: 1 addition & 0 deletions aioesphomeapi/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,7 @@ message BluetoothConnectionsFreeResponse {

uint32 free = 1;
uint32 limit = 2;
repeated uint64 allocated = 3;
}

message BluetoothGATTErrorResponse {
Expand Down
304 changes: 152 additions & 152 deletions aioesphomeapi/api_pb2.py

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion aioesphomeapi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@ def subscribe_bluetooth_le_raw_advertisements(
return partial(self._unsub_bluetooth_advertisements, unsub_callback)

def subscribe_bluetooth_connections_free(
self, on_bluetooth_connections_free_update: Callable[[int, int], None]
self,
on_bluetooth_connections_free_update: Callable[[int, int, list[int]], None],
) -> Callable[[], None]:
return self._get_connection().send_message_callback_response(
SubscribeBluetoothConnectionsFreeRequest(),
Expand Down
4 changes: 2 additions & 2 deletions aioesphomeapi/client_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ def on_bluetooth_le_advertising_response(


def on_bluetooth_connections_free_response(
on_bluetooth_connections_free_update: Callable[[int, int], None],
on_bluetooth_connections_free_update: Callable[[int, int, list[int]], None],
msg: BluetoothConnectionsFreeResponse,
) -> None:
on_bluetooth_connections_free_update(msg.free, msg.limit)
on_bluetooth_connections_free_update(msg.free, msg.limit, list(msg.allocated))


def on_bluetooth_gatt_notify_data_response(
Expand Down
12 changes: 8 additions & 4 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1858,15 +1858,19 @@ async def 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))
def on_bluetooth_connections_free(
free: int, limit: int, allocated: list[int]
) -> None:
connections.append((free, limit, allocated))

unsub = client.subscribe_bluetooth_connections_free(on_bluetooth_connections_free)
await asyncio.sleep(0)
response: message.Message = BluetoothConnectionsFreeResponse(free=2, limit=3)
response: message.Message = BluetoothConnectionsFreeResponse(
free=2, limit=3, allocated=[1234, 5678]
)
mock_data_received(protocol, generate_plaintext_packet(response))

assert connections == [(2, 3)]
assert connections == [(2, 3, [1234, 5678])]
unsub()


Expand Down

0 comments on commit a775831

Please sign in to comment.