Home Assistant States

This commit is contained in:
Otto Winter 2018-12-18 14:53:52 +01:00
parent 26fd0ccc09
commit 0213daa0a2
No known key found for this signature in database
GPG Key ID: DB66C0BE6013F97E
3 changed files with 112 additions and 44 deletions

View File

@ -283,6 +283,7 @@ enum LogLevel {
message SubscribeLogsRequest { message SubscribeLogsRequest {
LogLevel level = 1; LogLevel level = 1;
bool dump_config = 2;
} }
message SubscribeLogsResponse { message SubscribeLogsResponse {
@ -302,12 +303,19 @@ message ServiceCallResponse {
map<string, string> variables = 4; map<string, string> variables = 4;
} }
message SubscribeHomeAssistantStateRequest { // 1. Client sends SubscribeHomeAssistantStatesRequest
string entity_id = 1; // 2. Server responds with zero or more SubscribeHomeAssistantStateResponse (async)
// 3. Client sends HomeAssistantStateResponse for state changes.
message SubscribeHomeAssistantStatesRequest {
} }
message SubscribeHomeAssistantStateResponse { message SubscribeHomeAssistantStateResponse {
string entity_id = 1; string entity_id = 1;
}
message HomeAssistantStateResponse {
string entity_id = 1;
string state = 2; string state = 2;
} }

File diff suppressed because one or more lines are too long

View File

@ -54,6 +54,9 @@ MESSAGE_TYPE_TO_PROTO = {
35: pb.ServiceCallResponse, 35: pb.ServiceCallResponse,
36: pb.GetTimeRequest, 36: pb.GetTimeRequest,
37: pb.GetTimeResponse, 37: pb.GetTimeResponse,
38: pb.SubscribeHomeAssistantStatesRequest,
39: pb.SubscribeHomeAssistantStateResponse,
40: pb.HomeAssistantStateResponse,
} }
@ -592,6 +595,24 @@ class APIClient:
self._message_handlers.append(on_msg) self._message_handlers.append(on_msg)
await self._send_message(pb.SubscribeServiceCallsRequest()) 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, async def cover_command(self,
key: int, key: int,
command: int command: int