mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 08:16:36 +00:00
Throttle updates for entity-filter (#3551)
* Throttle updates for entity-filter * throttle element config sets * apply changes * apply review changes
This commit is contained in:
parent
8e0c39e451
commit
c8d3293ae9
@ -12,6 +12,8 @@ class EntityFilterCard extends HTMLElement implements LovelaceCard {
|
|||||||
private _config?: EntityFilterCardConfig;
|
private _config?: EntityFilterCardConfig;
|
||||||
private _configEntities?: EntityConfig[];
|
private _configEntities?: EntityConfig[];
|
||||||
private _baseCardConfig?: LovelaceCardConfig;
|
private _baseCardConfig?: LovelaceCardConfig;
|
||||||
|
private _hass?: HomeAssistant;
|
||||||
|
private _oldEntities?: EntityConfig[];
|
||||||
|
|
||||||
public getCardSize(): number {
|
public getCardSize(): number {
|
||||||
return this._element ? this._element.getCardSize() : 1;
|
return this._element ? this._element.getCardSize() : 1;
|
||||||
@ -41,6 +43,13 @@ class EntityFilterCard extends HTMLElement implements LovelaceCard {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.haveEntitiesChanged(hass)) {
|
||||||
|
this._hass = hass;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._hass = hass;
|
||||||
|
|
||||||
if (!this._configEntities) {
|
if (!this._configEntities) {
|
||||||
this._configEntities = processConfigEntities(this._config.entities);
|
this._configEntities = processConfigEntities(this._config.entities);
|
||||||
}
|
}
|
||||||
@ -62,7 +71,16 @@ class EntityFilterCard extends HTMLElement implements LovelaceCard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (element.tagName !== "HUI-ERROR-CARD") {
|
if (element.tagName !== "HUI-ERROR-CARD") {
|
||||||
|
const isSame =
|
||||||
|
this._oldEntities &&
|
||||||
|
entitiesList.length === this._oldEntities.length &&
|
||||||
|
entitiesList.every((entity, idx) => entity === this._oldEntities![idx]);
|
||||||
|
|
||||||
|
if (!isSame) {
|
||||||
|
this._oldEntities = entitiesList;
|
||||||
element.setConfig({ ...this._baseCardConfig!, entities: entitiesList });
|
element.setConfig({ ...this._baseCardConfig!, entities: entitiesList });
|
||||||
|
}
|
||||||
|
|
||||||
element.isPanel = this.isPanel;
|
element.isPanel = this.isPanel;
|
||||||
element.hass = hass;
|
element.hass = hass;
|
||||||
}
|
}
|
||||||
@ -75,6 +93,27 @@ class EntityFilterCard extends HTMLElement implements LovelaceCard {
|
|||||||
this.style.display = "block";
|
this.style.display = "block";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private haveEntitiesChanged(hass: HomeAssistant): boolean {
|
||||||
|
if (!this._hass) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this._configEntities) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const config of this._configEntities) {
|
||||||
|
if (
|
||||||
|
this._hass.states[config.entity] !== hass.states[config.entity] ||
|
||||||
|
this._hass.localize !== hass.localize
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private _cardElement(): LovelaceCard | undefined {
|
private _cardElement(): LovelaceCard | undefined {
|
||||||
if (!this._element && this._config) {
|
if (!this._element && this._config) {
|
||||||
const element = createCardElement(this._baseCardConfig!);
|
const element = createCardElement(this._baseCardConfig!);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user