Fix todo url (#18954)

* Fix todo url

* Move searchParams

* Update src/panels/todo/ha-panel-todo.ts

* check if saved entity exists

---------

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
Simon Lamon 2023-12-08 13:35:57 +01:00 committed by GitHub
parent 6d36b0e28c
commit c9e6963387
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,7 +46,10 @@ import { HuiErrorCard } from "../lovelace/cards/hui-error-card";
import { createCardElement } from "../lovelace/create-element/create-card-element";
import { LovelaceCard } from "../lovelace/types";
import { navigate } from "../../common/navigate";
import { createSearchParam } from "../../common/url/search-params";
import {
createSearchParam,
extractSearchParam,
} from "../../common/url/search-params";
import { constructUrlCurrentPath } from "../../common/url/construct-url";
@customElement("ha-panel-todo")
@ -105,18 +108,21 @@ class PanelTodo extends LitElement {
if (!this.hasUpdated) {
this.hass.loadFragmentTranslation("lovelace");
const urlEntityId = extractSearchParam("entity_id");
if (urlEntityId) {
this._entityId = urlEntityId;
} else {
if (this._entityId && !(this._entityId in this.hass.states)) {
this._entityId = undefined;
}
if (!this._entityId) {
this._entityId = getTodoLists(this.hass)[0]?.entity_id;
}
}
}
if (!this.hasUpdated && !this._entityId) {
this._entityId = getTodoLists(this.hass)[0]?.entity_id;
} else if (!this.hasUpdated) {
this._setupTodoElement();
}
}
protected updated(changedProperties: PropertyValues): void {
super.updated(changedProperties);
if (changedProperties.has("_entityId")) {
if (changedProperties.has("_entityId") || !this.hasUpdated) {
this._setupTodoElement();
}