mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 11:46:42 +00:00
More error handling for preview flow (#25611)
* More error handling for preview flow * await unsub
This commit is contained in:
parent
38f8c804af
commit
e8fc36026a
@ -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 = (
|
||||||
|
@ -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") {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user