From ca9da0eeecb88b6100286373af97c57aded12358 Mon Sep 17 00:00:00 2001 From: boern99 Date: Sun, 10 Nov 2024 14:04:11 +0000 Subject: [PATCH 1/4] if isNumeric ignore CONTINUOUS_DOMAINS --- src/dialogs/more-info/const.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dialogs/more-info/const.ts b/src/dialogs/more-info/const.ts index e75fd38516d8..592bd22e83b5 100644 --- a/src/dialogs/more-info/const.ts +++ b/src/dialogs/more-info/const.ts @@ -111,7 +111,7 @@ export const computeShowLogBookComponent = ( const domain = computeDomain(entityId); if ( - CONTINUOUS_DOMAINS.includes(domain) || + (CONTINUOUS_DOMAINS.includes(domain) && !isNaN(Number(stateObj.state))) || DOMAINS_MORE_INFO_NO_HISTORY.includes(domain) ) { return false; From 8979b0c99c9f9530d1c01eae1f849a07a7cdff2d Mon Sep 17 00:00:00 2001 From: boern99 Date: Mon, 25 Nov 2024 19:17:40 +0000 Subject: [PATCH 2/4] use isNumeric logic from history.ts --- src/data/history.ts | 31 ++++++++++++++++++++++--------- src/dialogs/more-info/const.ts | 4 +++- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/data/history.ts b/src/data/history.ts index 29dfa5a285bf..f7a2cc20326f 100644 --- a/src/data/history.ts +++ b/src/data/history.ts @@ -469,15 +469,13 @@ export const computeHistory = ( let unit: string | undefined; - const isNumeric = - forceNumeric || - isNumericFromDomain(domain) || - (currentState != null && - isNumericFromAttributes(currentState.attributes)) || - (currentState != null && - domain === "sensor" && - isNumericSensorEntity(currentState, sensorNumericalDeviceClasses)) || - numericStateFromHistory != null; + const isNumeric = isNumericEntity( + domain, + currentState, + numericStateFromHistory, + sensorNumericalDeviceClasses, + forceNumeric + ); if (isNumeric) { unit = @@ -551,3 +549,18 @@ export const computeGroupKey = ( device_class: string | undefined, splitDeviceClasses: boolean ) => (splitDeviceClasses ? `${unit}_${device_class || ""}` : unit); + +export const isNumericEntity = ( + domain: string, + currentState: HassEntity | undefined, + numericStateFromHistory: EntityHistoryState | undefined, + sensorNumericalDeviceClasses: string[], + forceNumeric = false +): boolean => + forceNumeric || + isNumericFromDomain(domain) || + (currentState != null && isNumericFromAttributes(currentState.attributes)) || + (currentState != null && + domain === "sensor" && + isNumericSensorEntity(currentState, sensorNumericalDeviceClasses)) || + numericStateFromHistory != null; diff --git a/src/dialogs/more-info/const.ts b/src/dialogs/more-info/const.ts index 592bd22e83b5..5ed123fb9acd 100644 --- a/src/dialogs/more-info/const.ts +++ b/src/dialogs/more-info/const.ts @@ -5,6 +5,7 @@ import type { GroupEntity } from "../../data/group"; import { computeGroupDomain } from "../../data/group"; import { CONTINUOUS_DOMAINS } from "../../data/logbook"; import type { HomeAssistant } from "../../types"; +import { isNumericEntity } from "../../data/history"; export const DOMAINS_NO_INFO = ["camera", "configurator"]; /** @@ -111,7 +112,8 @@ export const computeShowLogBookComponent = ( const domain = computeDomain(entityId); if ( - (CONTINUOUS_DOMAINS.includes(domain) && !isNaN(Number(stateObj.state))) || + (CONTINUOUS_DOMAINS.includes(domain) && + isNumericEntity(domain, stateObj, undefined, [], false)) || DOMAINS_MORE_INFO_NO_HISTORY.includes(domain) ) { return false; From 5a99282b73348af74a19e48c6831d99fff946099 Mon Sep 17 00:00:00 2001 From: boern99 Date: Tue, 7 Jan 2025 18:43:54 +0000 Subject: [PATCH 3/4] removed check for stateObj.attributes.unit_of_measurement --- src/dialogs/more-info/const.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dialogs/more-info/const.ts b/src/dialogs/more-info/const.ts index 5ed123fb9acd..99d6b953215c 100644 --- a/src/dialogs/more-info/const.ts +++ b/src/dialogs/more-info/const.ts @@ -106,7 +106,7 @@ export const computeShowLogBookComponent = ( } const stateObj = hass.states[entityId]; - if (!stateObj || stateObj.attributes.unit_of_measurement) { + if (!stateObj) { return false; } From 1272a5119a57c3851be52c680fe1108788ac86db Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Wed, 8 Jan 2025 10:08:49 +0200 Subject: [PATCH 4/4] pass numericDevicesClasses to computeShowLogBookComponent --- src/dialogs/more-info/const.ts | 10 +++++++-- src/dialogs/more-info/ha-more-info-dialog.ts | 15 ++++++++++++- .../ha-more-info-history-and-logbook.ts | 21 +++++++++++++++++-- src/dialogs/more-info/ha-more-info-info.ts | 21 +++++++++++++++++-- 4 files changed, 60 insertions(+), 7 deletions(-) diff --git a/src/dialogs/more-info/const.ts b/src/dialogs/more-info/const.ts index 99d6b953215c..76b51ae79123 100644 --- a/src/dialogs/more-info/const.ts +++ b/src/dialogs/more-info/const.ts @@ -99,7 +99,8 @@ export const computeShowHistoryComponent = ( export const computeShowLogBookComponent = ( hass: HomeAssistant, - entityId: string + entityId: string, + sensorNumericalDeviceClasses: string[] = [] ): boolean => { if (!isComponentLoaded(hass, "logbook")) { return false; @@ -113,7 +114,12 @@ export const computeShowLogBookComponent = ( const domain = computeDomain(entityId); if ( (CONTINUOUS_DOMAINS.includes(domain) && - isNumericEntity(domain, stateObj, undefined, [], false)) || + isNumericEntity( + domain, + stateObj, + undefined, + sensorNumericalDeviceClasses + )) || DOMAINS_MORE_INFO_NO_HISTORY.includes(domain) ) { return false; diff --git a/src/dialogs/more-info/ha-more-info-dialog.ts b/src/dialogs/more-info/ha-more-info-dialog.ts index 51d14f1cce77..c37e337aa3d0 100644 --- a/src/dialogs/more-info/ha-more-info-dialog.ts +++ b/src/dialogs/more-info/ha-more-info-dialog.ts @@ -52,6 +52,7 @@ import "./ha-more-info-info"; import type { MoreInfoInfo } from "./ha-more-info-info"; import "./ha-more-info-settings"; import "./more-info-content"; +import { getSensorNumericDeviceClasses } from "../../data/sensor"; export interface MoreInfoDialogParams { entityId: string | null; @@ -101,6 +102,8 @@ export class MoreInfoDialog extends LitElement { @query("ha-more-info-info, ha-more-info-history-and-logbook") private _history?: MoreInfoInfo | MoreInfoHistoryAndLogbook; + @state() private _sensorNumericDeviceClasses?: string[] = []; + public showDialog(params: MoreInfoDialogParams) { this._entityId = params.entityId; if (!this._entityId) { @@ -161,7 +164,11 @@ export class MoreInfoDialog extends LitElement { return ( DOMAINS_WITH_MORE_INFO.includes(domain) && (computeShowHistoryComponent(this.hass, this._entityId!) || - computeShowLogBookComponent(this.hass, this._entityId!)) + computeShowLogBookComponent( + this.hass, + this._entityId!, + this._sensorNumericDeviceClasses + )) ); } @@ -258,6 +265,11 @@ export class MoreInfoDialog extends LitElement { this._setView("related"); } + private async _loadNumericDeviceClasses() { + const deviceClasses = await getSensorNumericDeviceClasses(this.hass); + this._sensorNumericDeviceClasses = deviceClasses.numeric_device_classes; + } + protected render() { if (!this._entityId) { return nothing; @@ -515,6 +527,7 @@ export class MoreInfoDialog extends LitElement { protected firstUpdated(changedProps: PropertyValues) { super.firstUpdated(changedProps); this.addEventListener("close-dialog", () => this.closeDialog()); + this._loadNumericDeviceClasses(); } protected updated(changedProps: PropertyValues) { diff --git a/src/dialogs/more-info/ha-more-info-history-and-logbook.ts b/src/dialogs/more-info/ha-more-info-history-and-logbook.ts index a4aa7698698e..3ce6261995a6 100644 --- a/src/dialogs/more-info/ha-more-info-history-and-logbook.ts +++ b/src/dialogs/more-info/ha-more-info-history-and-logbook.ts @@ -1,6 +1,6 @@ import type { CSSResultGroup } from "lit"; import { css, html, LitElement } from "lit"; -import { customElement, property, query } from "lit/decorators"; +import { customElement, property, query, state } from "lit/decorators"; import type { ChartResizeOptions } from "../../components/chart/ha-chart-base"; import type { HomeAssistant } from "../../types"; import { @@ -10,6 +10,7 @@ import { import "./ha-more-info-history"; import type { MoreInfoHistory } from "./ha-more-info-history"; import "./ha-more-info-logbook"; +import { getSensorNumericDeviceClasses } from "../../data/sensor"; @customElement("ha-more-info-history-and-logbook") export class MoreInfoHistoryAndLogbook extends LitElement { @@ -20,6 +21,18 @@ export class MoreInfoHistoryAndLogbook extends LitElement { @query("ha-more-info-history") private _history?: MoreInfoHistory; + @state() private _sensorNumericDeviceClasses?: string[] = []; + + private async _loadNumericDeviceClasses() { + const deviceClasses = await getSensorNumericDeviceClasses(this.hass); + this._sensorNumericDeviceClasses = deviceClasses.numeric_device_classes; + } + + protected firstUpdated(changedProps) { + super.firstUpdated(changedProps); + this._loadNumericDeviceClasses(); + } + public resize(options?: ChartResizeOptions) { this._history?.resize(options); } @@ -34,7 +47,11 @@ export class MoreInfoHistoryAndLogbook extends LitElement { > ` : ""} - ${computeShowLogBookComponent(this.hass, this.entityId) + ${computeShowLogBookComponent( + this.hass, + this.entityId, + this._sensorNumericDeviceClasses + ) ? html` `} ${DOMAINS_WITH_MORE_INFO.includes(domain) || - !computeShowLogBookComponent(this.hass, entityId) + !computeShowLogBookComponent( + this.hass, + entityId, + this._sensorNumericDeviceClasses + ) ? "" : html`