-
-
-
-
- [[_computeName(item, hass.states)]]
-
-
-
- [[_computeState(item, hass.states)]]
-
-
-
-
+ renderEntity(entityConf) {
+ const stateObj = this.hass.states[entityConf.entity];
+
+ return html`
+
+ ${
+ this._config.show_name !== false
+ ? html`
${
+ "name" in entityConf
+ ? entityConf.name
+ : computeStateName(stateObj)
+ }
`
+ : ""
+ }
+
+ ${
+ this._config.show_state !== false
+ ? html`
${computeStateDisplay(this.localize, stateObj)}
`
+ : ""
+ }
+
+ `;
+ }
+
+ render() {
+ if (!this._config) return html``;
+ const { title } = this._config;
+ const states = this.hass.states;
+ const entities = this._configEntities.filter(
+ (conf) => conf.entity in states
+ );
+
+ return html`
+ ${this.renderStyle()}
+
+
+ ${repeat(
+ entities,
+ (entityConf) => entityConf.entity,
+ (entityConf) => this.renderEntity(entityConf)
+ )}
`;
@@ -82,9 +118,7 @@ class HuiGlanceCard extends LocalizeMixin(EventsMixin(PolymerElement)) {
static get properties() {
return {
- hass: Object,
- _config: Object,
- _configEntities: Array,
+ hass: {},
};
}
@@ -106,34 +140,13 @@ class HuiGlanceCard extends LocalizeMixin(EventsMixin(PolymerElement)) {
}
this._configEntities = processConfigEntities(config.entities);
- }
-
- _computeClasses(hasHeader) {
- return `entities ${hasHeader ? "" : "no-header"}`;
- }
-
- _showEntity(item, states) {
- return item.entity in states;
- }
-
- _showInfo(info) {
- return info !== false;
- }
-
- _computeName(item, states) {
- return "name" in item ? item.name : computeStateName(states[item.entity]);
- }
-
- _computeStateObj(item, states) {
- return states[item.entity];
- }
-
- _computeState(item, states) {
- return computeStateDisplay(this.localize, states[item.entity]);
+ if (this.hass) {
+ this.requestUpdate();
+ }
}
_handleClick(ev) {
- const config = ev.model.item;
+ const config = ev.currentTarget.entityConf;
const entityId = config.entity;
switch (config.tap_action) {
case "toggle":