mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-27 06:47:20 +00:00
Throttle counting updates (#12223)
This commit is contained in:
parent
65c4d02452
commit
61dc4eaaea
@ -3,7 +3,6 @@ import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
|||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import { computeDomain } from "../common/entity/compute_domain";
|
|
||||||
import { subscribeNotifications } from "../data/persistent_notification";
|
import { subscribeNotifications } from "../data/persistent_notification";
|
||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
import "./ha-icon-button";
|
import "./ha-icon-button";
|
||||||
@ -43,11 +42,8 @@ class HaMenuButton extends LitElement {
|
|||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
const hasNotifications =
|
const hasNotifications =
|
||||||
(this.narrow || this.hass.dockedSidebar === "always_hidden") &&
|
this._hasNotifications &&
|
||||||
(this._hasNotifications ||
|
(this.narrow || this.hass.dockedSidebar === "always_hidden");
|
||||||
Object.keys(this.hass.states).some(
|
|
||||||
(entityId) => computeDomain(entityId) === "configurator"
|
|
||||||
));
|
|
||||||
return html`
|
return html`
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
.label=${this.hass.localize("ui.sidebar.sidebar_toggle")}
|
.label=${this.hass.localize("ui.sidebar.sidebar_toggle")}
|
||||||
|
@ -36,10 +36,9 @@ import memoizeOne from "memoize-one";
|
|||||||
import { LocalStorage } from "../common/decorators/local-storage";
|
import { LocalStorage } from "../common/decorators/local-storage";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import { toggleAttribute } from "../common/dom/toggle_attribute";
|
import { toggleAttribute } from "../common/dom/toggle_attribute";
|
||||||
import { computeDomain } from "../common/entity/compute_domain";
|
|
||||||
import { computeStateDomain } from "../common/entity/compute_state_domain";
|
|
||||||
import { stringCompare } from "../common/string/compare";
|
import { stringCompare } from "../common/string/compare";
|
||||||
import { computeRTL } from "../common/util/compute_rtl";
|
import { computeRTL } from "../common/util/compute_rtl";
|
||||||
|
import { throttle } from "../common/util/throttle";
|
||||||
import { ActionHandlerDetail } from "../data/lovelace";
|
import { ActionHandlerDetail } from "../data/lovelace";
|
||||||
import {
|
import {
|
||||||
PersistentNotification,
|
PersistentNotification,
|
||||||
@ -294,11 +293,7 @@ class HaSidebar extends LitElement {
|
|||||||
toggleAttribute(this, "rtl", computeRTL(this.hass));
|
toggleAttribute(this, "rtl", computeRTL(this.hass));
|
||||||
}
|
}
|
||||||
|
|
||||||
this._updatesCount = Object.values(this.hass.states).filter(
|
this._calculateCounts();
|
||||||
(entity) =>
|
|
||||||
computeStateDomain(entity) === "update" &&
|
|
||||||
updateCanInstall(entity as UpdateEntity)
|
|
||||||
).length;
|
|
||||||
|
|
||||||
if (!SUPPORT_SCROLL_IF_NEEDED) {
|
if (!SUPPORT_SCROLL_IF_NEEDED) {
|
||||||
return;
|
return;
|
||||||
@ -312,6 +307,21 @@ class HaSidebar extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _calculateCounts = throttle(() => {
|
||||||
|
let updateCount = 0;
|
||||||
|
|
||||||
|
for (const entityId of Object.keys(this.hass.states)) {
|
||||||
|
if (
|
||||||
|
entityId.startsWith("update.") &&
|
||||||
|
updateCanInstall(this.hass.states[entityId] as UpdateEntity)
|
||||||
|
) {
|
||||||
|
updateCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this._updatesCount = updateCount;
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
private _renderHeader() {
|
private _renderHeader() {
|
||||||
return html`<div
|
return html`<div
|
||||||
class="menu"
|
class="menu"
|
||||||
@ -519,14 +529,9 @@ class HaSidebar extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _renderNotifications() {
|
private _renderNotifications() {
|
||||||
let notificationCount = this._notifications
|
const notificationCount = this._notifications
|
||||||
? this._notifications.length
|
? this._notifications.length
|
||||||
: 0;
|
: 0;
|
||||||
for (const entityId in this.hass.states) {
|
|
||||||
if (computeDomain(entityId) === "configurator") {
|
|
||||||
notificationCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return html`<div
|
return html`<div
|
||||||
class="notifications-container"
|
class="notifications-container"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user