mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2024-12-22 16:48:04 +01:00
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:
parent
811b05ba05
commit
d6fd9b6cfd
@ -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
@ -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()
|
||||
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user