mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2025-02-26 03:21:46 +01:00
Add entity attribute to Home Assistant state subscribtions (#30)
This commit is contained in:
parent
c7836302d0
commit
fa6d8de974
@ -561,6 +561,7 @@ message SubscribeHomeAssistantStateResponse {
|
||||
option (id) = 39;
|
||||
option (source) = SOURCE_SERVER;
|
||||
string entity_id = 1;
|
||||
string attribute = 2;
|
||||
}
|
||||
|
||||
message HomeAssistantStateResponse {
|
||||
@ -570,6 +571,7 @@ message HomeAssistantStateResponse {
|
||||
|
||||
string entity_id = 1;
|
||||
string state = 2;
|
||||
string attribute = 3;
|
||||
}
|
||||
|
||||
// ==================== IMPORT TIME ====================
|
||||
|
File diff suppressed because one or more lines are too long
@ -199,26 +199,35 @@ class APIClient:
|
||||
kwargs[key] = getattr(msg, key)
|
||||
on_service_call(HomeassistantServiceCall(**kwargs))
|
||||
|
||||
await self._connection.send_message_callback_response(pb.SubscribeHomeassistantServicesRequest(),
|
||||
on_msg)
|
||||
await self._connection.send_message_callback_response(
|
||||
pb.SubscribeHomeassistantServicesRequest(), on_msg
|
||||
)
|
||||
|
||||
async def subscribe_home_assistant_states(self, on_state_sub: Callable[[str], None]) -> None:
|
||||
async def subscribe_home_assistant_states(
|
||||
self, on_state_sub: Callable[[str, Optional[str]], None]
|
||||
) -> None:
|
||||
self._check_authenticated()
|
||||
|
||||
def on_msg(msg):
|
||||
if isinstance(msg, pb.SubscribeHomeAssistantStateResponse):
|
||||
on_state_sub(msg.entity_id)
|
||||
on_state_sub(msg.entity_id, msg.attribute)
|
||||
|
||||
await self._connection.send_message_callback_response(
|
||||
pb.SubscribeHomeAssistantStatesRequest(), on_msg)
|
||||
pb.SubscribeHomeAssistantStatesRequest(), on_msg
|
||||
)
|
||||
|
||||
async def send_home_assistant_state(self, entity_id: str, state: str) -> None:
|
||||
async def send_home_assistant_state(
|
||||
self, entity_id: str, attribute: Optional[str], state: str
|
||||
) -> None:
|
||||
self._check_authenticated()
|
||||
|
||||
await self._connection.send_message(pb.HomeAssistantStateResponse(
|
||||
entity_id=entity_id,
|
||||
state=state,
|
||||
))
|
||||
await self._connection.send_message(
|
||||
pb.HomeAssistantStateResponse(
|
||||
entity_id=entity_id,
|
||||
state=state,
|
||||
attribute=attribute,
|
||||
)
|
||||
)
|
||||
|
||||
async def cover_command(self,
|
||||
key: int,
|
||||
|
Loading…
Reference in New Issue
Block a user