diff --git a/src/panels/config/devices/device-detail/ha-device-entities-card.ts b/src/panels/config/devices/device-detail/ha-device-entities-card.ts index 0fdd15f905..efe75a45f3 100644 --- a/src/panels/config/devices/device-detail/ha-device-entities-card.ts +++ b/src/panels/config/devices/device-detail/ha-device-entities-card.ts @@ -3,7 +3,6 @@ import { css, html, LitElement, nothing } from "lit"; import { customElement, property, state } from "lit/decorators"; import { classMap } from "lit/directives/class-map"; import { until } from "lit/directives/until"; -import { computeEntityName } from "../../../../common/entity/compute_entity_name"; import { stripPrefixFromEntityName } from "../../../../common/entity/strip_prefix_from_entity_name"; import "../../../../components/ha-button"; import "../../../../components/ha-card"; @@ -170,11 +169,8 @@ export class HaDeviceEntitiesCard extends LitElement { const element = createRowElement(config); if (this.hass) { element.hass = this.hass; - const stateObj = this.hass.states[entry.entity_id]; - let name = - computeEntityName(stateObj, this.hass.entities, this.hass.devices) || - this.deviceName; + let name = entry.stateName || this.deviceName; if (entry.hidden_by) { name += ` (${this.hass.localize( diff --git a/src/state/lazy-context-provider.ts b/src/state/lazy-context-provider.ts index 878208ba0f..d6f9a3354b 100644 --- a/src/state/lazy-context-provider.ts +++ b/src/state/lazy-context-provider.ts @@ -178,6 +178,12 @@ export class LazyContextProvider< originalCallback: (value: T, unsubscribe?: () => void) => void ): (value: T, unsubscribe?: () => void) => void { let tracked = false; + // Keep stable references so ContextConsumer doesn't think the + // subscription changed and call the old disposer (which removes + // the subscription from the inner provider's map). + let cachedDisposer: (() => void) | undefined; + let cachedWrappedDisposer: (() => void) | undefined; + return (value: T, disposer?: () => void) => { if (!tracked && disposer) { // First call with a disposer — this consumer is now subscribed. @@ -186,20 +192,23 @@ export class LazyContextProvider< this._clearTeardownTimer(); } - const wrappedDisposer = disposer - ? () => { - if (tracked) { - tracked = false; - this._subscriberCount--; - if (this._subscriberCount === 0 && this._loaded) { - this._scheduleTeardown(); + if (disposer !== cachedDisposer) { + cachedDisposer = disposer; + cachedWrappedDisposer = disposer + ? () => { + if (tracked) { + tracked = false; + this._subscriberCount--; + if (this._subscriberCount === 0 && this._loaded) { + this._scheduleTeardown(); + } } + disposer(); } - disposer(); - } - : undefined; + : undefined; + } - originalCallback(value, wrappedDisposer); + originalCallback(value, cachedWrappedDisposer); }; }