Cleanup and bugfixing

This commit is contained in:
Thomas Lovén 2019-01-21 10:16:59 +01:00
parent c9b8a16bb3
commit 895edd78c5

View File

@ -8,18 +8,15 @@ class StateSwitch extends LitElement {
this.cards = {} this.cards = {}
for(var k in this.config.states) { for(var k in this.config.states) {
const conf = this.config.states[k]; this.cards[k] = window.cardTools.createCard(this.config.states[k]);
let tag = conf.type; this.cardSize = Math.max(this.cardSize, this.cards[k].getCardSize());
tag = tag.startsWith("custom:")? tag.substr(7) : `hui-${tag}-card`;
const card = this.cards[k] = document.createElement(tag);
card.setConfig(conf);
this.cardSize = Math.max(this.cardSize, card.getCardSize());
} }
this.idCard = document.createElement("ha-card"); this.idCard = window.cardTools.createCard({
this.idCard.innerHTML = `<h2>${window.cardTools.deviceID}</h2>`; type: "markdown",
title: "Device ID",
content: `Your device id is: \`${window.cardTools.deviceID}\``,
});
} }
render() { render() {
@ -33,12 +30,17 @@ class StateSwitch extends LitElement {
const lastCard = this.currentCard; const lastCard = this.currentCard;
if (this.config.entity === 'user') { if (this.config.entity === 'user') {
this.currentCard = this.cards[hass.user.name] || this.cards[this.config.default]; this.currentCard = this.cards[hass.user.name]
|| this.cards[this.config.default];
} else if(this.config.entity == 'browser') { } else if(this.config.entity == 'browser') {
this.currentCard = this.cards[window.cardTools.deviceID] || (this.config.default)?this.cards[this.config.default]:this.idCard; this.currentCard = this.cards[window.cardTools.deviceID]
|| ((this.config.default)
? this.cards[this.config.default]
: this.idCard);
} else { } else {
let state = hass.states[this.config.entity]; let state = hass.states[this.config.entity];
this.currentCard = ((state)?this.cards[state.state]:null) || this.cards[this.config.default]; this.currentCard = ((state)?this.cards[state.state]:null)
|| this.cards[this.config.default];
} }
if(this.currentCard != lastCard) this.requestUpdate(); if(this.currentCard != lastCard) this.requestUpdate();