Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actionable Persistent Notifications #21361

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading