Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/data/data_entry_flow.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -59,26 +60,31 @@ export interface DataEntryFlowStepExternal {
translation_domain?: string;
}

export interface DataEntryFlowStepCreateEntry {
export interface DataEntryFlowStepCreateEntry<
Tresult extends ConfigEntry | RepairsIssue = ConfigEntry,
Comment thread
MindFreeze marked this conversation as resolved.
Outdated
> {
type: "create_entry";
version: number;
flow_id: string;
next_flow?: [FlowType, string]; // [flow_type, flow_id]
handler: string;
title: string;
result?: ConfigEntry;
result?: Tresult;
Comment thread
MindFreeze marked this conversation as resolved.
Outdated
description: string;
description_placeholders?: Record<string, string>;
translation_domain?: string;
}

export interface DataEntryFlowStepAbort {
export interface DataEntryFlowStepAbort<
Tresult extends ConfigEntry | RepairsIssue = ConfigEntry,
Comment thread
MindFreeze marked this conversation as resolved.
Outdated
> {
type: "abort";
flow_id: string;
handler: string;
reason: string;
description_placeholders?: Record<string, string>;
translation_domain?: string;
result?: Tresult;
Comment thread
MindFreeze marked this conversation as resolved.
Outdated
next_flow?: [FlowType, string]; // [flow_type, flow_id]
}

Expand Down
42 changes: 27 additions & 15 deletions src/dialogs/config-flow/dialog-data-entry-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 "../../panels/config/repairs/show-dialog-repair-flow";
import "./step-flow-abort";
import "./step-flow-create-entry";
import "./step-flow-external";
Expand Down Expand Up @@ -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,
});
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
)}
></step-flow-create-entry>
Expand Down Expand Up @@ -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
);

Expand Down Expand Up @@ -629,21 +635,27 @@ class DataEntryFlowDialog extends LitElement {
dialogClosedCallback: this._params!.dialogClosedCallback,
});
} else if (_step.next_flow[0] === "options_flow") {
if (_step.type === "create_entry") {
Comment thread
iluvdata marked this conversation as resolved.
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!, "", {
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)!,
Comment thread
MindFreeze marked this conversation as resolved.
Outdated
{
continueFlowId: _step.next_flow[1],
navigateToResult: this._params!.navigateToResult,
dialogClosedCallback: this._params!.dialogClosedCallback,
});
}
}
);
} else {
this.closeDialog();
showAlertDialog(this, {
Expand Down
6 changes: 4 additions & 2 deletions src/dialogs/config-flow/step-flow-create-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<ConfigEntry>;

@property({ attribute: false }) public devices!: DeviceRegistryEntry[];

Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/panels/config/entities/entity-registry-settings-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ export class EntityRegistrySettingsEditor extends LitElement {
invert: this._switchAsInvert,
target_domain: this._switchAsDomain,
}
)) as DataEntryFlowStepCreateEntry;
)) as DataEntryFlowStepCreateEntry<ConfigEntry>;
if (configFlowResult.result?.entry_id) {
try {
const entry = await this._waitForEntityRegistryUpdate(
Expand Down Expand Up @@ -1275,7 +1275,7 @@ export class EntityRegistrySettingsEditor extends LitElement {
invert: this._switchAsInvert,
target_domain: this._switchAsDomain,
}
)) as DataEntryFlowStepCreateEntry;
)) as DataEntryFlowStepCreateEntry<ConfigEntry>;
if (configFlowResult.result?.entry_id) {
try {
const entry = await this._waitForEntityRegistryUpdate(
Expand Down
5 changes: 3 additions & 2 deletions src/panels/config/repairs/show-dialog-repair-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
fetchRepairsFlow,
handleRepairsFlowStep,
} from "../../../data/repairs";
import type { DataEntryFlowDialogParams } from "../../../dialogs/config-flow/show-dialog-data-entry-flow";
import {
loadDataEntryFlowDialog,
showFlowDialog,
Expand Down Expand Up @@ -36,14 +37,14 @@ export const loadRepairFlowDialog = loadDataEntryFlowDialog;
export const showRepairsFlowDialog = (
element: HTMLElement,
issue: RepairsIssue,
dialogClosedCallback?: (params: { flowFinished: boolean }) => void
dialogParams?: Omit<DataEntryFlowDialogParams, "flowConfig">
): void =>
showFlowDialog(
element,
{
startFlowHandler: issue.domain,
domain: issue.domain,
dialogClosedCallback,
...dialogParams,
},
{
flowType: "repair_flow",
Expand Down
Loading