Update to show when entity is unavailable

This commit is contained in:
Zack Arnett 2018-10-17 12:15:20 -04:00
parent 5578580d78
commit 4c3db2119b

View File

@ -82,10 +82,6 @@ export class HuiGlanceCard extends HassLocalizeLitMixin(LitElement)
return html``; return html``;
} }
const { title } = this.config; const { title } = this.config;
const states = this.hass.states;
const entities = this.configEntities!.filter(
(conf) => conf.entity in states
);
applyThemesOnElement(this, this.hass!.themes, this.config.theme); applyThemesOnElement(this, this.hass!.themes, this.config.theme);
@ -94,7 +90,7 @@ export class HuiGlanceCard extends HassLocalizeLitMixin(LitElement)
<ha-card .header="${title}"> <ha-card .header="${title}">
<div class="entities ${classMap({ "no-header": !title })}"> <div class="entities ${classMap({ "no-header": !title })}">
${repeat<EntityConfig>( ${repeat<EntityConfig>(
entities, this.configEntities!,
(entityConf) => entityConf.entity, (entityConf) => entityConf.entity,
(entityConf) => this.renderEntity(entityConf) (entityConf) => this.renderEntity(entityConf)
)} )}
@ -137,6 +133,10 @@ export class HuiGlanceCard extends HassLocalizeLitMixin(LitElement)
state-badge { state-badge {
margin: 8px 0; margin: 8px 0;
} }
.not-found {
background-color: yellow;
text-align: center;
}
</style> </style>
`; `;
} }
@ -144,6 +144,12 @@ export class HuiGlanceCard extends HassLocalizeLitMixin(LitElement)
private renderEntity(entityConf) { private renderEntity(entityConf) {
const stateObj = this.hass!.states[entityConf.entity]; const stateObj = this.hass!.states[entityConf.entity];
if (!stateObj) {
return html`<div class="entity not-found">Entity Not Available: ${
entityConf.entity
}</div>`;
}
return html` return html`
<div <div
class="entity" class="entity"