Merge pull request #13126 from home-assistant/dev

20220706.0
This commit is contained in:
Bram Kragten 2022-07-06 18:56:12 +02:00 committed by GitHub
commit 4358437278
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 79 additions and 49 deletions

View File

@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "home-assistant-frontend"
version = "20220705.0"
version = "20220706.0"
license = {text = "Apache-2.0"}
description = "The Home Assistant frontend"
readme = "README.md"

View File

@ -76,7 +76,11 @@ class Storage {
public setValue(storageKey: string, value: any): any {
this._storage[storageKey] = value;
try {
window.localStorage.setItem(storageKey, JSON.stringify(value));
if (value === undefined) {
window.localStorage.removeItem(storageKey);
} else {
window.localStorage.setItem(storageKey, JSON.stringify(value));
}
} catch (err: any) {
// Safari in private mode doesn't allow localstorage
}

View File

@ -637,7 +637,7 @@ export class HaSceneEditor extends SubscribeMixin(
Object.keys(config.entities).forEach((entity) => {
if (
!this._single_entities.includes(entity) &&
config.metadata![entity].entity_only
config.metadata![entity]?.entity_only
) {
this._single_entities.push(entity);
}

View File

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