Skip to content

Commit

Permalink
Actionable Persistent Notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
karwosts committed Jul 10, 2024
1 parent bef53ae commit 4d1d100
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/data/persistent_notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

Expand Down
21 changes: 21 additions & 0 deletions src/dialogs/notifications/persistent-notification-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ export class HuiPersistentNotificationItem extends LitElement {
</span>
</div>
${this.notification.actions?.map(
(a) =>
html` <mwc-button
slot="actions"
@click=${this._handleAction}
.action=${a}
>${a.title}</mwc-button
>`
)}
<mwc-button slot="actions" @click=${this._handleDismiss}
>${this.hass.localize(
"ui.card.persistent_notification.dismiss"
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 4d1d100

Please sign in to comment.