Update for Home Assistant 0.86

This commit is contained in:
Thomas Lovén 2019-01-24 10:53:32 +01:00
parent 5ab35c5410
commit 6d11d3cc65
2 changed files with 20 additions and 10 deletions

View File

@ -5,6 +5,8 @@ Make a group from entities in a lovelace entities card - and fold them away when
This card requires [card-tools](https://github.com/thomasloven/lovelace-card-tools) to be installed. This card requires [card-tools](https://github.com/thomasloven/lovelace-card-tools) to be installed.
For installation instructions [see this guide](https://github.com/thomasloven/hass-config/wiki/Lovelace-Plugins).
## Options ## Options
| Name | Type | Default | Description | Name | Type | Default | Description

View File

@ -1,5 +1,5 @@
var LitElement = LitElement || Object.getPrototypeOf(customElements.get('hui-error-entity-row')); customElements.whenDefined('card-tools').then(() => {
class FoldEntityRow extends LitElement { class FoldEntityRow extends cardTools.litElement() {
static get properties() { static get properties() {
return { return {
@ -8,7 +8,7 @@ class FoldEntityRow extends LitElement {
} }
render() { render() {
return window.cardTools.litHtml` return cardTools.litHtml()`
${this._renderStyle()} ${this._renderStyle()}
<div id=head> <div id=head>
<div id=entity> <div id=entity>
@ -25,7 +25,7 @@ class FoldEntityRow extends LitElement {
} }
_renderStyle() { _renderStyle() {
return window.cardTools.litHtml` return cardTools.litHtml()`
<style> <style>
#items { #items {
padding: 0 0 0 40px; padding: 0 0 0 40px;
@ -67,7 +67,7 @@ class FoldEntityRow extends LitElement {
_renderElement(conf, options) { _renderElement(conf, options) {
conf = (typeof conf === "string") ? {entity: conf} : conf; conf = (typeof conf === "string") ? {entity: conf} : conf;
conf = Object.assign(conf, options); conf = Object.assign(conf, options);
const element = window.cardTools.createEntityRow(conf); const element = cardTools.createEntityRow(conf);
if(this._hass) element.hass = this._hass; if(this._hass) element.hass = this._hass;
const DOMAINS_HIDE_MORE_INFO = [ const DOMAINS_HIDE_MORE_INFO = [
@ -80,7 +80,7 @@ class FoldEntityRow extends LitElement {
if (conf.entity && !DOMAINS_HIDE_MORE_INFO.includes(conf.entity.split(".")[0])) { if (conf.entity && !DOMAINS_HIDE_MORE_INFO.includes(conf.entity.split(".")[0])) {
element.classList.add("state-card-dialog"); element.classList.add("state-card-dialog");
element.addEventListener("click", () => { element.addEventListener("click", () => {
window.cardTools.moreInfo(conf.entity); cardTools.moreInfo(conf.entity);
}); });
} }
return element; return element;
@ -101,13 +101,13 @@ class FoldEntityRow extends LitElement {
_renderItem(conf, options) { _renderItem(conf, options) {
const element = this._renderElement(conf, options); const element = this._renderElement(conf, options);
return window.cardTools.litHtml`<div> ${element} </div>`; return cardTools.litHtml()`<div> ${element} </div>`;
} }
setConfig(config) { setConfig(config) {
if(!this._config) { if(!this._config) {
if(!window.cardTools) throw new Error(`Can't find card-tools. See https://github.com/thomasloven/lovelace-card-tools`); if(!cardTools) throw new Error(`Can't find card-tools. See https://github.com/thomasloven/lovelace-card-tools`);
window.cardTools.checkVersion(0.1); cardTools.checkVersion(0.1);
this._config = config; this._config = config;
this._closed = !config.open; this._closed = !config.open;
@ -119,7 +119,7 @@ class FoldEntityRow extends LitElement {
if (config.entities) if (config.entities)
items = config.entities; items = config.entities;
if (head && head.split('.')[0] === "group") if (head && head.split('.')[0] === "group")
items = window.cardTools.hass().states[head].attributes.entity_id; items = cardTools.hass().states[head].attributes.entity_id;
if(items) if(items)
this._entities = items.map((e) => this._renderItem(e, config.group_config)); this._entities = items.map((e) => this._renderItem(e, config.group_config));
@ -134,3 +134,11 @@ class FoldEntityRow extends LitElement {
} }
customElements.define('fold-entity-row', FoldEntityRow); customElements.define('fold-entity-row', FoldEntityRow);
});
window.setTimeout(() => {
if(customElements.get('card-tools')) return;
customElements.define('fold-entity-row', class extends HTMLElement{
setConfig() { throw new Error("Can't find card-tools. See https://github.com/thomasloven/lovelace-card-tools");}
});
}, 2000);