mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 03:36:44 +00:00
Show logbook component in more info for non-numeric values (#22997)
* if isNumeric ignore CONTINUOUS_DOMAINS * use isNumeric logic from history.ts * removed check for stateObj.attributes.unit_of_measurement * pass numericDevicesClasses to computeShowLogBookComponent --------- Co-authored-by: Petar Petrov <MindFreeze@users.noreply.github.com>
This commit is contained in:
parent
85bebfc309
commit
c50f701160
@ -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;
|
||||
|
@ -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"];
|
||||
/**
|
||||
@ -98,20 +99,27 @@ export const computeShowHistoryComponent = (
|
||||
|
||||
export const computeShowLogBookComponent = (
|
||||
hass: HomeAssistant,
|
||||
entityId: string
|
||||
entityId: string,
|
||||
sensorNumericalDeviceClasses: string[] = []
|
||||
): boolean => {
|
||||
if (!isComponentLoaded(hass, "logbook")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const stateObj = hass.states[entityId];
|
||||
if (!stateObj || stateObj.attributes.unit_of_measurement) {
|
||||
if (!stateObj) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const domain = computeDomain(entityId);
|
||||
if (
|
||||
CONTINUOUS_DOMAINS.includes(domain) ||
|
||||
(CONTINUOUS_DOMAINS.includes(domain) &&
|
||||
isNumericEntity(
|
||||
domain,
|
||||
stateObj,
|
||||
undefined,
|
||||
sensorNumericalDeviceClasses
|
||||
)) ||
|
||||
DOMAINS_MORE_INFO_NO_HISTORY.includes(domain)
|
||||
) {
|
||||
return false;
|
||||
|
@ -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) {
|
||||
|
@ -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 {
|
||||
></ha-more-info-history>
|
||||
`
|
||||
: ""}
|
||||
${computeShowLogBookComponent(this.hass, this.entityId)
|
||||
${computeShowLogBookComponent(
|
||||
this.hass,
|
||||
this.entityId,
|
||||
this._sensorNumericDeviceClasses
|
||||
)
|
||||
? html`
|
||||
<ha-more-info-logbook
|
||||
.hass=${this.hass}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import type { HassEntity } from "home-assistant-js-websocket";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, query } from "lit/decorators";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
import { computeDomain } from "../../common/entity/compute_domain";
|
||||
import type { ChartResizeOptions } from "../../components/chart/ha-chart-base";
|
||||
import type { ExtEntityRegistryEntry } from "../../data/entity_registry";
|
||||
@ -17,6 +17,7 @@ import "./ha-more-info-history";
|
||||
import type { MoreInfoHistory } from "./ha-more-info-history";
|
||||
import "./ha-more-info-logbook";
|
||||
import "./more-info-content";
|
||||
import { getSensorNumericDeviceClasses } from "../../data/sensor";
|
||||
|
||||
@customElement("ha-more-info-info")
|
||||
export class MoreInfoInfo extends LitElement {
|
||||
@ -28,9 +29,21 @@ export class MoreInfoInfo extends LitElement {
|
||||
|
||||
@property({ attribute: false }) public editMode?: boolean;
|
||||
|
||||
@state() private _sensorNumericDeviceClasses?: string[] = [];
|
||||
|
||||
@query("ha-more-info-history")
|
||||
private _history?: MoreInfoHistory;
|
||||
|
||||
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);
|
||||
}
|
||||
@ -85,7 +98,11 @@ export class MoreInfoInfo extends LitElement {
|
||||
.entityId=${this.entityId}
|
||||
></ha-more-info-history>`}
|
||||
${DOMAINS_WITH_MORE_INFO.includes(domain) ||
|
||||
!computeShowLogBookComponent(this.hass, entityId)
|
||||
!computeShowLogBookComponent(
|
||||
this.hass,
|
||||
entityId,
|
||||
this._sensorNumericDeviceClasses
|
||||
)
|
||||
? ""
|
||||
: html`<ha-more-info-logbook
|
||||
.hass=${this.hass}
|
||||
|
Loading…
x
Reference in New Issue
Block a user