Adjust subscribe_home_assistant_states to allow separate callback (#928)

This commit is contained in:
Jesse Hills 2024-08-26 13:45:15 +12:00 committed by GitHub
parent 854925e33e
commit 615f79483c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 2 deletions

View File

@ -910,11 +910,17 @@ class APIClient:
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,),
)

View File

@ -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)