fix reload history when no selection made (#13137)

This commit is contained in:
Bram Kragten 2022-07-07 14:58:51 +02:00 committed by GitHub
parent e8086b6a6f
commit 24688ba18e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -121,7 +121,7 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
: ""} : ""}
<ha-icon-button <ha-icon-button
@click=${this._getHistory} @click=${this._getHistory}
.disabled=${this._isLoading} .disabled=${this._isLoading || !this._targetPickerValue}
.path=${mdiRefresh} .path=${mdiRefresh}
.label=${this.hass.localize("ui.common.refresh")} .label=${this.hass.localize("ui.common.refresh")}
></ha-icon-button> ></ha-icon-button>
@ -254,10 +254,14 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
} }
private async _getHistory() { private async _getHistory() {
if (!this._targetPickerValue) {
return;
}
this._isLoading = true; this._isLoading = true;
const entityIds = this._getEntityIds(); const entityIds = this._getEntityIds();
if (entityIds === undefined) { if (entityIds === undefined) {
this._isLoading = false;
this._stateHistory = undefined; this._stateHistory = undefined;
return; return;
} }
@ -267,20 +271,22 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
this._stateHistory = []; this._stateHistory = [];
return; return;
} }
try {
const dateHistory = await fetchDateWS(
this.hass,
this._startDate,
this._endDate,
entityIds
);
const dateHistory = await fetchDateWS( this._stateHistory = computeHistory(
this.hass, this.hass,
this._startDate, dateHistory,
this._endDate, this.hass.localize
entityIds );
); } finally {
this._isLoading = false;
this._stateHistory = computeHistory( }
this.hass,
dateHistory,
this.hass.localize
);
this._isLoading = false;
} }
private _getEntityIds(): string[] | undefined { private _getEntityIds(): string[] | undefined {