diff --git a/src/data/data_entry_flow.ts b/src/data/data_entry_flow.ts index 5a0aa7a66c7a..ea0344617690 100644 --- a/src/data/data_entry_flow.ts +++ b/src/data/data_entry_flow.ts @@ -1,6 +1,7 @@ import type { Connection } from "home-assistant-js-websocket"; import type { HaFormSchema } from "../components/ha-form/types"; import type { ConfigEntry } from "./config_entries"; +import type { RepairsIssue } from "./repairs"; export type FlowType = | "config_flow" @@ -59,26 +60,31 @@ export interface DataEntryFlowStepExternal { translation_domain?: string; } -export interface DataEntryFlowStepCreateEntry { +export interface DataEntryFlowStepCreateEntry< + TResult extends ConfigEntry | RepairsIssue = ConfigEntry, +> { type: "create_entry"; version: number; flow_id: string; next_flow?: [FlowType, string]; // [flow_type, flow_id] handler: string; title: string; - result?: ConfigEntry; + result?: TResult; description: string; description_placeholders?: Record; translation_domain?: string; } -export interface DataEntryFlowStepAbort { +export interface DataEntryFlowStepAbort< + TResult extends ConfigEntry | RepairsIssue = ConfigEntry, +> { type: "abort"; flow_id: string; handler: string; reason: string; description_placeholders?: Record; translation_domain?: string; + result?: TResult; next_flow?: [FlowType, string]; // [flow_type, flow_id] } diff --git a/src/dialogs/config-flow/dialog-data-entry-flow.ts b/src/dialogs/config-flow/dialog-data-entry-flow.ts index e8895635aef7..e6895c12cfea 100644 --- a/src/dialogs/config-flow/dialog-data-entry-flow.ts +++ b/src/dialogs/config-flow/dialog-data-entry-flow.ts @@ -11,12 +11,14 @@ import "../../components/ha-button"; import "../../components/ha-dialog"; import "../../components/ha-dialog-footer"; import "../../components/ha-icon-button"; +import type { ConfigEntry } from "../../data/config_entries"; import type { DataEntryFlowStep } from "../../data/data_entry_flow"; import { subscribeDataEntryFlowProgress, subscribeDataEntryFlowProgressed, } from "../../data/data_entry_flow"; import type { DeviceRegistryEntry } from "../../data/device/device_registry"; +import type { RepairsIssue } from "../../data/repairs"; import { haStyleDialog } from "../../resources/styles"; import type { HomeAssistant } from "../../types"; import { documentationUrl } from "../../util/documentation-url"; @@ -28,6 +30,7 @@ import type { } from "./show-dialog-data-entry-flow"; import { showOptionsFlowDialog } from "./show-dialog-options-flow"; import { showSubConfigFlowDialog } from "./show-dialog-sub-config-flow"; +import { showRepairsFlowDialog } from "../repairs-flow/show-dialog-repair-flow"; import "./step-flow-abort"; import "./step-flow-create-entry"; import "./step-flow-external"; @@ -207,7 +210,9 @@ class DataEntryFlowDialog extends LitElement { this._params.dialogClosedCallback({ flowFinished, entryId: - "result" in this._step ? this._step.result?.entry_id : undefined, + "result" in this._step + ? (this._step.result as ConfigEntry)?.entry_id + : undefined, }); } @@ -267,7 +272,7 @@ class DataEntryFlowDialog extends LitElement { const devicesLength = this._devices( this._params.flowConfig.showDevices, Object.values(this.hass.devices), - this._step.result?.entry_id, + (this._step.result as ConfigEntry)?.entry_id, this._params.carryOverDevices ).length; return this.hass.localize( @@ -457,7 +462,8 @@ class DataEntryFlowDialog extends LitElement { .devices=${this._devices( this._params.flowConfig.showDevices, Object.values(this.hass.devices), - this._step.result?.entry_id, + (this._step.result as ConfigEntry) + ?.entry_id, this._params.carryOverDevices )} > @@ -525,7 +531,7 @@ class DataEntryFlowDialog extends LitElement { const devices = this._devices( this._params!.flowConfig.showDevices, Object.values(this.hass.devices), - this._step.result?.entry_id, + (this._step.result as ConfigEntry)?.entry_id, this._params!.carryOverDevices ); @@ -629,21 +635,23 @@ class DataEntryFlowDialog extends LitElement { dialogClosedCallback: this._params!.dialogClosedCallback, }); } else if (_step.next_flow[0] === "options_flow") { - if (_step.type === "create_entry") { - showOptionsFlowDialog(this, _step.result!, { - continueFlowId: _step.next_flow[1], - navigateToResult: this._params!.navigateToResult, - dialogClosedCallback: this._params!.dialogClosedCallback, - }); - } + showOptionsFlowDialog(this, _step.result!, { + continueFlowId: _step.next_flow[1], + navigateToResult: this._params!.navigateToResult, + dialogClosedCallback: this._params!.dialogClosedCallback, + }); } else if (_step.next_flow[0] === "config_subentries_flow") { - if (_step.type === "create_entry") { - showSubConfigFlowDialog(this, _step.result!, "", { - continueFlowId: _step.next_flow[1], - navigateToResult: this._params!.navigateToResult, - dialogClosedCallback: this._params!.dialogClosedCallback, - }); - } + showSubConfigFlowDialog(this, _step.result!, "", { + continueFlowId: _step.next_flow[1], + navigateToResult: this._params!.navigateToResult, + dialogClosedCallback: this._params!.dialogClosedCallback, + }); + } else if (_step.next_flow[0] === "repair_flow") { + showRepairsFlowDialog(this, _step.result as unknown as RepairsIssue, { + continueFlowId: _step.next_flow[1], + navigateToResult: this._params!.navigateToResult, + dialogClosedCallback: this._params!.dialogClosedCallback, + }); } else { this.closeDialog(); showAlertDialog(this, { diff --git a/src/dialogs/config-flow/step-flow-create-entry.ts b/src/dialogs/config-flow/step-flow-create-entry.ts index 21b6964a4537..70d06e750de6 100644 --- a/src/dialogs/config-flow/step-flow-create-entry.ts +++ b/src/dialogs/config-flow/step-flow-create-entry.ts @@ -15,6 +15,7 @@ import type { HaInput } from "../../components/input/ha-input"; import { assistSatelliteSupportsSetupFlow } from "../../data/assist_satellite"; import { getConfigEntries } from "../../data/config_entries"; import type { DataEntryFlowStepCreateEntry } from "../../data/data_entry_flow"; +import type { ConfigEntry } from "../../data/config_entries"; import type { DeviceRegistryEntry } from "../../data/device/device_registry"; import { updateDeviceRegistryEntry } from "../../data/device/device_registry"; import { @@ -40,7 +41,8 @@ class StepFlowCreateEntry extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; - @property({ attribute: false }) public step!: DataEntryFlowStepCreateEntry; + @property({ attribute: false }) + public step!: DataEntryFlowStepCreateEntry; @property({ attribute: false }) public devices!: DeviceRegistryEntry[]; @@ -79,7 +81,7 @@ class StepFlowCreateEntry extends LitElement { if ( this.devices.length !== 1 || this.devices[0].primary_config_entry !== this.step.result?.entry_id || - this.step.result.domain === "voip" + this.step.result?.domain === "voip" ) { return; } diff --git a/src/panels/config/repairs/dialog-repairs-issue-subtitle.ts b/src/dialogs/repairs-flow/dialog-repairs-issue-subtitle.ts similarity index 89% rename from src/panels/config/repairs/dialog-repairs-issue-subtitle.ts rename to src/dialogs/repairs-flow/dialog-repairs-issue-subtitle.ts index bdaa68856184..1095771a02ad 100644 --- a/src/panels/config/repairs/dialog-repairs-issue-subtitle.ts +++ b/src/dialogs/repairs-flow/dialog-repairs-issue-subtitle.ts @@ -1,8 +1,8 @@ import { css, html, LitElement } from "lit"; import { customElement, property } from "lit/decorators"; -import type { HomeAssistant } from "../../../types"; -import { domainToName } from "../../../data/integration"; -import type { RepairsIssue } from "../../../data/repairs"; +import type { HomeAssistant } from "../../types"; +import { domainToName } from "../../data/integration"; +import type { RepairsIssue } from "../../data/repairs"; @customElement("dialog-repairs-issue-subtitle") class DialogRepairsIssueSubtitle extends LitElement { diff --git a/src/panels/config/repairs/show-dialog-repair-flow.ts b/src/dialogs/repairs-flow/show-dialog-repair-flow.ts similarity index 95% rename from src/panels/config/repairs/show-dialog-repair-flow.ts rename to src/dialogs/repairs-flow/show-dialog-repair-flow.ts index 2b2998e780fe..c148b2874099 100644 --- a/src/panels/config/repairs/show-dialog-repair-flow.ts +++ b/src/dialogs/repairs-flow/show-dialog-repair-flow.ts @@ -1,18 +1,19 @@ import { html, nothing } from "lit"; -import type { DataEntryFlowStep } from "../../../data/data_entry_flow"; -import { domainToName } from "../../../data/integration"; -import type { RepairsIssue } from "../../../data/repairs"; +import type { DataEntryFlowStep } from "../../data/data_entry_flow"; +import { domainToName } from "../../data/integration"; +import type { RepairsIssue } from "../../data/repairs"; import { createRepairsFlow, deleteRepairsFlow, fetchRepairsFlow, handleRepairsFlowStep, -} from "../../../data/repairs"; +} from "../../data/repairs"; +import type { DataEntryFlowDialogParams } from "../config-flow/show-dialog-data-entry-flow"; import { loadDataEntryFlowDialog, showFlowDialog, -} from "../../../dialogs/config-flow/show-dialog-data-entry-flow"; -import type { HomeAssistant } from "../../../types"; +} from "../config-flow/show-dialog-data-entry-flow"; +import type { HomeAssistant } from "../../types"; import "./dialog-repairs-issue-subtitle"; const mergePlaceholders = (issue: RepairsIssue, step: DataEntryFlowStep) => @@ -36,14 +37,14 @@ export const loadRepairFlowDialog = loadDataEntryFlowDialog; export const showRepairsFlowDialog = ( element: HTMLElement, issue: RepairsIssue, - dialogClosedCallback?: (params: { flowFinished: boolean }) => void + dialogParams?: Omit ): void => showFlowDialog( element, { startFlowHandler: issue.domain, domain: issue.domain, - dialogClosedCallback, + ...dialogParams, }, { flowType: "repair_flow", diff --git a/src/panels/config/entities/entity-registry-settings-editor.ts b/src/panels/config/entities/entity-registry-settings-editor.ts index 0cb96fba2ca5..cad116993894 100644 --- a/src/panels/config/entities/entity-registry-settings-editor.ts +++ b/src/panels/config/entities/entity-registry-settings-editor.ts @@ -1209,7 +1209,7 @@ export class EntityRegistrySettingsEditor extends LitElement { invert: this._switchAsInvert, target_domain: this._switchAsDomain, } - )) as DataEntryFlowStepCreateEntry; + )) as DataEntryFlowStepCreateEntry; if (configFlowResult.result?.entry_id) { try { const entry = await this._waitForEntityRegistryUpdate( @@ -1275,7 +1275,7 @@ export class EntityRegistrySettingsEditor extends LitElement { invert: this._switchAsInvert, target_domain: this._switchAsDomain, } - )) as DataEntryFlowStepCreateEntry; + )) as DataEntryFlowStepCreateEntry; if (configFlowResult.result?.entry_id) { try { const entry = await this._waitForEntityRegistryUpdate( diff --git a/src/panels/config/repairs/dialog-repairs-issue.ts b/src/panels/config/repairs/dialog-repairs-issue.ts index 1813e7821a01..b0d02a846e97 100644 --- a/src/panels/config/repairs/dialog-repairs-issue.ts +++ b/src/panels/config/repairs/dialog-repairs-issue.ts @@ -9,7 +9,7 @@ import "../../../components/ha-dialog"; import "../../../components/ha-button"; import "../../../components/ha-svg-icon"; import "../../../components/ha-dialog-footer"; -import "./dialog-repairs-issue-subtitle"; +import "../../../dialogs/repairs-flow/dialog-repairs-issue-subtitle"; import "../../../components/ha-markdown"; import type { RepairsIssue } from "../../../data/repairs"; import { ignoreRepairsIssue } from "../../../data/repairs"; diff --git a/src/panels/config/repairs/ha-config-repairs.ts b/src/panels/config/repairs/ha-config-repairs.ts index 9f50e16fbb47..1ea2d20991f3 100644 --- a/src/panels/config/repairs/ha-config-repairs.ts +++ b/src/panels/config/repairs/ha-config-repairs.ts @@ -20,7 +20,7 @@ import type { HomeAssistant } from "../../../types"; import { brandsUrl } from "../../../util/brands-url"; import { fixStatisticsIssue } from "../developer-tools/statistics/fix-statistics"; import { showVacuumSegmentMappingDialog } from "../entities/dialogs/show-dialog-vacuum-segment-mapping"; -import { showRepairsFlowDialog } from "./show-dialog-repair-flow"; +import { showRepairsFlowDialog } from "../../../dialogs/repairs-flow/show-dialog-repair-flow"; import { showRepairsIssueDialog } from "./show-repair-issue-dialog"; @customElement("ha-config-repairs")