mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 11:46:42 +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;
|
let unit: string | undefined;
|
||||||
|
|
||||||
const isNumeric =
|
const isNumeric = isNumericEntity(
|
||||||
forceNumeric ||
|
domain,
|
||||||
isNumericFromDomain(domain) ||
|
currentState,
|
||||||
(currentState != null &&
|
numericStateFromHistory,
|
||||||
isNumericFromAttributes(currentState.attributes)) ||
|
sensorNumericalDeviceClasses,
|
||||||
(currentState != null &&
|
forceNumeric
|
||||||
domain === "sensor" &&
|
);
|
||||||
isNumericSensorEntity(currentState, sensorNumericalDeviceClasses)) ||
|
|
||||||
numericStateFromHistory != null;
|
|
||||||
|
|
||||||
if (isNumeric) {
|
if (isNumeric) {
|
||||||
unit =
|
unit =
|
||||||
@ -551,3 +549,18 @@ export const computeGroupKey = (
|
|||||||
device_class: string | undefined,
|
device_class: string | undefined,
|
||||||
splitDeviceClasses: boolean
|
splitDeviceClasses: boolean
|
||||||
) => (splitDeviceClasses ? `${unit}_${device_class || ""}` : unit);
|
) => (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 { computeGroupDomain } from "../../data/group";
|
||||||
import { CONTINUOUS_DOMAINS } from "../../data/logbook";
|
import { CONTINUOUS_DOMAINS } from "../../data/logbook";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
|
import { isNumericEntity } from "../../data/history";
|
||||||
|
|
||||||
export const DOMAINS_NO_INFO = ["camera", "configurator"];
|
export const DOMAINS_NO_INFO = ["camera", "configurator"];
|
||||||
/**
|
/**
|
||||||
@ -98,20 +99,27 @@ export const computeShowHistoryComponent = (
|
|||||||
|
|
||||||
export const computeShowLogBookComponent = (
|
export const computeShowLogBookComponent = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entityId: string
|
entityId: string,
|
||||||
|
sensorNumericalDeviceClasses: string[] = []
|
||||||
): boolean => {
|
): boolean => {
|
||||||
if (!isComponentLoaded(hass, "logbook")) {
|
if (!isComponentLoaded(hass, "logbook")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const stateObj = hass.states[entityId];
|
const stateObj = hass.states[entityId];
|
||||||
if (!stateObj || stateObj.attributes.unit_of_measurement) {
|
if (!stateObj) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const domain = computeDomain(entityId);
|
const domain = computeDomain(entityId);
|
||||||
if (
|
if (
|
||||||
CONTINUOUS_DOMAINS.includes(domain) ||
|
(CONTINUOUS_DOMAINS.includes(domain) &&
|
||||||
|
isNumericEntity(
|
||||||
|
domain,
|
||||||
|
stateObj,
|
||||||
|
undefined,
|
||||||
|
sensorNumericalDeviceClasses
|
||||||
|
)) ||
|
||||||
DOMAINS_MORE_INFO_NO_HISTORY.includes(domain)
|
DOMAINS_MORE_INFO_NO_HISTORY.includes(domain)
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -52,6 +52,7 @@ import "./ha-more-info-info";
|
|||||||
import type { MoreInfoInfo } from "./ha-more-info-info";
|
import type { MoreInfoInfo } from "./ha-more-info-info";
|
||||||
import "./ha-more-info-settings";
|
import "./ha-more-info-settings";
|
||||||
import "./more-info-content";
|
import "./more-info-content";
|
||||||
|
import { getSensorNumericDeviceClasses } from "../../data/sensor";
|
||||||
|
|
||||||
export interface MoreInfoDialogParams {
|
export interface MoreInfoDialogParams {
|
||||||
entityId: string | null;
|
entityId: string | null;
|
||||||
@ -101,6 +102,8 @@ export class MoreInfoDialog extends LitElement {
|
|||||||
@query("ha-more-info-info, ha-more-info-history-and-logbook")
|
@query("ha-more-info-info, ha-more-info-history-and-logbook")
|
||||||
private _history?: MoreInfoInfo | MoreInfoHistoryAndLogbook;
|
private _history?: MoreInfoInfo | MoreInfoHistoryAndLogbook;
|
||||||
|
|
||||||
|
@state() private _sensorNumericDeviceClasses?: string[] = [];
|
||||||
|
|
||||||
public showDialog(params: MoreInfoDialogParams) {
|
public showDialog(params: MoreInfoDialogParams) {
|
||||||
this._entityId = params.entityId;
|
this._entityId = params.entityId;
|
||||||
if (!this._entityId) {
|
if (!this._entityId) {
|
||||||
@ -161,7 +164,11 @@ export class MoreInfoDialog extends LitElement {
|
|||||||
return (
|
return (
|
||||||
DOMAINS_WITH_MORE_INFO.includes(domain) &&
|
DOMAINS_WITH_MORE_INFO.includes(domain) &&
|
||||||
(computeShowHistoryComponent(this.hass, this._entityId!) ||
|
(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");
|
this._setView("related");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _loadNumericDeviceClasses() {
|
||||||
|
const deviceClasses = await getSensorNumericDeviceClasses(this.hass);
|
||||||
|
this._sensorNumericDeviceClasses = deviceClasses.numeric_device_classes;
|
||||||
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
if (!this._entityId) {
|
if (!this._entityId) {
|
||||||
return nothing;
|
return nothing;
|
||||||
@ -515,6 +527,7 @@ export class MoreInfoDialog extends LitElement {
|
|||||||
protected firstUpdated(changedProps: PropertyValues) {
|
protected firstUpdated(changedProps: PropertyValues) {
|
||||||
super.firstUpdated(changedProps);
|
super.firstUpdated(changedProps);
|
||||||
this.addEventListener("close-dialog", () => this.closeDialog());
|
this.addEventListener("close-dialog", () => this.closeDialog());
|
||||||
|
this._loadNumericDeviceClasses();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected updated(changedProps: PropertyValues) {
|
protected updated(changedProps: PropertyValues) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import type { CSSResultGroup } from "lit";
|
import type { CSSResultGroup } from "lit";
|
||||||
import { css, html, LitElement } 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 { ChartResizeOptions } from "../../components/chart/ha-chart-base";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import {
|
import {
|
||||||
@ -10,6 +10,7 @@ import {
|
|||||||
import "./ha-more-info-history";
|
import "./ha-more-info-history";
|
||||||
import type { MoreInfoHistory } from "./ha-more-info-history";
|
import type { MoreInfoHistory } from "./ha-more-info-history";
|
||||||
import "./ha-more-info-logbook";
|
import "./ha-more-info-logbook";
|
||||||
|
import { getSensorNumericDeviceClasses } from "../../data/sensor";
|
||||||
|
|
||||||
@customElement("ha-more-info-history-and-logbook")
|
@customElement("ha-more-info-history-and-logbook")
|
||||||
export class MoreInfoHistoryAndLogbook extends LitElement {
|
export class MoreInfoHistoryAndLogbook extends LitElement {
|
||||||
@ -20,6 +21,18 @@ export class MoreInfoHistoryAndLogbook extends LitElement {
|
|||||||
@query("ha-more-info-history")
|
@query("ha-more-info-history")
|
||||||
private _history?: MoreInfoHistory;
|
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) {
|
public resize(options?: ChartResizeOptions) {
|
||||||
this._history?.resize(options);
|
this._history?.resize(options);
|
||||||
}
|
}
|
||||||
@ -34,7 +47,11 @@ export class MoreInfoHistoryAndLogbook extends LitElement {
|
|||||||
></ha-more-info-history>
|
></ha-more-info-history>
|
||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
${computeShowLogBookComponent(this.hass, this.entityId)
|
${computeShowLogBookComponent(
|
||||||
|
this.hass,
|
||||||
|
this.entityId,
|
||||||
|
this._sensorNumericDeviceClasses
|
||||||
|
)
|
||||||
? html`
|
? html`
|
||||||
<ha-more-info-logbook
|
<ha-more-info-logbook
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import type { HassEntity } from "home-assistant-js-websocket";
|
import type { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { css, html, LitElement, nothing } from "lit";
|
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 { computeDomain } from "../../common/entity/compute_domain";
|
||||||
import type { ChartResizeOptions } from "../../components/chart/ha-chart-base";
|
import type { ChartResizeOptions } from "../../components/chart/ha-chart-base";
|
||||||
import type { ExtEntityRegistryEntry } from "../../data/entity_registry";
|
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 type { MoreInfoHistory } from "./ha-more-info-history";
|
||||||
import "./ha-more-info-logbook";
|
import "./ha-more-info-logbook";
|
||||||
import "./more-info-content";
|
import "./more-info-content";
|
||||||
|
import { getSensorNumericDeviceClasses } from "../../data/sensor";
|
||||||
|
|
||||||
@customElement("ha-more-info-info")
|
@customElement("ha-more-info-info")
|
||||||
export class MoreInfoInfo extends LitElement {
|
export class MoreInfoInfo extends LitElement {
|
||||||
@ -28,9 +29,21 @@ export class MoreInfoInfo extends LitElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public editMode?: boolean;
|
@property({ attribute: false }) public editMode?: boolean;
|
||||||
|
|
||||||
|
@state() private _sensorNumericDeviceClasses?: string[] = [];
|
||||||
|
|
||||||
@query("ha-more-info-history")
|
@query("ha-more-info-history")
|
||||||
private _history?: MoreInfoHistory;
|
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) {
|
public resize(options?: ChartResizeOptions) {
|
||||||
this._history?.resize(options);
|
this._history?.resize(options);
|
||||||
}
|
}
|
||||||
@ -85,7 +98,11 @@ export class MoreInfoInfo extends LitElement {
|
|||||||
.entityId=${this.entityId}
|
.entityId=${this.entityId}
|
||||||
></ha-more-info-history>`}
|
></ha-more-info-history>`}
|
||||||
${DOMAINS_WITH_MORE_INFO.includes(domain) ||
|
${DOMAINS_WITH_MORE_INFO.includes(domain) ||
|
||||||
!computeShowLogBookComponent(this.hass, entityId)
|
!computeShowLogBookComponent(
|
||||||
|
this.hass,
|
||||||
|
entityId,
|
||||||
|
this._sensorNumericDeviceClasses
|
||||||
|
)
|
||||||
? ""
|
? ""
|
||||||
: html`<ha-more-info-logbook
|
: html`<ha-more-info-logbook
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user