Performance improvements. Fix #32, I hope.
This commit is contained in:
1 parent
65b2bd2fda
commit
01e22c1e3f
2 files changed
+41
-26
No files matched your search
+1
-2
@@ -1,5 +1,4 @@
|
|||||||
!function(t){var e={};function i(r){if(e[r])return e[r].exports;var s=e[r]={i:r,l:!1,exports:{}};return t[r].call(s.exports,s,s.exports,i),s.l=!0,s.exports}i.m=t,i.c=e,i.d=function(t,e,r){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(i.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)i.d(r,s,function(e){return t[e]}.bind(null,s));return r},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=0)}([function(t,e,i){"use strict";i.r(e);const r=customElements.get("home-assistant-main")?Object.getPrototypeOf(customElements.get("home-assistant-main")):Object.getPrototypeOf(customElements.get("hui-view")),s=r.prototype.html;r.prototype.css;const n="custom:";function o(t,e){const i=document.createElement("hui-error-card");return i.setConfig({type:"error",error:t,config:e}),i}function a(t,e){if(!e||"object"!=typeof e||!e.type)return o(`No ${t} type configured`,e);let i=e.type;if(i=i.startsWith(n)?i.substr(n.length):`hui-${i}-${t}`,customElements.get(i))return function(t,e){const i=document.createElement(t);try{i.setConfig(e)}catch(t){return o(t,e)}return i}(i,e);const r=o(`Custom element doesn't exist: ${i}.`,e);r.style.display="None";const s=setTimeout(()=>{r.style.display=""},2e3);return customElements.whenDefined(i).then(()=>{clearTimeout(s),function(t,e,i=null){if((t=new Event(t,{bubbles:!0,cancelable:!1,composed:!0})).detail=e||{},i)i.dispatchEvent(t);else{var r=document.querySelector("home-assistant");(r=(r=(r=(r=(r=(r=(r=(r=(r=(r=(r=r&&r.shadowRoot)&&r.querySelector("home-assistant-main"))&&r.shadowRoot)&&r.querySelector("app-drawer-layout partial-panel-resolver"))&&r.shadowRoot||r)&&r.querySelector("ha-panel-lovelace"))&&r.shadowRoot)&&r.querySelector("hui-root"))&&r.shadowRoot)&&r.querySelector("ha-app-layout #view"))&&r.firstElementChild)&&r.dispatchEvent(t)}}("ll-rebuild",{},r)}),r}function c(){return document.querySelector("home-assistant").hass}class u extends r{static get properties(){return{hass:{},config:{},noHass:{type:Boolean}}}setConfig(t){var e;this._config=t,this.el?this.el.setConfig(t):this.el=this.create(t),this._hass&&(this.el.hass=this._hass),this.noHass&&(e=this,document.querySelector("home-assistant").provideHass(e))}set config(t){this.setConfig(t)}set hass(t){this._hass=t,this.el&&(this.el.hass=t)}createRenderRoot(){return this}render(){return s`${this.el}`}}if(!customElements.get("card-maker")){class t extends u{create(t){return function(t){return a("card",t)}(t)}getCardSize(){return this.firstElementChild&&this.firstElementChild.getCardSize?this.firstElementChild.getCardSize():1}}customElements.define("card-maker",t)}if(!customElements.get("element-maker")){class t extends u{create(t){return function(t){return a("element",t)}(t)}}customElements.define("element-maker",t)}if(!customElements.get("entity-row-maker")){class t extends u{create(t){return function(t){const e=new Set(["call-service","divider","section","weblink"]);if(!t)return o("Invalid configuration given.",t);if("string"==typeof t&&(t={entity:t}),"object"!=typeof t||!t.entity&&!t.type)return o("Invalid configuration given.",t);const i=t.type||"default";if(e.has(i)||i.startsWith(n))return a("row",t);const r=t.entity.split(".",1)[0];return Object.assign(t,{type:{alert:"toggle",automation:"toggle",climate:"climate",cover:"cover",fan:"toggle",group:"group",input_boolean:"toggle",input_number:"input-number",input_select:"input-select",input_text:"input-text",light:"toggle",lock:"lock",media_player:"media-player",remote:"toggle",scene:"scene",script:"script",sensor:"sensor",timer:"timer",switch:"toggle",vacuum:"toggle",water_heater:"climate",input_datetime:"input-datetime"}[r]||"text"}),a("entity-row",t)}(t)}}customElements.define("entity-row-maker",t)}const l=c().callWS({type:"config/area_registry/list"}),f=c().callWS({type:"config/device_registry/list"}),d=c().callWS({type:"config/entity_registry/list"});async function h(){return window.cardToolsData=window.cardToolsData||{areas:await l,devices:await f,entities:await d},window.cardToolsData}function p(t){const e=window.cardToolsData;let i=[];if(!t)return i;for(const r of e.devices)r.area_id===t.area_id&&i.push(r);return i}function g(t){const e=window.cardToolsData;let i=[];if(!t)return i;for(const r of e.entities)r.device_id===t.id&&i.push(r.entity_id);return i}function y(t,e){if("string"==typeof e&&"string"==typeof t&&(t.startsWith("/")&&t.endsWith("/")||-1!==t.indexOf("*"))){return t.startsWith("/")||(t=`/^${t=t.replace(/\./g,".").replace(/\*/g,".*")}$/`),new RegExp(t.slice(1Line truncated
|
!function(t){var e={};function i(r){if(e[r])return e[r].exports;var s=e[r]={i:r,l:!1,exports:{}};return t[r].call(s.exports,s,s.exports,i),s.l=!0,s.exports}i.m=t,i.c=e,i.d=function(t,e,r){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(i.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)i.d(r,s,function(e){return t[e]}.bind(null,s));return r},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=0)}([function(t,e,i){"use strict";i.r(e);const r=customElements.get("home-assistant-main")?Object.getPrototypeOf(customElements.get("home-assistant-main")):Object.getPrototypeOf(customElements.get("hui-view")),s=r.prototype.html;r.prototype.css;const n="custom:";function o(t,e){const i=document.createElement("hui-error-card");return i.setConfig({type:"error",error:t,config:e}),i}function a(t,e){if(!e||"object"!=typeof e||!e.type)return o(`No ${t} type configured`,e);let i=e.type;if(i=i.startsWith(n)?i.substr(n.length):`hui-${i}-${t}`,customElements.get(i))return function(t,e){const i=document.createElement(t);try{i.setConfig(e)}catch(t){return o(t,e)}return i}(i,e);const r=o(`Custom element doesn't exist: ${i}.`,e);r.style.display="None";const s=setTimeout(()=>{r.style.display=""},2e3);return customElements.whenDefined(i).then(()=>{clearTimeout(s),function(t,e,i=null){if((t=new Event(t,{bubbles:!0,cancelable:!1,composed:!0})).detail=e||{},i)i.dispatchEvent(t);else{var r=document.querySelector("home-assistant");(r=(r=(r=(r=(r=(r=(r=(r=(r=(r=(r=r&&r.shadowRoot)&&r.querySelector("home-assistant-main"))&&r.shadowRoot)&&r.querySelector("app-drawer-layout partial-panel-resolver"))&&r.shadowRoot||r)&&r.querySelector("ha-panel-lovelace"))&&r.shadowRoot)&&r.querySelector("hui-root"))&&r.shadowRoot)&&r.querySelector("ha-app-layout #view"))&&r.firstElementChild)&&r.dispatchEvent(t)}}("ll-rebuild",{},r)}),r}function c(){return document.querySelector("home-assistant").hass}class u extends r{static get properties(){return{hass:{},config:{},noHass:{type:Boolean}}}setConfig(t){var e;this._config=t,this.el?this.el.setConfig(t):this.el=this.create(t),this._hass&&(this.el.hass=this._hass),this.noHass&&(e=this,document.querySelector("home-assistant").provideHass(e))}set config(t){this.setConfig(t)}set hass(t){this._hass=t,this.el&&(this.el.hass=t)}createRenderRoot(){return this}render(){return s`${this.el}`}}if(!customElements.get("card-maker")){class t extends u{create(t){return function(t){return a("card",t)}(t)}getCardSize(){return this.firstElementChild&&this.firstElementChild.getCardSize?this.firstElementChild.getCardSize():1}}customElements.define("card-maker",t)}if(!customElements.get("element-maker")){class t extends u{create(t){return function(t){return a("element",t)}(t)}}customElements.define("element-maker",t)}if(!customElements.get("entity-row-maker")){class t extends u{create(t){return function(t){const e=new Set(["call-service","divider","section","weblink"]);if(!t)return o("Invalid configuration given.",t);if("string"==typeof t&&(t={entity:t}),"object"!=typeof t||!t.entity&&!t.type)return o("Invalid configuration given.",t);const i=t.type||"default";if(e.has(i)||i.startsWith(n))return a("row",t);const r=t.entity.split(".",1)[0];return Object.assign(t,{type:{alert:"toggle",automation:"toggle",climate:"climate",cover:"cover",fan:"toggle",group:"group",input_boolean:"toggle",input_number:"input-number",input_select:"input-select",input_text:"input-text",light:"toggle",lock:"lock",media_player:"media-player",remote:"toggle",scene:"scene",script:"script",sensor:"sensor",timer:"timer",switch:"toggle",vacuum:"toggle",water_heater:"climate",input_datetime:"input-datetime"}[r]||"text"}),a("entity-row",t)}(t)}}customElements.define("entity-row-maker",t)}const l=c().callWS({type:"config/area_registry/list"}),f=c().callWS({type:"config/device_registry/list"}),d=c().callWS({type:"config/entity_registry/list"});async function h(){return window.cardToolsData=window.cardToolsData||{areas:await l,devices:await f,entities:await d},window.cardToolsData}function g(t){const e=window.cardToolsData;let i=[];if(!t)return i;for(const r of e.devices)r.area_id===t.area_id&&i.push(r);return i}function p(t){const e=window.cardToolsData;let i=[];if(!t)return i;for(const r of e.entities)r.device_id===t.id&&i.push(r.entity_id);return i}function y(t,e){if("string"==typeof e&&"string"==typeof t&&(t.startsWith("/")&&t.endsWith("/")||-1!==t.indexOf("*"))){return t.startsWith("/")||(t=`/^${t=t.replace(/\./g,".").replace(/\*/g,".*")}$/`),new RegExp(t.slice(1Line truncated
|
||||||
<card-maker
|
<card-maker
|
||||||
.config=${this.cardConfig}
|
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
></card-maker>`}getCardSize(){return this.querySelector("card-maker")&&this.querySelector("card-maker").getCardSize?this.querySelector("card-maker").getCardSize():this.entities.length?this.entities.length:this._config.filter&&this._config.filter.include?Object.keys(this._config.filter.include).length:1}})}]);
|
></card-maker>`}getCardSize(){return this.querySelector("card-maker")&&this.querySelector("card-maker").getCardSize?this.querySelector("card-maker").getCardSize():this.entities.length?this.entities.length:this._config.filter&&this._config.filter.include?Object.keys(this._config.filter.include).length:1}})}]);
|
||||||
+40
-24
@@ -9,8 +9,6 @@ class AutoEntities extends LitElement {
|
|||||||
static get properties() {
|
static get properties() {
|
||||||
return {
|
return {
|
||||||
hass: {},
|
hass: {},
|
||||||
cardConfig: {},
|
|
||||||
entities: {},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
async setConfig(config) {
|
async setConfig(config) {
|
||||||
@@ -19,8 +17,8 @@ class AutoEntities extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._config = config;
|
this._config = config;
|
||||||
this.entities = [];
|
this._entities = [];
|
||||||
this.cardConfig = {entities: this.entities, ...config.card};
|
this.cardConfig = {entities: [], ...config.card};
|
||||||
}
|
}
|
||||||
|
|
||||||
async _getEntities()
|
async _getEntities()
|
||||||
@@ -94,27 +92,46 @@ class AutoEntities extends LitElement {
|
|||||||
return entities;
|
return entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
async updated(changedProperties) {
|
set entities(ent) {
|
||||||
if(changedProperties.has("hass") && this.hass) {
|
function compare(a,b) {
|
||||||
function compare(a,b) {
|
if( a === b )
|
||||||
if( a === b ) return true;
|
|
||||||
if( a == null || b == null) return false;
|
|
||||||
if(a.length != b.length) return false;
|
|
||||||
for(var i = 0; i < a.length; i++)
|
|
||||||
if(a[i] !== b[i])
|
|
||||||
return false;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
if( a == null || b == null)
|
||||||
|
return false;
|
||||||
|
if(a.length != b.length)
|
||||||
|
return false;
|
||||||
|
for(var i = 0; i < a.length; i++)
|
||||||
|
if(JSON.stringify(a[i]) !== JSON.stringify(b[i]))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(!compare(ent, this._entities))
|
||||||
|
{
|
||||||
|
this._entities = ent;
|
||||||
|
this.cardConfig = {...this.cardConfig, entities: this._entities};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
get entities() {
|
||||||
|
return this._entities;
|
||||||
|
}
|
||||||
|
|
||||||
const oldEntities = this.entities;
|
set cardConfig(cardConfig) {
|
||||||
const newEntities = await this._getEntities();
|
this._cardConfig = cardConfig;
|
||||||
if(!compare(oldEntities, newEntities)) {
|
if(this.querySelector("card-maker"))
|
||||||
this.entities = newEntities;
|
this.querySelector("card-maker").config = cardConfig;
|
||||||
this.cardConfig = {
|
}
|
||||||
...this.cardConfig,
|
get cardConfig() {
|
||||||
entities: newEntities,
|
return this._cardConfig;
|
||||||
};
|
}
|
||||||
}
|
|
||||||
|
firstUpdated() {
|
||||||
|
this.cardConfig = this._cardConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
updated(changedProperties) {
|
||||||
|
if(changedProperties.has("hass") && this.hass) {
|
||||||
|
// Run this in a timeout to improve performance
|
||||||
|
setTimeout(() => this._getEntities().then((e) => this.entities = e), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +145,6 @@ class AutoEntities extends LitElement {
|
|||||||
}
|
}
|
||||||
return html`
|
return html`
|
||||||
<card-maker
|
<card-maker
|
||||||
.config=${this.cardConfig}
|
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
></card-maker>`;
|
></card-maker>`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user