[[localize('ui.notification_drawer.empty')]]
@@ -125,10 +123,6 @@ export class HuiNotificationDrawer extends EventsMixin(LocalizeMixin(PolymerElem
static get properties() {
return {
hass: Object,
- _entities: {
- type: Array,
- computed: '_getEntities(hass.states, hidden)'
- },
narrow: {
type: Boolean,
reflectToAttribute: true
@@ -142,21 +136,21 @@ export class HuiNotificationDrawer extends EventsMixin(LocalizeMixin(PolymerElem
type: Boolean,
value: true,
reflectToAttribute: true
+ },
+ notifications: {
+ type: Array,
+ value: []
}
};
}
- _getEntities(states, hidden) {
- return (states && !hidden) ? computeNotifications(states) : [];
- }
-
_closeDrawer(ev) {
ev.stopPropagation();
this.open = false;
}
- _empty(entities) {
- return entities.length === 0;
+ _empty(notifications) {
+ return notifications.length === 0;
}
_openChanged(open) {
diff --git a/src/panels/lovelace/components/notifications/hui-notification-item.js b/src/panels/lovelace/components/notifications/hui-notification-item.js
index 9fcab424284e..d174cd0b9458 100644
--- a/src/panels/lovelace/components/notifications/hui-notification-item.js
+++ b/src/panels/lovelace/components/notifications/hui-notification-item.js
@@ -8,25 +8,27 @@ export class HuiNotificationItem extends PolymerElement {
static get properties() {
return {
hass: Object,
- stateObj: {
+ notification: {
type: Object,
observer: '_stateChanged'
}
};
}
- _stateChanged(stateObj) {
+ _stateChanged(notification) {
if (this.lastChild) {
this.removeChild(this.lastChild);
}
- if (!stateObj) return;
+ if (!notification) return;
- const domain = computeDomain(stateObj.entity_id);
+ const domain = notification.entity_id
+ ? computeDomain(notification.entity_id)
+ : 'persistent_notification';
const tag = `hui-${domain}-notification-item`;
const el = document.createElement(tag);
el.hass = this.hass;
- el.stateObj = stateObj;
+ el.notification = notification;
this.appendChild(el);
}
}
diff --git a/src/panels/lovelace/components/notifications/hui-notifications-button.js b/src/panels/lovelace/components/notifications/hui-notifications-button.js
index 5d9048cb64de..45e872ca577a 100644
--- a/src/panels/lovelace/components/notifications/hui-notifications-button.js
+++ b/src/panels/lovelace/components/notifications/hui-notifications-button.js
@@ -5,8 +5,6 @@ import '@polymer/app-layout/app-toolbar/app-toolbar.js';
import { html } from '@polymer/polymer/lib/utils/html-tag.js';
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
-import computeNotifications from '../../common/compute-notifications.js';
-
import EventsMixin from '../../../../mixins/events-mixin.js';
/*
@@ -36,16 +34,19 @@ export class HuiNotificationsButton extends EventsMixin(PolymerElement) {
}
-
+
`;
}
static get properties() {
return {
- hass: Object,
notificationsOpen: {
type: Boolean,
notify: true
+ },
+ notifications: {
+ type: Array,
+ value: []
}
};
}
@@ -54,8 +55,8 @@ export class HuiNotificationsButton extends EventsMixin(PolymerElement) {
this.notificationsOpen = true;
}
- _hasNotifications(states) {
- return computeNotifications(states).length > 0;
+ _hasNotifications(notifications) {
+ return notifications.length > 0;
}
}
customElements.define('hui-notifications-button', HuiNotificationsButton);
diff --git a/src/panels/lovelace/components/notifications/hui-persistent-notification-item.js b/src/panels/lovelace/components/notifications/hui-persistent-notification-item.js
index dfe511b9c39d..dcb4aeeb7b67 100644
--- a/src/panels/lovelace/components/notifications/hui-persistent-notification-item.js
+++ b/src/panels/lovelace/components/notifications/hui-persistent-notification-item.js
@@ -4,8 +4,6 @@ import '@polymer/paper-icon-button/paper-icon-button.js';
import { html } from '@polymer/polymer/lib/utils/html-tag.js';
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
-import computeStateName from '../../../../common/entity/compute_state_name.js';
-
import '../../../../components/ha-markdown.js';
import './hui-notification-item-template.js';
@@ -18,13 +16,13 @@ export class HuiPersistentNotificationItem extends LocalizeMixin(PolymerElement)
static get template() {
return html`
- [[_computeTitle(stateObj)]]
+ [[_computeTitle(notification)]]
-
+
- [[localize('ui.card.persistent_notification.dismiss')]]
@@ -34,16 +32,18 @@ export class HuiPersistentNotificationItem extends LocalizeMixin(PolymerElement)
static get properties() {
return {
hass: Object,
- stateObj: Object
+ notification: Object
};
}
_handleDismiss() {
- this.hass.callApi('DELETE', `states/${this.stateObj.entity_id}`);
+ this.hass.callService('persistent_notification', 'dismiss', {
+ notification_id: this.notification.notification_id
+ });
}
- _computeTitle(stateObj) {
- return (stateObj.attributes.title || computeStateName(stateObj));
+ _computeTitle(notification) {
+ return notification.title || notification.notification_id;
}
}
customElements.define(
diff --git a/src/panels/lovelace/hui-root.js b/src/panels/lovelace/hui-root.js
index f4374f03445c..f0b3b592e997 100644
--- a/src/panels/lovelace/hui-root.js
+++ b/src/panels/lovelace/hui-root.js
@@ -22,6 +22,7 @@ import '../../layouts/ha-app-layout.js';
import '../../components/ha-start-voice-button.js';
import '../../components/ha-icon.js';
import { loadModule, loadCSS, loadJS } from '../../common/dom/load_resource.js';
+import { subscribeNotifications } from '../../data/ws-notifications';
import './components/notifications/hui-notification-drawer.js';
import './components/notifications/hui-notifications-button.js';
import './hui-unused-entities.js';
@@ -29,6 +30,7 @@ import './hui-view.js';
import debounce from '../../common/util/debounce.js';
import createCardElement from './common/create-card-element.js';
+import computeNotifications from './common/compute-notifications';
// CSS and JS should only be imported once. Modules and HTML are safe.
const CSS_CACHE = {};
@@ -76,6 +78,7 @@ class HUIRoot extends NavigateMixin(EventsMixin(PolymerElement)) {
@@ -87,6 +90,7 @@ class HUIRoot extends NavigateMixin(EventsMixin(PolymerElement)) {
this._selectView(this._curView), 100);
}
+ connectedCallback() {
+ super.connectedCallback();
+ this._unsubNotifications = subscribeNotifications(this.hass.connection, (notifications) => {
+ this._persistentNotifications = notifications;
+ });
+ }
+
+ disconnectedCallback() {
+ super.disconnectedCallback();
+ if (typeof this._unsubNotifications === 'function') {
+ this._unsubNotifications();
+ }
+ }
+
+ _updateNotifications(states, persistent) {
+ if (!states) return persistent;
+
+ const configurator = computeNotifications(states);
+ return persistent.concat(configurator);
+ }
+
_routeChanged(route) {
const views = this.config && this.config.views;
if (route.path === '' && route.prefix === '/lovelace' && views) {