mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Group history by device class (#18841)
This commit is contained in:
parent
861959ed2d
commit
219fc9e53a
@ -303,6 +303,11 @@ export class StateHistoryCharts extends LitElement {
|
|||||||
padding-right: 1px;
|
padding-right: 1px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.entry-container:not(:first-child) {
|
||||||
|
border-top: 2px solid var(--divider-color);
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
.container,
|
.container,
|
||||||
lit-virtualizer {
|
lit-virtualizer {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
@ -49,6 +49,7 @@ export interface LineChartEntity {
|
|||||||
|
|
||||||
export interface LineChartUnit {
|
export interface LineChartUnit {
|
||||||
unit: string;
|
unit: string;
|
||||||
|
device_class?: string;
|
||||||
identifier: string;
|
identifier: string;
|
||||||
data: LineChartEntity[];
|
data: LineChartEntity[];
|
||||||
}
|
}
|
||||||
@ -323,7 +324,8 @@ const processTimelineEntity = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
const processLineChartEntities = (
|
const processLineChartEntities = (
|
||||||
unit,
|
unit: string,
|
||||||
|
device_class: string | undefined,
|
||||||
entities: HistoryStates,
|
entities: HistoryStates,
|
||||||
hassEntities: HassEntities
|
hassEntities: HassEntities
|
||||||
): LineChartUnit => {
|
): LineChartUnit => {
|
||||||
@ -391,6 +393,7 @@ const processLineChartEntities = (
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
unit,
|
unit,
|
||||||
|
device_class,
|
||||||
identifier: Object.keys(entities).join(""),
|
identifier: Object.keys(entities).join(""),
|
||||||
data,
|
data,
|
||||||
};
|
};
|
||||||
@ -466,6 +469,12 @@ export const computeHistory = (
|
|||||||
}[domain];
|
}[domain];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const deviceClass: string | undefined = (
|
||||||
|
currentState?.attributes || numericStateFromHistory?.a
|
||||||
|
)?.device_class;
|
||||||
|
|
||||||
|
const key = computeGroupKey(unit, deviceClass);
|
||||||
|
|
||||||
if (!unit) {
|
if (!unit) {
|
||||||
timelineDevices.push(
|
timelineDevices.push(
|
||||||
processTimelineEntity(
|
processTimelineEntity(
|
||||||
@ -478,19 +487,32 @@ export const computeHistory = (
|
|||||||
currentState
|
currentState
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} else if (unit in lineChartDevices && entityId in lineChartDevices[unit]) {
|
} else if (key in lineChartDevices && entityId in lineChartDevices[key]) {
|
||||||
lineChartDevices[unit][entityId].push(...stateInfo);
|
lineChartDevices[key][entityId].push(...stateInfo);
|
||||||
} else {
|
} else {
|
||||||
if (!(unit in lineChartDevices)) {
|
if (!(key in lineChartDevices)) {
|
||||||
lineChartDevices[unit] = {};
|
lineChartDevices[key] = {};
|
||||||
}
|
}
|
||||||
lineChartDevices[unit][entityId] = stateInfo;
|
lineChartDevices[key][entityId] = stateInfo;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const unitStates = Object.keys(lineChartDevices).map((unit) =>
|
const unitStates = Object.keys(lineChartDevices).map((key) => {
|
||||||
processLineChartEntities(unit, lineChartDevices[unit], hass.states)
|
const splitKey = key.split("_");
|
||||||
);
|
const unit = splitKey[0];
|
||||||
|
const deviceClass = splitKey[1] || undefined;
|
||||||
|
return processLineChartEntities(
|
||||||
|
unit,
|
||||||
|
deviceClass,
|
||||||
|
lineChartDevices[key],
|
||||||
|
hass.states
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
return { line: unitStates, timeline: timelineDevices };
|
return { line: unitStates, timeline: timelineDevices };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const computeGroupKey = (
|
||||||
|
unit: string | undefined,
|
||||||
|
device_class: string | undefined
|
||||||
|
) => `${unit}_${device_class || ""}`;
|
||||||
|
@ -46,6 +46,7 @@ import {
|
|||||||
EntityHistoryState,
|
EntityHistoryState,
|
||||||
LineChartUnit,
|
LineChartUnit,
|
||||||
LineChartEntity,
|
LineChartEntity,
|
||||||
|
computeGroupKey,
|
||||||
} from "../../data/history";
|
} from "../../data/history";
|
||||||
import { fetchStatistics, Statistics } from "../../data/recorder";
|
import { fetchStatistics, Statistics } from "../../data/recorder";
|
||||||
import { getSensorNumericDeviceClasses } from "../../data/sensor";
|
import { getSensorNumericDeviceClasses } from "../../data/sensor";
|
||||||
@ -221,14 +222,20 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
|
|||||||
): HistoryResult {
|
): HistoryResult {
|
||||||
const result: HistoryResult = { ...historyResult, line: [] };
|
const result: HistoryResult = { ...historyResult, line: [] };
|
||||||
|
|
||||||
const units = new Set(
|
const keys = new Set(
|
||||||
historyResult.line
|
historyResult.line
|
||||||
.map((i) => i.unit)
|
.map((i) => computeGroupKey(i.unit, i.device_class))
|
||||||
.concat(ltsResult.line.map((i) => i.unit))
|
.concat(
|
||||||
|
ltsResult.line.map((i) => computeGroupKey(i.unit, i.device_class))
|
||||||
|
)
|
||||||
);
|
);
|
||||||
units.forEach((unit) => {
|
keys.forEach((key) => {
|
||||||
const historyItem = historyResult.line.find((i) => i.unit === unit);
|
const historyItem = historyResult.line.find(
|
||||||
const ltsItem = ltsResult.line.find((i) => i.unit === unit);
|
(i) => computeGroupKey(i.unit, i.device_class) === key
|
||||||
|
);
|
||||||
|
const ltsItem = ltsResult.line.find(
|
||||||
|
(i) => computeGroupKey(i.unit, i.device_class) === key
|
||||||
|
);
|
||||||
if (historyItem && ltsItem) {
|
if (historyItem && ltsItem) {
|
||||||
const newLineItem: LineChartUnit = { ...historyItem, data: [] };
|
const newLineItem: LineChartUnit = { ...historyItem, data: [] };
|
||||||
const entities = new Set(
|
const entities = new Set(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user