Adds throttler to config pages for state entity updates (#21646)

throttler
This commit is contained in:
Simon Lamon 2024-08-28 08:27:28 +02:00 committed by GitHub
parent 6b99cda982
commit 00eb820e36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -51,6 +51,7 @@ import { SubscribeMixin } from "../../mixins/subscribe-mixin";
import { HomeAssistant, Route } from "../../types";
import { subscribeLabelRegistry } from "../../data/label_registry";
import { subscribeFloorRegistry } from "../../data/floor_registry";
import { throttle } from "../../common/util/throttle";
declare global {
// for fire event
@ -395,6 +396,10 @@ class HaPanelConfig extends SubscribeMixin(HassRouterPage) {
initialValue: [],
});
private _hassThrottler = throttle((el, hass) => {
el.hass = hass;
}, 1000);
public hassSubscribe(): UnsubscribeFunc[] {
return [
subscribeEntityRegistry(this.hass.connection!, (entities) => {
@ -641,7 +646,11 @@ class HaPanelConfig extends SubscribeMixin(HassRouterPage) {
this.hass.dockedSidebar === "docked" ? this._wideSidebar : this._wide;
el.route = this.routeTail;
el.hass = this.hass;
if (el.hass !== undefined) {
this._hassThrottler(el, this.hass);
} else {
el.hass = this.hass;
}
el.showAdvanced = Boolean(this.hass.userData?.showAdvanced);
el.isWide = isWide;
el.narrow = this.narrow;