|
|
@@ -1,4 +1,4 @@
|
|
|
|
import { mdiCollapseAll, mdiRefresh } from "@mdi/js";
|
|
|
|
import { mdiFilterRemove, mdiRefresh } from "@mdi/js";
|
|
|
|
import "@polymer/app-layout/app-header/app-header";
|
|
|
|
import "@polymer/app-layout/app-header/app-header";
|
|
|
|
import "@polymer/app-layout/app-toolbar/app-toolbar";
|
|
|
|
import "@polymer/app-layout/app-toolbar/app-toolbar";
|
|
|
|
import {
|
|
|
|
import {
|
|
|
@@ -10,10 +10,14 @@ import {
|
|
|
|
startOfWeek,
|
|
|
|
startOfWeek,
|
|
|
|
startOfYesterday,
|
|
|
|
startOfYesterday,
|
|
|
|
} from "date-fns/esm";
|
|
|
|
} from "date-fns/esm";
|
|
|
|
import { UnsubscribeFunc } from "home-assistant-js-websocket/dist/types";
|
|
|
|
import {
|
|
|
|
|
|
|
|
HassServiceTarget,
|
|
|
|
|
|
|
|
UnsubscribeFunc,
|
|
|
|
|
|
|
|
} from "home-assistant-js-websocket/dist/types";
|
|
|
|
import { css, html, LitElement, PropertyValues } from "lit";
|
|
|
|
import { css, html, LitElement, PropertyValues } from "lit";
|
|
|
|
import { property, state } from "lit/decorators";
|
|
|
|
import { property, state } from "lit/decorators";
|
|
|
|
import { LocalStorage } from "../../common/decorators/local-storage";
|
|
|
|
import { LocalStorage } from "../../common/decorators/local-storage";
|
|
|
|
|
|
|
|
import { ensureArray } from "../../common/ensure-array";
|
|
|
|
import { computeDomain } from "../../common/entity/compute_domain";
|
|
|
|
import { computeDomain } from "../../common/entity/compute_domain";
|
|
|
|
import { computeStateName } from "../../common/entity/compute_state_name";
|
|
|
|
import { computeStateName } from "../../common/entity/compute_state_name";
|
|
|
|
import { navigate } from "../../common/navigate";
|
|
|
|
import { navigate } from "../../common/navigate";
|
|
|
@@ -54,7 +58,8 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
|
|
|
|
|
|
|
|
|
|
|
|
@state() private _endDate: Date;
|
|
|
|
@state() private _endDate: Date;
|
|
|
|
|
|
|
|
|
|
|
|
@LocalStorage("historyPickedValue", true, false) private _targetPickerValue?;
|
|
|
|
@LocalStorage("historyPickedValue", true, false)
|
|
|
|
|
|
|
|
private _targetPickerValue?: HassServiceTarget;
|
|
|
|
|
|
|
|
|
|
|
|
@state() private _isLoading = false;
|
|
|
|
@state() private _isLoading = false;
|
|
|
|
|
|
|
|
|
|
|
@@ -160,7 +165,7 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
|
|
|
|
<ha-icon-button
|
|
|
|
<ha-icon-button
|
|
|
|
@click=${this._removeAll}
|
|
|
|
@click=${this._removeAll}
|
|
|
|
.disabled=${this._isLoading}
|
|
|
|
.disabled=${this._isLoading}
|
|
|
|
.path=${mdiCollapseAll}
|
|
|
|
.path=${mdiFilterRemove}
|
|
|
|
.label=${this.hass.localize("ui.panel.history.remove_all")}
|
|
|
|
.label=${this.hass.localize("ui.panel.history.remove_all")}
|
|
|
|
></ha-icon-button>
|
|
|
|
></ha-icon-button>
|
|
|
|
`
|
|
|
|
`
|
|
|
@@ -189,7 +194,7 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
|
|
|
|
.value=${this._targetPickerValue}
|
|
|
|
.value=${this._targetPickerValue}
|
|
|
|
.disabled=${this._isLoading}
|
|
|
|
.disabled=${this._isLoading}
|
|
|
|
horizontal
|
|
|
|
horizontal
|
|
|
|
@value-changed=${this._entitiesChanged}
|
|
|
|
@value-changed=${this._targetsChanged}
|
|
|
|
></ha-target-picker>
|
|
|
|
></ha-target-picker>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
${this._isLoading
|
|
|
|
${this._isLoading
|
|
|
@@ -217,8 +222,12 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
|
|
|
|
`;
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected firstUpdated(changedProps: PropertyValues) {
|
|
|
|
public willUpdate(changedProps: PropertyValues) {
|
|
|
|
super.firstUpdated(changedProps);
|
|
|
|
super.willUpdate(changedProps);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.hasUpdated) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const today = new Date();
|
|
|
|
const today = new Date();
|
|
|
|
const weekStart = startOfWeek(today);
|
|
|
|
const weekStart = startOfWeek(today);
|
|
|
@@ -238,11 +247,22 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const entityIds = extractSearchParam("entity_id");
|
|
|
|
const entityIds = extractSearchParam("entity_id");
|
|
|
|
|
|
|
|
const deviceIds = extractSearchParam("device_id");
|
|
|
|
|
|
|
|
const areaIds = extractSearchParam("area_id");
|
|
|
|
|
|
|
|
if (entityIds || deviceIds || areaIds) {
|
|
|
|
|
|
|
|
this._targetPickerValue = {};
|
|
|
|
|
|
|
|
}
|
|
|
|
if (entityIds) {
|
|
|
|
if (entityIds) {
|
|
|
|
const splitEntityIds = entityIds.split(",");
|
|
|
|
const splitIds = entityIds.split(",");
|
|
|
|
this._targetPickerValue = {
|
|
|
|
this._targetPickerValue!.entity_id = splitIds;
|
|
|
|
entity_id: splitEntityIds,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (deviceIds) {
|
|
|
|
|
|
|
|
const splitIds = deviceIds.split(",");
|
|
|
|
|
|
|
|
this._targetPickerValue!.device_id = splitIds;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (areaIds) {
|
|
|
|
|
|
|
|
const splitIds = areaIds.split(",");
|
|
|
|
|
|
|
|
this._targetPickerValue!.area_id = splitIds;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const startDate = extractSearchParam("start_date");
|
|
|
|
const startDate = extractSearchParam("start_date");
|
|
|
@@ -314,11 +334,17 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
|
|
|
|
this._isLoading = true;
|
|
|
|
this._isLoading = true;
|
|
|
|
const entityIds = this._getEntityIds();
|
|
|
|
const entityIds = this._getEntityIds();
|
|
|
|
|
|
|
|
|
|
|
|
if (!entityIds.length) {
|
|
|
|
if (entityIds === undefined) {
|
|
|
|
this._stateHistory = undefined;
|
|
|
|
this._stateHistory = undefined;
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (entityIds.length === 0) {
|
|
|
|
|
|
|
|
this._isLoading = false;
|
|
|
|
|
|
|
|
this._stateHistory = [];
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const dateHistory = await fetchDateWS(
|
|
|
|
const dateHistory = await fetchDateWS(
|
|
|
|
this.hass,
|
|
|
|
this.hass,
|
|
|
|
this._startDate,
|
|
|
|
this._startDate,
|
|
|
@@ -334,9 +360,9 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
|
|
|
|
this._isLoading = false;
|
|
|
|
this._isLoading = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private _getEntityIds(): string[] {
|
|
|
|
private _getEntityIds(): string[] | undefined {
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
this._targetPickerValue === undefined ||
|
|
|
|
!this._targetPickerValue ||
|
|
|
|
this._entities === undefined ||
|
|
|
|
this._entities === undefined ||
|
|
|
|
this._stateEntities === undefined ||
|
|
|
|
this._stateEntities === undefined ||
|
|
|
|
this._devices === undefined ||
|
|
|
|
this._devices === undefined ||
|
|
|
@@ -344,7 +370,7 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
|
|
|
|
this._areaIdToEntities === undefined ||
|
|
|
|
this._areaIdToEntities === undefined ||
|
|
|
|
this._areaIdToDevices === undefined
|
|
|
|
this._areaIdToDevices === undefined
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
return [];
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const entityIds = new Set<string>();
|
|
|
|
const entityIds = new Set<string>();
|
|
|
|
let {
|
|
|
|
let {
|
|
|
@@ -353,25 +379,20 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
|
|
|
|
entity_id: searchingEntityId,
|
|
|
|
entity_id: searchingEntityId,
|
|
|
|
} = this._targetPickerValue;
|
|
|
|
} = this._targetPickerValue;
|
|
|
|
|
|
|
|
|
|
|
|
if (searchingAreaId !== undefined) {
|
|
|
|
if (searchingAreaId) {
|
|
|
|
searchingAreaId =
|
|
|
|
searchingAreaId = ensureArray(searchingAreaId);
|
|
|
|
typeof searchingAreaId === "string"
|
|
|
|
|
|
|
|
? [searchingAreaId]
|
|
|
|
|
|
|
|
: searchingAreaId;
|
|
|
|
|
|
|
|
for (const singleSearchingAreaId of searchingAreaId) {
|
|
|
|
for (const singleSearchingAreaId of searchingAreaId) {
|
|
|
|
const foundEntities = this._areaIdToEntities[singleSearchingAreaId];
|
|
|
|
const foundEntities = this._areaIdToEntities[singleSearchingAreaId];
|
|
|
|
if (!foundEntities) {
|
|
|
|
if (foundEntities?.length) {
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const foundEntity of foundEntities) {
|
|
|
|
for (const foundEntity of foundEntities) {
|
|
|
|
if (foundEntity.entity_category === null) {
|
|
|
|
if (foundEntity.entity_category === null) {
|
|
|
|
entityIds.add(foundEntity.entity_id);
|
|
|
|
entityIds.add(foundEntity.entity_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const foundDevices = this._areaIdToDevices[singleSearchingAreaId];
|
|
|
|
const foundDevices = this._areaIdToDevices[singleSearchingAreaId];
|
|
|
|
if (foundDevices !== undefined) {
|
|
|
|
if (foundDevices) {
|
|
|
|
for (const foundDevice of foundDevices) {
|
|
|
|
for (const foundDevice of foundDevices) {
|
|
|
|
const foundDeviceEntities =
|
|
|
|
const foundDeviceEntities =
|
|
|
|
this._deviceIdToEntities[foundDevice.id];
|
|
|
|
this._deviceIdToEntities[foundDevice.id];
|
|
|
@@ -389,17 +410,11 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (searchingDeviceId !== undefined) {
|
|
|
|
if (searchingDeviceId) {
|
|
|
|
searchingDeviceId =
|
|
|
|
searchingDeviceId = ensureArray(searchingDeviceId);
|
|
|
|
typeof searchingDeviceId === "string"
|
|
|
|
|
|
|
|
? [searchingDeviceId]
|
|
|
|
|
|
|
|
: searchingDeviceId;
|
|
|
|
|
|
|
|
for (const singleSearchingDeviceId of searchingDeviceId) {
|
|
|
|
for (const singleSearchingDeviceId of searchingDeviceId) {
|
|
|
|
const foundEntities = this._deviceIdToEntities[singleSearchingDeviceId];
|
|
|
|
const foundEntities = this._deviceIdToEntities[singleSearchingDeviceId];
|
|
|
|
if (!foundEntities) {
|
|
|
|
if (foundEntities?.length) {
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const foundEntity of foundEntities) {
|
|
|
|
for (const foundEntity of foundEntities) {
|
|
|
|
if (foundEntity.entity_category === null) {
|
|
|
|
if (foundEntity.entity_category === null) {
|
|
|
|
entityIds.add(foundEntity.entity_id);
|
|
|
|
entityIds.add(foundEntity.entity_id);
|
|
|
@@ -407,16 +422,15 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (searchingEntityId !== undefined) {
|
|
|
|
if (searchingEntityId !== undefined) {
|
|
|
|
searchingEntityId =
|
|
|
|
searchingEntityId = ensureArray(searchingEntityId);
|
|
|
|
typeof searchingEntityId === "string"
|
|
|
|
|
|
|
|
? [searchingEntityId]
|
|
|
|
|
|
|
|
: searchingEntityId;
|
|
|
|
|
|
|
|
for (const singleSearchingEntityId of searchingEntityId) {
|
|
|
|
for (const singleSearchingEntityId of searchingEntityId) {
|
|
|
|
entityIds.add(singleSearchingEntityId);
|
|
|
|
entityIds.add(singleSearchingEntityId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return [...entityIds];
|
|
|
|
return [...entityIds];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@@ -432,7 +446,7 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
|
|
|
|
this._updatePath();
|
|
|
|
this._updatePath();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private _entitiesChanged(ev) {
|
|
|
|
private _targetsChanged(ev) {
|
|
|
|
this._targetPickerValue = ev.detail.value;
|
|
|
|
this._targetPickerValue = ev.detail.value;
|
|
|
|
this._updatePath();
|
|
|
|
this._updatePath();
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -441,7 +455,19 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
|
|
|
|
const params: Record<string, string> = {};
|
|
|
|
const params: Record<string, string> = {};
|
|
|
|
|
|
|
|
|
|
|
|
if (this._targetPickerValue) {
|
|
|
|
if (this._targetPickerValue) {
|
|
|
|
params.entity_id = this._getEntityIds().join(",");
|
|
|
|
if (this._targetPickerValue.entity_id) {
|
|
|
|
|
|
|
|
params.entity_id = ensureArray(this._targetPickerValue.entity_id).join(
|
|
|
|
|
|
|
|
","
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._targetPickerValue.area_id) {
|
|
|
|
|
|
|
|
params.area_id = ensureArray(this._targetPickerValue.area_id).join(",");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._targetPickerValue.device_id) {
|
|
|
|
|
|
|
|
params.device_id = ensureArray(this._targetPickerValue.device_id).join(
|
|
|
|
|
|
|
|
","
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (this._startDate) {
|
|
|
|
if (this._startDate) {
|
|
|
|