Skip to content
This repository was archived by the owner on Oct 8, 2020. It is now read-only.
This repository was archived by the owner on Oct 8, 2020. It is now read-only.

Bad performance with customElements #272

@zibous

Description

@zibous

When I activate the custom header, the constructor of a customElements is called multiple times. This worsens the display of the view massively.

System Home Assistant 0.116.0b5
Frontend-Version: 20201001.1 - latest

arch x86_64
dev false
docker false
hassio false
installation_type Home Assistant Core
os_name Linux
os_version 5.4.0-48-generic
python_version 3.8.2
timezone Europe/Vaduz
version 0.116.0b5
virtualenv true

Bildschirmfoto 2020-10-07 um 20 03 12

Config

## ########################################
## Compact Custom Header
## ########################################

custom_header:
  compact_mode: true
  header_text: "IPS Smarthome"
  footer_mode: false
  hide_help: true
  background: "rgba(0,0,0,0.8)"

Without custom_header:
Bildschirmfoto 2020-10-07 um 19 50 09

With custom_header:
Bildschirmfoto 2020-10-07 um 19 52 22

customElement:

class ContentCardExample extends HTMLElement {
	
	constructor() {
		super();
		console.log('*****Event - card - constructor', Math.random().toString(36).substr(2, 9), new Date().getTime());
	}
	
    set hass(hass) {
		if (!this.content) {
            let startTime = new Date()
            console.log("Create new ha-card", startTime)
			const card = document.createElement("ha-card");
			card.header = "Example card";
			this.content = document.createElement("div");
			this.content.style.padding = "0 16px 16px";
			card.appendChild(this.content);
			this.appendChild(card);
		}

		const entityId = this.config.entity;
		const state = hass.states[entityId];
		const stateStr = state ? state.state : "unavailable";

		this.content.innerHTML = `
        The state of ${entityId} is ${stateStr}!
        <br><br>
        <img src="http://via.placeholder.com/350x150">
      `;
	}

	setConfig(config) {
		if (!config.entity) {
			throw new Error("You need to define an entity");
		}
		this.config = config;
	}

	// The height of your card. Home Assistant uses this to automatically
	// distribute all cards over the available columns.
	getCardSize() {
		return 3;
	}
}

customElements.define("content-card-example", ContentCardExample);

Is there a workaround for so I can use the CCH?

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions