Skip to content

Commit

Permalink
Fix error when Lovelace in edit mode
Browse files Browse the repository at this point in the history
Fix an error when Lovelace UI is in edit mode, caused by the notification button not being present.
  • Loading branch information
gadgetchnnel committed Jul 1, 2019
1 parent 2aa09a4 commit 73ad648
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion custom_card.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"lovelace-home-feed-card": {
"version": "0.2.5",
"version": "0.2.6",
"remote_location": "https://raw.githubusercontent.com/gadgetchnnel/lovelace-home-feed-card/master/lovelace-home-feed-card.js",
"visit_repo": "https://github.com/gadgetchnnel/lovelace-home-feed-card",
"changelog": "https://github.com/gadgetchnnel/lovelace-home-feed-card"
Expand Down
20 changes: 12 additions & 8 deletions lovelace-home-feed-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ class HomeFeedCard extends Polymer.Element {
}

async refreshNotifications() {
if(!this._hass) return;

var response = await this._hass.callWS({type: 'persistent_notification/get'});
if(this._config.id_filter) {
response = response.filter(n => n.notification_id.match(this._config.id_filter));
Expand Down Expand Up @@ -488,14 +490,16 @@ class HomeFeedCard extends Polymer.Element {

notificationMonitor() {
let oldNotificationCount = this.notificationCount ? this.notificationCount : "0";

let notificationIndicator = this.notificationButton.shadowRoot.querySelector(".indicator div");
let notificationCount = notificationIndicator ? notificationIndicator.innerText : "0";
if(notificationCount != oldNotificationCount){
this.notificationCount = notificationCount;
this.refreshNotifications().then(() => {
this.loadedNotifications = true;
});
if(this.notificationButton)
{
let notificationIndicator = this.notificationButton.shadowRoot.querySelector(".indicator div");
let notificationCount = notificationIndicator ? notificationIndicator.innerText : "0";
if(notificationCount != oldNotificationCount){
this.notificationCount = notificationCount;
this.refreshNotifications().then(() => {
this.loadedNotifications = true;
});
}
}
window.setTimeout(
() => this.notificationMonitor(),
Expand Down

0 comments on commit 73ad648

Please sign in to comment.