mirror of
https://github.com/home-assistant/frontend.git
synced 2026-04-25 20:12:48 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user