1 """Push notification handling."""
3 from __future__
import annotations
6 from collections.abc
import Callable
12 PUSH_CONFIRM_TIMEOUT = 10
16 """Class that represents a push channel."""
22 support_confirm: bool,
23 send_message: Callable[[dict],
None],
24 on_teardown: Callable[[],
None],
26 """Initialize a local push channel."""
32 self.pending_confirms: dict[str, dict] = {}
36 """Send a push notification."""
42 data[
"hass_confirm_id"] = confirm_id
44 async
def handle_push_failed(_=None):
45 """Handle a failed local push notification."""
49 if self.pending_confirms.pop(confirm_id,
None)
is None:
56 await fallback_send(data)
58 self.pending_confirms[confirm_id] = {
60 self.
hasshass, PUSH_CONFIRM_TIMEOUT, handle_push_failed
62 "handle_push_failed": handle_push_failed,
68 """Confirm a push notification.
70 Returns if confirmation successful.
72 if confirm_id
not in self.pending_confirms:
75 self.pending_confirms.pop(confirm_id)[
"unsub_scheduled_push_failed"]()
79 """Tear down this channel."""
87 cancel_pending_local_tasks = [
88 actions[
"handle_push_failed"]()
89 for actions
in self.pending_confirms.values()
92 if cancel_pending_local_tasks:
93 await asyncio.gather(*cancel_pending_local_tasks)
None __init__(self, HomeAssistant hass, str webhook_id, bool support_confirm, Callable[[dict], None] send_message, Callable[[], None] on_teardown)
def async_send_notification(self, data, fallback_send)
bool async_confirm_notification(self, confirm_id)
CALLBACK_TYPE async_call_later(HomeAssistant hass, float|timedelta delay, HassJob[[datetime], Coroutine[Any, Any, None]|None]|Callable[[datetime], Coroutine[Any, Any, None]|None] action)