Optimize undefined checks and don't fetch history twice

This commit is contained in:
Christopher Altona 2022-06-30 02:43:13 +00:00
parent 8b007610f9
commit 049af5b00c

View File

@ -99,7 +99,7 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
return accumulator; return accumulator;
}, {}); }, {});
this._deviceIdToEntities = entities.reduce((accumulator, current) => { this._deviceIdToEntities = entities.reduce((accumulator, current) => {
if (current.device_id === undefined || current.device_id === null) { if (!current.device_id) {
return accumulator; return accumulator;
} }
let found = accumulator[current.device_id]; let found = accumulator[current.device_id];
@ -111,7 +111,7 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
return accumulator; return accumulator;
}, {}); }, {});
this._areaIdToEntities = entities.reduce((accumulator, current) => { this._areaIdToEntities = entities.reduce((accumulator, current) => {
if (current.area_id === undefined || current.area_id === null) { if (!current.area_id) {
return accumulator; return accumulator;
} }
let found = accumulator[current.area_id]; let found = accumulator[current.area_id];
@ -129,7 +129,7 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
return accumulator; return accumulator;
}, {}); }, {});
this._areaIdToDevices = devices.reduce((accumulator, current) => { this._areaIdToDevices = devices.reduce((accumulator, current) => {
if (current.area_id === undefined || current.area_id === null) { if (!current.area_id) {
return accumulator; return accumulator;
} }
let found = accumulator[current.area_id]; let found = accumulator[current.area_id];
@ -201,7 +201,7 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
></ha-circular-progress> ></ha-circular-progress>
</div>` </div>`
: this._targetPickerValue === undefined : this._targetPickerValue === undefined
? html` <div class="start-search"> ? html`<div class="start-search">
${this.hass.localize("ui.panel.history.start_search")} ${this.hass.localize("ui.panel.history.start_search")}
</div>` </div>`
: html` : html`
@ -303,12 +303,10 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
private _showAll() { private _showAll() {
this._targetPickerValue = { entity_id: Object.keys(this._entities ?? {}) }; this._targetPickerValue = { entity_id: Object.keys(this._entities ?? {}) };
this._getHistory();
} }
private _removeAll() { private _removeAll() {
this._targetPickerValue = undefined; this._targetPickerValue = undefined;
this._getHistory();
} }
private _refreshHistory() { private _refreshHistory() {