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

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = (

const domain = computeDomain(entityId);
if (
CONTINUOUS_DOMAINS.includes(domain) ||
(CONTINUOUS_DOMAINS.includes(domain) &&
isNumericEntity(domain, stateObj, undefined, [], false)) ||
Copy link
Contributor

@karwosts karwosts Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ideally we'd like to also use the numericDevicesClasses cached list here, instead of just passing an empty array.

It is slightly tricky though as getting that is an async operation, so you'll have to probably do it at the caller and pass it into this function.

DOMAINS_MORE_INFO_NO_HISTORY.includes(domain)
) {
return false;
Expand Down
Loading