From 895edd78c5d1ffad052d02b1d758be20e94bdd6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Mon, 21 Jan 2019 10:16:59 +0100 Subject: [PATCH] Cleanup and bugfixing --- state-switch.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/state-switch.js b/state-switch.js index 48dbf3b..fb03154 100644 --- a/state-switch.js +++ b/state-switch.js @@ -8,18 +8,15 @@ class StateSwitch extends LitElement { this.cards = {} for(var k in this.config.states) { - const conf = this.config.states[k]; - let tag = conf.type; - 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.cards[k] = window.cardTools.createCard(this.config.states[k]); + this.cardSize = Math.max(this.cardSize, this.cards[k].getCardSize()); } - this.idCard = document.createElement("ha-card"); - this.idCard.innerHTML = `

${window.cardTools.deviceID}

`; + this.idCard = window.cardTools.createCard({ + type: "markdown", + title: "Device ID", + content: `Your device id is: \`${window.cardTools.deviceID}\``, + }); } render() { @@ -33,12 +30,17 @@ class StateSwitch extends LitElement { const lastCard = this.currentCard; 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') { - 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 { 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();