-
-
-
+
+
+
+
+
+ ${this._isLoading
+ ? html`
+
+
`
+ : html`
+
+
+ `}
${this._isLoading
? html`
@@ -142,7 +177,13 @@ class HaPanelHistory extends LitElement {
[addDays(weekStart, -7), addDays(weekEnd, -7)],
};
- this._entityId = extractSearchParam("entity_id") ?? "";
+ const entityIds = extractSearchParam("entity_id");
+ if (entityIds) {
+ const splitEntityIds = entityIds.split(",");
+ this._targetPickerValue = {
+ entity_id: splitEntityIds,
+ };
+ }
const startDate = extractSearchParam("start_date");
if (startDate) {
@@ -158,16 +199,41 @@ class HaPanelHistory extends LitElement {
if (
changedProps.has("_startDate") ||
changedProps.has("_endDate") ||
- changedProps.has("_entityId")
+ changedProps.has("_targetPickerValue") ||
+ changedProps.has("_entities")
) {
this._getHistory();
}
- if (changedProps.has("hass")) {
+ if (changedProps.has("hass") || changedProps.has("_entities")) {
const oldHass = changedProps.get("hass") as HomeAssistant | undefined;
if (!oldHass || oldHass.language !== this.hass.language) {
this.rtl = computeRTL(this.hass);
}
+ if (this._entities) {
+ const stateEntities: EntityRegistryEntry[] = [];
+ const regEntityIds = new Set(
+ this._entities.map((entity) => entity.entity_id)
+ );
+ for (const entityId of Object.keys(this.hass.states)) {
+ if (regEntityIds.has(entityId)) {
+ continue;
+ }
+ stateEntities.push({
+ name: computeStateName(this.hass.states[entityId]),
+ entity_id: entityId,
+ platform: computeDomain(entityId),
+ disabled_by: null,
+ hidden_by: null,
+ area_id: null,
+ config_entry_id: null,
+ device_id: null,
+ icon: null,
+ entity_category: null,
+ });
+ }
+ this._stateEntities = stateEntities;
+ }
}
}
@@ -177,12 +243,16 @@ class HaPanelHistory extends LitElement {
private async _getHistory() {
this._isLoading = true;
- const dateHistory = await fetchDateWS(
- this.hass,
- this._startDate,
- this._endDate,
- this._entityId
- );
+ const entityIds = this._getEntityIds();
+ const dateHistory =
+ entityIds.length === 0
+ ? {}
+ : await fetchDateWS(
+ this.hass,
+ this._startDate,
+ this._endDate,
+ entityIds
+ );
this._stateHistory = computeHistory(
this.hass,
dateHistory,
@@ -191,6 +261,52 @@ class HaPanelHistory extends LitElement {
this._isLoading = false;
}
+ private _filterEntity(entity: EntityRegistryEntry): boolean {
+ const { area_id, device_id, entity_id } = this._targetPickerValue;
+ if (area_id !== undefined) {
+ if (typeof area_id === "string" && area_id === entity.area_id) {
+ return true;
+ }
+ if (Array.isArray(area_id) && area_id.includes(entity.area_id)) {
+ return true;
+ }
+ }
+ if (device_id !== undefined) {
+ if (typeof device_id === "string" && device_id === entity.device_id) {
+ return true;
+ }
+ if (Array.isArray(device_id) && device_id.includes(entity.device_id)) {
+ return true;
+ }
+ }
+ if (entity_id !== undefined) {
+ if (typeof entity_id === "string" && entity_id === entity.entity_id) {
+ return true;
+ }
+ if (Array.isArray(entity_id) && entity_id.includes(entity.entity_id)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private _getEntityIds(): string[] {
+ if (
+ this._targetPickerValue === undefined ||
+ this._entities === undefined ||
+ this._stateEntities === undefined
+ ) {
+ return [];
+ }
+ const entityIds = this._entities
+ .filter((entity) => this._filterEntity(entity))
+ .map((entity) => entity.entity_id);
+ const stateEntityIds = this._stateEntities
+ .filter((entity) => this._filterEntity(entity))
+ .map((entity) => entity.entity_id);
+ return [...entityIds, ...stateEntityIds];
+ }
+
private _dateRangeChanged(ev) {
this._startDate = ev.detail.startDate;
const endDate = ev.detail.endDate;
@@ -203,8 +319,8 @@ class HaPanelHistory extends LitElement {
this._updatePath();
}
- private _entityPicked(ev) {
- this._entityId = ev.target.value;
+ private _entitiesChanged(ev) {
+ this._targetPickerValue = ev.detail.value;
this._updatePath();
}
@@ -212,8 +328,8 @@ class HaPanelHistory extends LitElement {
private _updatePath() {
const params: Record = {};
- if (this._entityId) {
- params.entity_id = this._entityId;
+ if (this._targetPickerValue) {
+ params.entity_id = this._getEntityIds().join(",");
}
if (this._startDate) {
@@ -255,6 +371,18 @@ class HaPanelHistory extends LitElement {
height: 100%;
}
+ :host([narrow]) .narrow-wrap {
+ flex-wrap: wrap;
+ }
+
+ .horizontal {
+ align-items: center;
+ }
+
+ :host(:not([narrow])) .selector-padding {
+ padding-left: 32px;
+ }
+
.progress-wrapper {
position: relative;
}