From 4d1d100a585805e03e4a8c78fe6937a2a03fb9a2 Mon Sep 17 00:00:00 2001 From: karwosts Date: Wed, 10 Jul 2024 09:35:56 -0700 Subject: [PATCH] Actionable Persistent Notifications --- src/data/persistent_notification.ts | 6 ++++++ .../persistent-notification-item.ts | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/data/persistent_notification.ts b/src/data/persistent_notification.ts index 9ae0447537fa..64a7ba467012 100644 --- a/src/data/persistent_notification.ts +++ b/src/data/persistent_notification.ts @@ -11,11 +11,17 @@ export interface PersitentNotificationEntity extends HassEntity { message?: string; } +export interface PersistentNotificationAction { + action: string; + title: string; +} + export interface PersistentNotification { created_at: string; message: string; notification_id: string; title: string; + actions?: PersistentNotificationAction[]; status: "read" | "unread"; } diff --git a/src/dialogs/notifications/persistent-notification-item.ts b/src/dialogs/notifications/persistent-notification-item.ts index 16a615296511..05706c4953fb 100644 --- a/src/dialogs/notifications/persistent-notification-item.ts +++ b/src/dialogs/notifications/persistent-notification-item.ts @@ -39,6 +39,16 @@ export class HuiPersistentNotificationItem extends LitElement { + ${this.notification.actions?.map( + (a) => + html` ${a.title}` + )} + ${this.hass.localize( "ui.card.persistent_notification.dismiss" @@ -67,6 +77,17 @@ export class HuiPersistentNotificationItem extends LitElement { `; } + private _handleAction(ev): void { + this.hass?.callApi( + "POST", + `events/persistent_notification_action`, + ev.currentTarget.action + ); + this.hass!.callService("persistent_notification", "dismiss", { + notification_id: this.notification!.notification_id, + }); + } + private _handleDismiss(): void { this.hass!.callService("persistent_notification", "dismiss", { notification_id: this.notification!.notification_id,