Refactor raw Bluetooth advs subscriptions (#797)
This commit is contained in:
parent
1672302ac2
commit
cf83582ef1
|
@ -31,7 +31,6 @@ from .api_pb2 import ( # type: ignore
|
||||||
BluetoothGATTWriteRequest,
|
BluetoothGATTWriteRequest,
|
||||||
BluetoothGATTWriteResponse,
|
BluetoothGATTWriteResponse,
|
||||||
BluetoothLEAdvertisementResponse,
|
BluetoothLEAdvertisementResponse,
|
||||||
BluetoothLERawAdvertisement,
|
|
||||||
BluetoothLERawAdvertisementsResponse,
|
BluetoothLERawAdvertisementsResponse,
|
||||||
ButtonCommandRequest,
|
ButtonCommandRequest,
|
||||||
CameraImageRequest,
|
CameraImageRequest,
|
||||||
|
@ -72,7 +71,6 @@ from .api_pb2 import ( # type: ignore
|
||||||
VoiceAssistantResponse,
|
VoiceAssistantResponse,
|
||||||
)
|
)
|
||||||
from .client_callbacks import (
|
from .client_callbacks import (
|
||||||
on_ble_raw_advertisement_response,
|
|
||||||
on_bluetooth_connections_free_response,
|
on_bluetooth_connections_free_response,
|
||||||
on_bluetooth_device_connection_response,
|
on_bluetooth_device_connection_response,
|
||||||
on_bluetooth_gatt_notify_data_response,
|
on_bluetooth_gatt_notify_data_response,
|
||||||
|
@ -495,13 +493,13 @@ class APIClient:
|
||||||
return partial(self._unsub_bluetooth_advertisements, unsub_callback)
|
return partial(self._unsub_bluetooth_advertisements, unsub_callback)
|
||||||
|
|
||||||
async def subscribe_bluetooth_le_raw_advertisements(
|
async def subscribe_bluetooth_le_raw_advertisements(
|
||||||
self, on_advertisements: Callable[[list[BluetoothLERawAdvertisement]], None]
|
self, on_advertisements: Callable[[BluetoothLERawAdvertisementsResponse], None]
|
||||||
) -> Callable[[], None]:
|
) -> Callable[[], None]:
|
||||||
unsub_callback = self._get_connection().send_message_callback_response(
|
unsub_callback = self._get_connection().send_message_callback_response(
|
||||||
SubscribeBluetoothLEAdvertisementsRequest(
|
SubscribeBluetoothLEAdvertisementsRequest(
|
||||||
flags=BluetoothProxySubscriptionFlag.RAW_ADVERTISEMENTS
|
flags=BluetoothProxySubscriptionFlag.RAW_ADVERTISEMENTS
|
||||||
),
|
),
|
||||||
partial(on_ble_raw_advertisement_response, on_advertisements),
|
on_advertisements,
|
||||||
(BluetoothLERawAdvertisementsResponse,),
|
(BluetoothLERawAdvertisementsResponse,),
|
||||||
)
|
)
|
||||||
return partial(self._unsub_bluetooth_advertisements, unsub_callback)
|
return partial(self._unsub_bluetooth_advertisements, unsub_callback)
|
||||||
|
|
|
@ -17,8 +17,6 @@ from .api_pb2 import ( # type: ignore
|
||||||
BluetoothGATTReadResponse,
|
BluetoothGATTReadResponse,
|
||||||
BluetoothGATTWriteResponse,
|
BluetoothGATTWriteResponse,
|
||||||
BluetoothLEAdvertisementResponse,
|
BluetoothLEAdvertisementResponse,
|
||||||
BluetoothLERawAdvertisement,
|
|
||||||
BluetoothLERawAdvertisementsResponse,
|
|
||||||
CameraImageResponse,
|
CameraImageResponse,
|
||||||
HomeassistantServiceResponse,
|
HomeassistantServiceResponse,
|
||||||
SubscribeHomeAssistantStateResponse,
|
SubscribeHomeAssistantStateResponse,
|
||||||
|
@ -72,13 +70,6 @@ def on_bluetooth_le_advertising_response(
|
||||||
on_bluetooth_le_advertisement(BluetoothLEAdvertisement.from_pb(msg)) # type: ignore[misc]
|
on_bluetooth_le_advertisement(BluetoothLEAdvertisement.from_pb(msg)) # type: ignore[misc]
|
||||||
|
|
||||||
|
|
||||||
def on_ble_raw_advertisement_response(
|
|
||||||
on_advertisements: Callable[[list[BluetoothLERawAdvertisement]], None],
|
|
||||||
msg: BluetoothLERawAdvertisementsResponse,
|
|
||||||
) -> None:
|
|
||||||
on_advertisements(msg.advertisements)
|
|
||||||
|
|
||||||
|
|
||||||
def on_bluetooth_connections_free_response(
|
def on_bluetooth_connections_free_response(
|
||||||
on_bluetooth_connections_free_update: Callable[[int, int], None],
|
on_bluetooth_connections_free_update: Callable[[int, int], None],
|
||||||
msg: BluetoothConnectionsFreeResponse,
|
msg: BluetoothConnectionsFreeResponse,
|
||||||
|
|
|
@ -1641,9 +1641,9 @@ async def test_subscribe_bluetooth_le_raw_advertisements(
|
||||||
adv_groups = []
|
adv_groups = []
|
||||||
|
|
||||||
def on_raw_bluetooth_le_advertisements(
|
def on_raw_bluetooth_le_advertisements(
|
||||||
advs: list[BluetoothLERawAdvertisementsResponse],
|
advs: BluetoothLERawAdvertisementsResponse,
|
||||||
) -> None:
|
) -> None:
|
||||||
adv_groups.append(advs)
|
adv_groups.append(advs.advertisements)
|
||||||
|
|
||||||
unsub = await client.subscribe_bluetooth_le_raw_advertisements(
|
unsub = await client.subscribe_bluetooth_le_raw_advertisements(
|
||||||
on_raw_bluetooth_le_advertisements
|
on_raw_bluetooth_le_advertisements
|
||||||
|
|
Loading…
Reference in New Issue