mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2024-12-27 17:37:39 +01:00
Home Assistant States
This commit is contained in:
parent
26fd0ccc09
commit
0213daa0a2
@ -283,6 +283,7 @@ enum LogLevel {
|
||||
|
||||
message SubscribeLogsRequest {
|
||||
LogLevel level = 1;
|
||||
bool dump_config = 2;
|
||||
}
|
||||
|
||||
message SubscribeLogsResponse {
|
||||
@ -302,12 +303,19 @@ message ServiceCallResponse {
|
||||
map<string, string> variables = 4;
|
||||
}
|
||||
|
||||
message SubscribeHomeAssistantStateRequest {
|
||||
string entity_id = 1;
|
||||
// 1. Client sends SubscribeHomeAssistantStatesRequest
|
||||
// 2. Server responds with zero or more SubscribeHomeAssistantStateResponse (async)
|
||||
// 3. Client sends HomeAssistantStateResponse for state changes.
|
||||
message SubscribeHomeAssistantStatesRequest {
|
||||
|
||||
}
|
||||
|
||||
message SubscribeHomeAssistantStateResponse {
|
||||
string entity_id = 1;
|
||||
}
|
||||
|
||||
message HomeAssistantStateResponse {
|
||||
string entity_id = 1;
|
||||
string state = 2;
|
||||
}
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -54,6 +54,9 @@ MESSAGE_TYPE_TO_PROTO = {
|
||||
35: pb.ServiceCallResponse,
|
||||
36: pb.GetTimeRequest,
|
||||
37: pb.GetTimeResponse,
|
||||
38: pb.SubscribeHomeAssistantStatesRequest,
|
||||
39: pb.SubscribeHomeAssistantStateResponse,
|
||||
40: pb.HomeAssistantStateResponse,
|
||||
}
|
||||
|
||||
|
||||
@ -592,6 +595,24 @@ class APIClient:
|
||||
self._message_handlers.append(on_msg)
|
||||
await self._send_message(pb.SubscribeServiceCallsRequest())
|
||||
|
||||
async def subscribe_home_assistant_states(self, on_state_sub: Callable[[str], None]) -> None:
|
||||
self._check_authenticated()
|
||||
|
||||
def on_msg(msg):
|
||||
if isinstance(msg, pb.SubscribeHomeAssistantStateResponse):
|
||||
on_state_sub(msg.entity_id)
|
||||
|
||||
self._message_handlers.append(on_msg)
|
||||
await self._send_message(pb.SubscribeHomeAssistantStatesRequest())
|
||||
|
||||
async def send_home_assistant_state(self, entity_id: str, state: str) -> None:
|
||||
self._check_authenticated()
|
||||
|
||||
await self._send_message(pb.HomeAssistantStateResponse(
|
||||
entity_id=entity_id,
|
||||
state=state,
|
||||
))
|
||||
|
||||
async def cover_command(self,
|
||||
key: int,
|
||||
command: int
|
||||
|
Loading…
Reference in New Issue
Block a user