Handle lazy loaded entity registry when editing scripts from more info (#51438)

* Handle lazy loaded entity registry when editing scripts from more info

* Remove extra check

* Fix type of mixin
This commit is contained in:
Aidan Timson
2026-04-07 15:07:21 +01:00
committed by GitHub
parent 1eda51ddbc
commit 2a2bca2a61
3 changed files with 11 additions and 8 deletions

View File

@@ -147,7 +147,7 @@ export class HaAutomationEditor extends AutomationScriptEditorMixin<AutomationCo
this._newAutomationId &&
changedProps.has("entityRegistry")
) {
const automation = this.entityRegistry.find(
const automation = this.entityRegistry?.find(
(entity: EntityRegistryEntry) =>
entity.platform === "automation" &&
entity.unique_id === this._newAutomationId

View File

@@ -94,7 +94,7 @@ export const AutomationScriptEditorMixin = <TConfig extends BaseEditorConfig>(
@state()
@consume({ context: fullEntitiesContext, subscribe: true })
entityRegistry!: EntityRegistryEntry[];
entityRegistry?: EntityRegistryEntry[];
@state() protected dirty = false;
@@ -235,7 +235,7 @@ export const AutomationScriptEditorMixin = <TConfig extends BaseEditorConfig>(
goBack("/config");
return;
}
const entity = this.entityRegistry.find(
const entity = this.entityRegistry?.find(
(ent) => ent.platform === domain && ent.unique_id === id
);
if (entity) {

View File

@@ -112,7 +112,7 @@ export class HaScriptEditor extends SubscribeMixin(
this._newScriptId &&
changedProps.has("entityRegistry")
) {
const script = this.entityRegistry.find(
const script = this.entityRegistry?.find(
(entity: EntityRegistryEntry) =>
entity.platform === "script" && entity.unique_id === this._newScriptId
);
@@ -486,6 +486,9 @@ export class HaScriptEditor extends SubscribeMixin(
}
private _setEntityId() {
if (!this.entityRegistry) {
return;
}
const entity = this.entityRegistry.find(
(ent) => ent.platform === "script" && ent.unique_id === this.scriptId
);
@@ -535,7 +538,7 @@ export class HaScriptEditor extends SubscribeMixin(
this.config = normalizeScriptConfig(c.config);
this._checkValidation();
});
const regEntry = this.entityRegistry.find(
const regEntry = this.entityRegistry?.find(
(ent) => ent.entity_id === this.entityId
);
if (regEntry?.unique_id) {
@@ -629,7 +632,7 @@ export class HaScriptEditor extends SubscribeMixin(
private _idIsUsed(id: string): boolean {
return (
`script.${id}` in this.hass.states ||
this.entityRegistry.some((ent) => ent.unique_id === id)
(this.entityRegistry?.some((ent) => ent.unique_id === id) ?? false)
);
}
@@ -637,7 +640,7 @@ export class HaScriptEditor extends SubscribeMixin(
if (!this.scriptId) {
return;
}
const entity = this.entityRegistry.find(
const entity = this.entityRegistry?.find(
(entry) => entry.unique_id === this.scriptId
);
if (!entity) {
@@ -817,7 +820,7 @@ export class HaScriptEditor extends SubscribeMixin(
},
onClose: () => resolve(false),
entityRegistryUpdate: this.entityRegistryUpdate,
entityRegistryEntry: this.entityRegistry.find(
entityRegistryEntry: this.entityRegistry?.find(
(entry) => entry.unique_id === this.scriptId
),
});