feat: Unsubscribe from BLE advertisements fully on unsub (#409)

This commit is contained in:
richardhopton 2023-03-26 13:35:11 -07:00 committed by GitHub
parent 5ebd8956ec
commit 4bb8fbbed1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 45 deletions

View File

@ -53,6 +53,8 @@ service APIConnection {
rpc bluetooth_gatt_read_descriptor(BluetoothGATTReadDescriptorRequest) returns (void) {}
rpc bluetooth_gatt_write_descriptor(BluetoothGATTWriteDescriptorRequest) returns (void) {}
rpc bluetooth_gatt_notify(BluetoothGATTNotifyRequest) returns (void) {}
rpc unsubscribe_bluetooth_le_advertisements(UnsubscribeBluetoothLEAdvertisementsRequest) returns (void) {}
}
@ -1385,3 +1387,8 @@ message BluetoothDeviceUnpairingResponse {
bool success = 2;
int32 error = 3;
}
message UnsubscribeBluetoothLEAdvertisementsRequest {
option (id) = 87;
option (source) = SOURCE_CLIENT;
}

File diff suppressed because one or more lines are too long

View File

@ -96,6 +96,7 @@ from .api_pb2 import ( # type: ignore
SwitchCommandRequest,
SwitchStateResponse,
TextSensorStateResponse,
UnsubscribeBluetoothLEAdvertisementsRequest,
)
from .connection import APIConnection, ConnectionParams
from .core import (
@ -468,6 +469,9 @@ class APIClient:
def unsub() -> None:
if self._connection is not None:
self._connection.remove_message_callback(on_msg, msg_types)
self._connection.send_message(
UnsubscribeBluetoothLEAdvertisementsRequest()
)
return unsub

View File

@ -89,6 +89,7 @@ from .api_pb2 import ( # type: ignore
SwitchCommandRequest,
SwitchStateResponse,
TextSensorStateResponse,
UnsubscribeBluetoothLEAdvertisementsRequest,
)
TWO_CHAR = re.compile(r".{2}")
@ -306,4 +307,5 @@ MESSAGE_TYPE_TO_PROTO = {
84: BluetoothGATTNotifyResponse,
85: BluetoothDevicePairingResponse,
86: BluetoothDeviceUnpairingResponse,
87: UnsubscribeBluetoothLEAdvertisementsRequest,
}