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 { export interface GenericPreview {
state: string; state: string;
attributes: Record<string, any>; attributes: Record<string, any>;
error?: string;
} }
export const subscribePreviewGeneric = ( export const subscribePreviewGeneric = (

View File

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