Add support for Button entities (#143)

This commit is contained in:
Jesse Hills 2021-11-29 13:59:23 +13:00 committed by GitHub
parent f68fc025a8
commit dcad9cdcb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 218 additions and 33 deletions

View File

@ -41,6 +41,7 @@ service APIConnection {
rpc number_command (NumberCommandRequest) returns (void) {}
rpc select_command (SelectCommandRequest) returns (void) {}
rpc siren_command (SirenCommandRequest) returns (void) {}
rpc button_command (ButtonCommandRequest) returns (void) {}
}
@ -976,3 +977,27 @@ message SirenCommandRequest {
bool has_volume = 8;
float volume = 9;
}
// ==================== BUTTON ====================
message ListEntitiesButtonResponse {
option (id) = 61;
option (source) = SOURCE_SERVER;
option (ifdef) = "USE_BUTTON";
string object_id = 1;
fixed32 key = 2;
string name = 3;
string unique_id = 4;
string icon = 5;
bool disabled_by_default = 6;
EntityCategory entity_category = 7;
}
message ButtonCommandRequest {
option (id) = 62;
option (source) = SOURCE_CLIENT;
option (ifdef) = "USE_BUTTON";
option (no_delay) = true;
fixed32 key = 1;
}

File diff suppressed because one or more lines are too long

View File

@ -16,6 +16,7 @@ from google.protobuf import message
from .api_pb2 import ( # type: ignore
BinarySensorStateResponse,
ButtonCommandRequest,
CameraImageRequest,
CameraImageResponse,
ClimateCommandRequest,
@ -33,6 +34,7 @@ from .api_pb2 import ( # type: ignore
LightCommandRequest,
LightStateResponse,
ListEntitiesBinarySensorResponse,
ListEntitiesButtonResponse,
ListEntitiesCameraResponse,
ListEntitiesClimateResponse,
ListEntitiesCoverResponse,
@ -71,6 +73,7 @@ from .model import (
APIVersion,
BinarySensorInfo,
BinarySensorState,
ButtonInfo,
CameraInfo,
CameraState,
ClimateFanMode,
@ -217,6 +220,7 @@ class APIClient:
self._check_authenticated()
response_types: Dict[Any, Optional[Type[EntityInfo]]] = {
ListEntitiesBinarySensorResponse: BinarySensorInfo,
ListEntitiesButtonResponse: ButtonInfo,
ListEntitiesCoverResponse: CoverInfo,
ListEntitiesFanResponse: FanInfo,
ListEntitiesLightResponse: LightInfo,
@ -594,6 +598,14 @@ class APIClient:
assert self._connection is not None
await self._connection.send_message(req)
async def button_command(self, key: int) -> None:
self._check_authenticated()
req = ButtonCommandRequest()
req.key = key
assert self._connection is not None
await self._connection.send_message(req)
async def execute_service(
self, service: UserService, data: ExecuteServiceDataType
) -> None:

View File

@ -1,5 +1,6 @@
from .api_pb2 import ( # type: ignore
BinarySensorStateResponse,
ButtonCommandRequest,
CameraImageRequest,
CameraImageResponse,
ClimateCommandRequest,
@ -24,6 +25,7 @@ from .api_pb2 import ( # type: ignore
LightCommandRequest,
LightStateResponse,
ListEntitiesBinarySensorResponse,
ListEntitiesButtonResponse,
ListEntitiesCameraResponse,
ListEntitiesClimateResponse,
ListEntitiesCoverResponse,
@ -165,4 +167,6 @@ MESSAGE_TYPE_TO_PROTO = {
55: ListEntitiesSirenResponse,
56: SirenStateResponse,
57: SirenCommandRequest,
61: ListEntitiesButtonResponse,
62: ButtonCommandRequest,
}

View File

@ -585,6 +585,14 @@ class SirenState(EntityState):
state: bool = False
# ==================== BUTTON ====================
@dataclass(frozen=True)
class ButtonInfo(EntityInfo):
pass
# ==================== INFO MAP ====================
COMPONENT_TYPE_TO_INFO: Dict[str, Type[EntityInfo]] = {
"binary_sensor": BinarySensorInfo,
"cover": CoverInfo,
@ -598,6 +606,7 @@ COMPONENT_TYPE_TO_INFO: Dict[str, Type[EntityInfo]] = {
"number": NumberInfo,
"select": SelectInfo,
"siren": SirenInfo,
"button": ButtonInfo,
}