From e18f853f7e746da07bdb9f4982cb191dce08b0ed Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Mon, 24 Mar 2025 17:57:52 +0100 Subject: [PATCH] Fix state display mixin (#24760) --- src/state/state-display-mixin.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/state/state-display-mixin.ts b/src/state/state-display-mixin.ts index c74dc7a93c..05cca8e8f7 100644 --- a/src/state/state-display-mixin.ts +++ b/src/state/state-display-mixin.ts @@ -1,3 +1,4 @@ +import { isComponentLoaded } from "../common/config/is_component_loaded"; import { computeFormatFunctions } from "../common/translations/entity-state"; import { getSensorNumericDeviceClasses } from "../data/sensor"; import type { Constructor, HomeAssistant } from "../types"; @@ -31,10 +32,21 @@ export default >(superClass: T) => { } private _updateStateDisplay = async () => { - if (!this.hass) return; + if (!this.hass || !this.hass.config) { + return; + } - const { numeric_device_classes: sensorNumericDeviceClasses } = - await getSensorNumericDeviceClasses(this.hass); + let sensorNumericDeviceClasses: string[] = []; + + if (isComponentLoaded(this.hass, "sensor")) { + try { + sensorNumericDeviceClasses = ( + await getSensorNumericDeviceClasses(this.hass) + ).numeric_device_classes; + } catch (_err: any) { + // ignore + } + } const { formatEntityState,