More error handling for preview flow (#25611)

* More error handling for preview flow

* await unsub
This commit is contained in:
karwosts 2025-05-27 21:04:03 -07:00 committed by GitHub
parent 38f8c804af
commit e8fc36026a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 0 deletions

View File

@ -6,6 +6,7 @@ const HAS_CUSTOM_PREVIEW = ["generic_camera", "template"];
export interface GenericPreview {
state: string;
attributes: Record<string, any>;
error?: string;
}
export const subscribePreviewGeneric = (

View File

@ -58,6 +58,11 @@ export class FlowPreviewGeneric extends LitElement {
}
private _setPreview = (preview: GenericPreview) => {
if (preview.error) {
this._error = preview.error;
this._preview = undefined;
return;
}
const now = new Date().toISOString();
this._preview = {
entity_id: `${this.stepId}.___flow_preview___`,
@ -80,6 +85,7 @@ export class FlowPreviewGeneric extends LitElement {
if (this.flowType !== "config_flow" && this.flowType !== "options_flow") {
return;
}
this._error = undefined;
try {
this._unsub = subscribePreviewGeneric(
this.hass,
@ -89,6 +95,7 @@ export class FlowPreviewGeneric extends LitElement {
this.stepData,
this._setPreview
);
await this._unsub;
fireEvent(this, "set-flow-errors", { errors: {} });
} catch (err: any) {
if (typeof err.message === "string") {