mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-08 09:56:36 +00:00
Fix History Panel when no entities are found (#13103)
This commit is contained in:
parent
153ebb2a20
commit
2094ae534b
@ -314,11 +314,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,7 +340,7 @@ 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 === undefined ||
|
||||||
this._entities === undefined ||
|
this._entities === undefined ||
|
||||||
@ -344,7 +350,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 +359,23 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
|
|||||||
entity_id: searchingEntityId,
|
entity_id: searchingEntityId,
|
||||||
} = this._targetPickerValue;
|
} = this._targetPickerValue;
|
||||||
|
|
||||||
if (searchingAreaId !== undefined) {
|
if (searchingAreaId) {
|
||||||
searchingAreaId =
|
searchingAreaId =
|
||||||
typeof searchingAreaId === "string"
|
typeof searchingAreaId === "string"
|
||||||
? [searchingAreaId]
|
? [searchingAreaId]
|
||||||
: 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 +393,14 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (searchingDeviceId !== undefined) {
|
if (searchingDeviceId) {
|
||||||
searchingDeviceId =
|
searchingDeviceId =
|
||||||
typeof searchingDeviceId === "string"
|
typeof searchingDeviceId === "string"
|
||||||
? [searchingDeviceId]
|
? [searchingDeviceId]
|
||||||
: 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,6 +408,7 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (searchingEntityId !== undefined) {
|
if (searchingEntityId !== undefined) {
|
||||||
searchingEntityId =
|
searchingEntityId =
|
||||||
@ -417,6 +419,7 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
|
|||||||
entityIds.add(singleSearchingEntityId);
|
entityIds.add(singleSearchingEntityId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return [...entityIds];
|
return [...entityIds];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -441,7 +444,7 @@ 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(",");
|
params.entity_id = this._getEntityIds()?.join(",") || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._startDate) {
|
if (this._startDate) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user