mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Filter unrecorded entities from history panel (#19621)
* Filter unrecorded entities from history panel * cache result * Cache excluded entities instead of recorded entities
This commit is contained in:
parent
5fab1969a8
commit
d88670034a
@ -12,6 +12,14 @@ export interface RecorderInfo {
|
|||||||
thread_running: boolean;
|
thread_running: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface RecordedEntities {
|
||||||
|
entity_ids: string[];
|
||||||
|
}
|
||||||
|
export interface RecordedExcludedEntities {
|
||||||
|
recorded_ids: string[];
|
||||||
|
excluded_ids: string[];
|
||||||
|
}
|
||||||
|
|
||||||
export type StatisticType = "change" | "state" | "sum" | "min" | "max" | "mean";
|
export type StatisticType = "change" | "state" | "sum" | "min" | "max" | "mean";
|
||||||
|
|
||||||
export interface Statistics {
|
export interface Statistics {
|
||||||
@ -324,3 +332,25 @@ export const getDisplayUnit = (
|
|||||||
|
|
||||||
export const isExternalStatistic = (statisticsId: string): boolean =>
|
export const isExternalStatistic = (statisticsId: string): boolean =>
|
||||||
statisticsId.includes(":");
|
statisticsId.includes(":");
|
||||||
|
|
||||||
|
let recordedExcludedEntitiesCache: RecordedExcludedEntities | undefined;
|
||||||
|
|
||||||
|
export const getRecordedExcludedEntities = async (
|
||||||
|
hass: HomeAssistant
|
||||||
|
): Promise<RecordedExcludedEntities> => {
|
||||||
|
if (recordedExcludedEntitiesCache) {
|
||||||
|
return recordedExcludedEntitiesCache;
|
||||||
|
}
|
||||||
|
const recordedEntities = await hass.callWS<RecordedEntities>({
|
||||||
|
type: "recorder/recorded_entities",
|
||||||
|
});
|
||||||
|
|
||||||
|
recordedExcludedEntitiesCache = {
|
||||||
|
recorded_ids: recordedEntities.entity_ids,
|
||||||
|
excluded_ids: Object.keys(hass.states).filter(
|
||||||
|
(id) => !recordedEntities.entity_ids.includes(id)
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
return recordedExcludedEntitiesCache;
|
||||||
|
};
|
||||||
|
@ -6,6 +6,7 @@ import {
|
|||||||
} from "@mdi/js";
|
} from "@mdi/js";
|
||||||
import { ActionDetail } from "@material/mwc-list";
|
import { ActionDetail } from "@material/mwc-list";
|
||||||
import { differenceInHours } from "date-fns";
|
import { differenceInHours } from "date-fns";
|
||||||
|
import { HassEntity } from "home-assistant-js-websocket";
|
||||||
import {
|
import {
|
||||||
HassServiceTarget,
|
HassServiceTarget,
|
||||||
UnsubscribeFunc,
|
UnsubscribeFunc,
|
||||||
@ -45,7 +46,11 @@ import {
|
|||||||
computeHistory,
|
computeHistory,
|
||||||
subscribeHistory,
|
subscribeHistory,
|
||||||
} from "../../data/history";
|
} from "../../data/history";
|
||||||
import { Statistics, fetchStatistics } from "../../data/recorder";
|
import {
|
||||||
|
fetchStatistics,
|
||||||
|
Statistics,
|
||||||
|
getRecordedExcludedEntities,
|
||||||
|
} from "../../data/recorder";
|
||||||
import {
|
import {
|
||||||
expandAreaTarget,
|
expandAreaTarget,
|
||||||
expandDeviceTarget,
|
expandDeviceTarget,
|
||||||
@ -95,6 +100,8 @@ class HaPanelHistory extends LitElement {
|
|||||||
|
|
||||||
private _interval?: number;
|
private _interval?: number;
|
||||||
|
|
||||||
|
private _excludedEntities?: string[];
|
||||||
|
|
||||||
public constructor() {
|
public constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
@ -185,6 +192,7 @@ class HaPanelHistory extends LitElement {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.value=${this._targetPickerValue}
|
.value=${this._targetPickerValue}
|
||||||
.disabled=${this._isLoading}
|
.disabled=${this._isLoading}
|
||||||
|
.entityFilter=${this._entityFilter}
|
||||||
addOnTop
|
addOnTop
|
||||||
@value-changed=${this._targetsChanged}
|
@value-changed=${this._targetsChanged}
|
||||||
></ha-target-picker>
|
></ha-target-picker>
|
||||||
@ -211,6 +219,10 @@ class HaPanelHistory extends LitElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _entityFilter = (entity: HassEntity): boolean =>
|
||||||
|
!this._excludedEntities ||
|
||||||
|
!this._excludedEntities.includes(entity.entity_id);
|
||||||
|
|
||||||
private mergeHistoryResults(
|
private mergeHistoryResults(
|
||||||
ltsResult: HistoryResult,
|
ltsResult: HistoryResult,
|
||||||
historyResult: HistoryResult
|
historyResult: HistoryResult
|
||||||
@ -362,8 +374,17 @@ class HaPanelHistory extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _getRecordedExcludedEntities() {
|
||||||
|
const { recorded_ids: _recordedIds, excluded_ids: excludedIds } =
|
||||||
|
await getRecordedExcludedEntities(this.hass);
|
||||||
|
this._excludedEntities = excludedIds;
|
||||||
|
}
|
||||||
|
|
||||||
protected firstUpdated(changedProps: PropertyValues) {
|
protected firstUpdated(changedProps: PropertyValues) {
|
||||||
super.firstUpdated(changedProps);
|
super.firstUpdated(changedProps);
|
||||||
|
|
||||||
|
this._getRecordedExcludedEntities();
|
||||||
|
|
||||||
const searchParams = extractSearchParamsObject();
|
const searchParams = extractSearchParamsObject();
|
||||||
if (searchParams.back === "1" && history.length > 1) {
|
if (searchParams.back === "1" && history.length > 1) {
|
||||||
this._showBack = true;
|
this._showBack = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user