Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show logbook component in more info for non-numeric values #22997

31 changes: 22 additions & 9 deletions src/data/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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;
4 changes: 3 additions & 1 deletion src/dialogs/more-info/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
/**
Expand Down Expand Up @@ -111,7 +112,8 @@ export const computeShowLogBookComponent = (

boern99 marked this conversation as resolved.
Show resolved Hide resolved
const domain = computeDomain(entityId);
if (
CONTINUOUS_DOMAINS.includes(domain) ||
(CONTINUOUS_DOMAINS.includes(domain) &&
isNumericEntity(domain, stateObj, undefined, [], false)) ||
MindFreeze marked this conversation as resolved.
Show resolved Hide resolved
DOMAINS_MORE_INFO_NO_HISTORY.includes(domain)
) {
return false;
Expand Down
Loading