Add the ability to clear the cache to the API (#410)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
J. Nick Koston 2023-03-26 11:47:21 -10:00 committed by GitHub
parent 811b05ba05
commit d6fd9b6cfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 106 additions and 45 deletions

View File

@ -1184,6 +1184,7 @@ enum BluetoothDeviceRequestType {
BLUETOOTH_DEVICE_REQUEST_TYPE_UNPAIR = 3;
BLUETOOTH_DEVICE_REQUEST_TYPE_CONNECT_V3_WITH_CACHE = 4;
BLUETOOTH_DEVICE_REQUEST_TYPE_CONNECT_V3_WITHOUT_CACHE = 5;
BLUETOOTH_DEVICE_REQUEST_TYPE_CLEAR_CACHE = 6;
}
message BluetoothDeviceRequest {
@ -1392,3 +1393,13 @@ message UnsubscribeBluetoothLEAdvertisementsRequest {
option (id) = 87;
option (source) = SOURCE_CLIENT;
}
message BluetoothDeviceClearCacheResponse {
option (id) = 88;
option (source) = SOURCE_SERVER;
option (ifdef) = "USE_BLUETOOTH_PROXY";
uint64 address = 1;
bool success = 2;
int32 error = 3;
}

File diff suppressed because one or more lines are too long

View File

@ -21,6 +21,7 @@ from google.protobuf import message
from .api_pb2 import ( # type: ignore
BinarySensorStateResponse,
BluetoothConnectionsFreeResponse,
BluetoothDeviceClearCacheResponse,
BluetoothDeviceConnectionResponse,
BluetoothDevicePairingResponse,
BluetoothDeviceRequest,
@ -111,6 +112,7 @@ from .model import (
BinarySensorInfo,
BinarySensorState,
BluetoothConnectionsFree,
BluetoothDeviceClearCache,
BluetoothDeviceConnection,
BluetoothDevicePairing,
BluetoothDeviceRequestType,
@ -654,6 +656,31 @@ class APIClient:
return BluetoothDeviceUnpairing.from_pb(response)
async def bluetooth_device_clear_cache(
self, address: int, timeout: float = DEFAULT_BLE_TIMEOUT
) -> BluetoothDeviceClearCache:
self._check_authenticated()
assert self._connection is not None
def predicate_func(msg: BluetoothDeviceClearCacheResponse) -> bool:
return bool(msg.address == address)
responses = await self._connection.send_message_await_response_complex(
BluetoothDeviceRequest(
address=address, request_type=BluetoothDeviceRequestType.CLEAR_CACHE
),
predicate_func,
predicate_func,
(BluetoothDeviceClearCacheResponse,),
timeout=timeout,
)
assert len(responses) == 1
response = responses[0]
return BluetoothDeviceClearCache.from_pb(response)
async def bluetooth_device_disconnect(self, address: int) -> None:
self._check_authenticated()

View File

@ -5,6 +5,7 @@ from aioesphomeapi.model import BluetoothGATTError
from .api_pb2 import ( # type: ignore
BinarySensorStateResponse,
BluetoothConnectionsFreeResponse,
BluetoothDeviceClearCacheResponse,
BluetoothDeviceConnectionResponse,
BluetoothDevicePairingResponse,
BluetoothDeviceRequest,
@ -308,4 +309,5 @@ MESSAGE_TYPE_TO_PROTO = {
85: BluetoothDevicePairingResponse,
86: BluetoothDeviceUnpairingResponse,
87: UnsubscribeBluetoothLEAdvertisementsRequest,
88: BluetoothDeviceClearCacheResponse,
}

View File

@ -881,6 +881,13 @@ class BluetoothDeviceUnpairing(APIModelBase):
error: int = 0
@dataclass(frozen=True)
class BluetoothDeviceClearCache(APIModelBase):
address: int = 0
success: bool = False
error: int = 0
@dataclass(frozen=True)
class BluetoothGATTRead(APIModelBase):
address: int = 0
@ -979,6 +986,7 @@ class BluetoothDeviceRequestType(APIIntEnum):
UNPAIR = 3
CONNECT_V3_WITH_CACHE = 4
CONNECT_V3_WITHOUT_CACHE = 5
CLEAR_CACHE = 6
class LogLevel(APIIntEnum):