Add support for siren entities (#97)

This commit is contained in:
Jesse Hills 2021-09-09 13:11:51 +12:00 committed by GitHub
parent 0891c67bfb
commit 2350ac78b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 378 additions and 31 deletions

View File

@ -40,6 +40,7 @@ service APIConnection {
rpc climate_command (ClimateCommandRequest) returns (void) {}
rpc number_command (NumberCommandRequest) returns (void) {}
rpc select_command (SelectCommandRequest) returns (void) {}
rpc siren_command (SirenCommandRequest) returns (void) {}
}
@ -904,3 +905,46 @@ message SelectCommandRequest {
fixed32 key = 1;
string state = 2;
}
// ==================== SIREN ====================
message ListEntitiesSirenResponse {
option (id) = 55;
option (source) = SOURCE_SERVER;
option (ifdef) = "USE_SIREN";
string object_id = 1;
fixed32 key = 2;
string name = 3;
string unique_id = 4;
string icon = 5;
bool disabled_by_default = 6;
repeated string tones = 7;
bool supports_duration = 8;
bool supports_volume = 9;
}
message SirenStateResponse {
option (id) = 56;
option (source) = SOURCE_SERVER;
option (ifdef) = "USE_SIREN";
option (no_delay) = true;
fixed32 key = 1;
bool state = 2;
}
message SirenCommandRequest {
option (id) = 57;
option (source) = SOURCE_CLIENT;
option (ifdef) = "USE_SIREN";
option (no_delay) = true;
fixed32 key = 1;
bool has_state = 2;
bool state = 3;
bool has_tone = 4;
string tone = 5;
bool has_duration = 6;
uint32 duration = 7;
bool has_volume = 8;
float volume = 9;
}

File diff suppressed because one or more lines are too long

View File

@ -45,6 +45,7 @@ from .api_pb2 import ( # type: ignore
ListEntitiesSelectResponse,
ListEntitiesSensorResponse,
ListEntitiesServicesResponse,
ListEntitiesSirenResponse,
ListEntitiesSwitchResponse,
ListEntitiesTextSensorResponse,
NumberCommandRequest,
@ -52,6 +53,8 @@ from .api_pb2 import ( # type: ignore
SelectCommandRequest,
SelectStateResponse,
SensorStateResponse,
SirenCommandRequest,
SirenStateResponse,
SubscribeHomeassistantServicesRequest,
SubscribeHomeAssistantStateResponse,
SubscribeHomeAssistantStatesRequest,
@ -97,6 +100,8 @@ from .model import (
SelectState,
SensorInfo,
SensorState,
SirenInfo,
SirenState,
SwitchInfo,
SwitchState,
TextSensorInfo,
@ -228,6 +233,7 @@ class APIClient:
ListEntitiesNumberResponse: NumberInfo,
ListEntitiesSelectResponse: SelectInfo,
ListEntitiesSensorResponse: SensorInfo,
ListEntitiesSirenResponse: SirenInfo,
ListEntitiesSwitchResponse: SwitchInfo,
ListEntitiesTextSensorResponse: TextSensorInfo,
ListEntitiesServicesResponse: None,
@ -272,6 +278,7 @@ class APIClient:
NumberStateResponse: NumberState,
SelectStateResponse: SelectState,
SensorStateResponse: SensorState,
SirenStateResponse: SirenState,
SwitchStateResponse: SwitchState,
TextSensorStateResponse: TextSensorState,
ClimateStateResponse: ClimateState,
@ -570,6 +577,33 @@ class APIClient:
assert self._connection is not None
await self._connection.send_message(req)
async def siren_command(
self,
key: int,
state: Optional[bool] = None,
tone: Optional[str] = None,
volume: Optional[float] = None,
duration: Optional[int] = None,
) -> None:
self._check_authenticated()
req = SirenCommandRequest()
req.key = key
if state is not None:
req.state = state
req.has_state = True
if tone is not None:
req.tone = tone
req.has_tone = True
if volume is not None:
req.volume = volume
req.has_volume = True
if duration is not None:
req.duration = duration
req.has_duration = True
assert self._connection is not None
await self._connection.send_message(req)
async def execute_service(
self, service: UserService, data: ExecuteServiceDataType
) -> None:

View File

@ -35,6 +35,7 @@ from .api_pb2 import ( # type: ignore
ListEntitiesSelectResponse,
ListEntitiesSensorResponse,
ListEntitiesServicesResponse,
ListEntitiesSirenResponse,
ListEntitiesSwitchResponse,
ListEntitiesTextSensorResponse,
NumberCommandRequest,
@ -44,6 +45,8 @@ from .api_pb2 import ( # type: ignore
SelectCommandRequest,
SelectStateResponse,
SensorStateResponse,
SirenCommandRequest,
SirenStateResponse,
SubscribeHomeassistantServicesRequest,
SubscribeHomeAssistantStateResponse,
SubscribeHomeAssistantStatesRequest,
@ -115,4 +118,7 @@ MESSAGE_TYPE_TO_PROTO = {
52: ListEntitiesSelectResponse,
53: SelectStateResponse,
54: SelectCommandRequest,
55: ListEntitiesSirenResponse,
56: SirenStateResponse,
57: SirenCommandRequest,
}

View File

@ -535,6 +535,20 @@ class SelectState(EntityState):
missing_state: bool = False
# ==================== SIREN ====================
@dataclass(frozen=True)
class SirenInfo(EntityInfo):
icon: str = ""
tones: List[str] = converter_field(default_factory=list, converter=list)
supports_volume: bool = False
supports_duration: bool = False
@dataclass(frozen=True)
class SirenState(EntityState):
state: bool = False
COMPONENT_TYPE_TO_INFO: Dict[str, Type[EntityInfo]] = {
"binary_sensor": BinarySensorInfo,
"cover": CoverInfo,
@ -547,6 +561,7 @@ COMPONENT_TYPE_TO_INFO: Dict[str, Type[EntityInfo]] = {
"climate": ClimateInfo,
"number": NumberInfo,
"select": SelectInfo,
"siren": SirenInfo,
}