Skip to content

Commit

Permalink
Adjust subscribe_home_assistant_states to allow separate callback (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jesserockz authored Aug 26, 2024
1 parent 854925e commit 615f794
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 8 additions & 2 deletions aioesphomeapi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,11 +910,17 @@ async def stop_notify() -> None:
return stop_notify, remove_callback

def subscribe_home_assistant_states(
self, on_state_sub: Callable[[str, str | None], None]
self,
on_state_sub: Callable[[str, str | None], None],
on_state_request: Callable[[str, str | None], None] | None = None,
) -> None:
self._get_connection().send_message_callback_response(
SubscribeHomeAssistantStatesRequest(),
partial(on_subscribe_home_assistant_state_response, on_state_sub),
partial(
on_subscribe_home_assistant_state_response,
on_state_sub,
on_state_request,
),
(SubscribeHomeAssistantStateResponse,),
)

Expand Down
3 changes: 3 additions & 0 deletions aioesphomeapi/client_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ def on_bluetooth_gatt_notify_data_response(

def on_subscribe_home_assistant_state_response(
on_state_sub: Callable[[str, str | None], None],
on_state_request: Callable[[str, str | None], None] | None,
msg: SubscribeHomeAssistantStateResponse,
) -> None:
if on_state_request and msg.once:
on_state_request(msg.entity_id, msg.attribute)
on_state_sub(msg.entity_id, msg.attribute)


Expand Down

0 comments on commit 615f794

Please sign in to comment.