Skip to content

Commit

Permalink
Handle unavailable entities
Browse files Browse the repository at this point in the history
Handle unavailable entities to prevent them from breaking feed
  • Loading branch information
gadgetchnnel committed Jan 8, 2020
1 parent 71d6224 commit 586558f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 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.3.5b2",
"version": "0.3.5b3",
"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
28 changes: 26 additions & 2 deletions lovelace-home-feed-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,15 @@ class HomeFeedCard extends HomeFeedCardHelpers.LitElement {
getEntities() {
let data = this.entities.filter(i => i.multiple_items !== true && i.include_history !== true).map(i => {
let stateObj = this._hass.states[i.entity];

if(stateObj == null) {
return { entity_id: i.entity, icon: null, entity: i.entity, display_name: this._hass.localize(
"ui.panel.lovelace.warning.entity_not_found",
"entity",
i.entity
), more_info_on_tap: false,
content_template: null, state: "unavailable", stateObj: null, item_type: "unavailable", };
}
let domain = i.entity.split(".")[0];
if(!i.exclude_states.includes(stateObj.state)
&& (domain != "automation" || stateObj.attributes.last_triggered) // Exclude automations which have never been triggered
Expand Down Expand Up @@ -930,6 +939,11 @@ class HomeFeedCard extends HomeFeedCardHelpers.LitElement {
case "multi_entity":
var icon = n.icon;

var contentText = `${n.display_name}`;
break;
case "unavailable":
var icon = "mdi:alert-circle";

var contentText = `${n.display_name}`;
break;
default:
Expand Down Expand Up @@ -1048,14 +1062,24 @@ class HomeFeedCard extends HomeFeedCardHelpers.LitElement {
${closeLink}
</div>
<div class="item-content ${contentClass}" .item=${n} @click=${clickable ? this._handleClick : null}>
<ha-markdown class="markdown-content ${compact_mode ? "compact" : ""}" style="float:left;" .content=${contentText}></ha-markdown>
${timeItem}
${this.itemContent(n, compact_mode, contentText)}
${n.item_type != "unavailable" ? timeItem : null}
</div>
</div>
${compact_mode ? HomeFeedCardHelpers.html`` : HomeFeedCardHelpers.html`<hr style="clear:both;"/>`}
`;
}

itemContent(item, compact_mode, contentText){
if(item.item_type == "unavailable"){
return HomeFeedCardHelpers.html`
<hui-warning class="markdown-content ${compact_mode ? "compact" : ""}" style="float:left;">${contentText}</hui-warning>
`;
}
return HomeFeedCardHelpers.html`
<ha-markdown class="markdown-content ${compact_mode ? "compact" : ""}" style="float:left;" .content=${contentText}></ha-markdown>
`;
}
get notificationButton() {
if(!this._notificationButton){
this._notificationButton = this.rootElement.querySelector("hui-notifications-button");
Expand Down

0 comments on commit 586558f

Please sign in to comment.