diff --git a/demo/src/stubs/config_entries.ts b/demo/src/stubs/config_entries.ts index 9f23475d435a..bed9a11c1557 100644 --- a/demo/src/stubs/config_entries.ts +++ b/demo/src/stubs/config_entries.ts @@ -11,7 +11,7 @@ export const mockConfigEntries = (hass: MockHomeAssistant) => { supports_remove_device: false, supports_unload: true, supports_reconfigure: true, - supported_subentries: [], + supported_subentry_flows: [], pref_disable_new_entities: false, pref_disable_polling: false, disabled_by: null, diff --git a/gallery/src/pages/misc/integration-card.ts b/gallery/src/pages/misc/integration-card.ts index 3e3af36030a8..a3135d2098d0 100644 --- a/gallery/src/pages/misc/integration-card.ts +++ b/gallery/src/pages/misc/integration-card.ts @@ -32,7 +32,7 @@ const createConfigEntry = ( supports_remove_device: false, supports_unload: true, supports_reconfigure: true, - supported_subentries: [], + supported_subentry_flows: [], num_subentries: 0, disabled_by: null, pref_disable_new_entities: false, diff --git a/src/data/config_entries.ts b/src/data/config_entries.ts index 82b1cc5d8094..b1b4e6f19893 100644 --- a/src/data/config_entries.ts +++ b/src/data/config_entries.ts @@ -19,7 +19,9 @@ export interface ConfigEntry { supports_remove_device: boolean; supports_unload: boolean; supports_reconfigure: boolean; - supported_subentries: string[]; + supported_subentry_flows: { + [key: string]: { supports_reconfigure: boolean }; + }; num_subentries: number; pref_disable_new_entities: boolean; pref_disable_polling: boolean; diff --git a/src/data/sub_config_flow.ts b/src/data/sub_config_flow.ts index 1dbad1cc098e..3e78bde395ec 100644 --- a/src/data/sub_config_flow.ts +++ b/src/data/sub_config_flow.ts @@ -8,7 +8,8 @@ const HEADERS = { export const createSubConfigFlow = ( hass: HomeAssistant, configEntryId: string, - subFlowType: string + subFlowType: string, + subentry_id?: string ) => hass.callApi( "POST", @@ -16,6 +17,8 @@ export const createSubConfigFlow = ( { handler: [configEntryId, subFlowType], show_advanced_options: Boolean(hass.userData?.showAdvanced), + subentry_id, + source: subentry_id ? "reconfigure" : "user", }, HEADERS ); diff --git a/src/dialogs/config-flow/show-dialog-config-flow.ts b/src/dialogs/config-flow/show-dialog-config-flow.ts index dd0aaa438e0b..f94d1687d3a2 100644 --- a/src/dialogs/config-flow/show-dialog-config-flow.ts +++ b/src/dialogs/config-flow/show-dialog-config-flow.ts @@ -16,7 +16,9 @@ export const loadConfigFlowDialog = loadDataEntryFlowDialog; export const showConfigFlowDialog = ( element: HTMLElement, - dialogParams: Omit + dialogParams: Omit & { + entryId?: string; + } ): void => showFlowDialog(element, dialogParams, { flowType: "config_flow", diff --git a/src/dialogs/config-flow/show-dialog-data-entry-flow.ts b/src/dialogs/config-flow/show-dialog-data-entry-flow.ts index bb1d2bbba226..3d67b2e9c556 100644 --- a/src/dialogs/config-flow/show-dialog-data-entry-flow.ts +++ b/src/dialogs/config-flow/show-dialog-data-entry-flow.ts @@ -148,7 +148,6 @@ export interface DataEntryFlowDialogParams { }) => void; flowConfig: FlowConfig; showAdvanced?: boolean; - entryId?: string; dialogParentElement?: HTMLElement; } diff --git a/src/dialogs/config-flow/show-dialog-sub-config-flow.ts b/src/dialogs/config-flow/show-dialog-sub-config-flow.ts index 74071427b2a0..bc886985b272 100644 --- a/src/dialogs/config-flow/show-dialog-sub-config-flow.ts +++ b/src/dialogs/config-flow/show-dialog-sub-config-flow.ts @@ -19,14 +19,16 @@ export const showSubConfigFlowDialog = ( element: HTMLElement, configEntry: ConfigEntry, flowType: string, - dialogParams: Omit + dialogParams: Omit & { + subEntryId?: string; + } ): void => showFlowDialog(element, dialogParams, { flowType: "config_subentries_flow", showDevices: true, createFlow: async (hass, handler) => { const [step] = await Promise.all([ - createSubConfigFlow(hass, handler, flowType), + createSubConfigFlow(hass, handler, flowType, dialogParams.subEntryId), hass.loadFragmentTranslation("config"), hass.loadBackendTranslation("config_subentries", configEntry.domain), hass.loadBackendTranslation("selector", configEntry.domain), diff --git a/src/panels/config/integrations/ha-config-integration-page.ts b/src/panels/config/integrations/ha-config-integration-page.ts index 7073e1507d53..69c206a597d2 100644 --- a/src/panels/config/integrations/ha-config-integration-page.ts +++ b/src/panels/config/integrations/ha-config-integration-page.ts @@ -940,7 +940,7 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) { )} - ${item.supported_subentries.map( + ${Object.keys(item.supported_subentry_flows).map( (flowType) => html` + ${configEntry.supported_subentry_flows.add_entity?.supports_reconfigure + ? html` + + ${this.hass.localize( + "ui.panel.config.integrations.config_entry.configure" + )} + + ` + : nothing} { + const configEntry = ( + (ev.target as HTMLElement).closest(".sub-entry") as any + ).configEntry; + const subEntry = ((ev.target as HTMLElement).closest(".sub-entry") as any) + .subConfigEntry; + + // const flow = configEntry.supported_subentry_flows[subEntry.subentry_id]; + + showSubConfigFlowDialog( + this, + configEntry, + subEntry.flowType || "add_entity", + { + startFlowHandler: configEntry.entry_id, + subEntryId: subEntry.subentry_id, + } + ); + } + private async _handleDeleteSub(ev: Event): Promise { const configEntry = ( (ev.target as HTMLElement).closest(".sub-entry") as any diff --git a/src/panels/config/integrations/ha-config-integrations-dashboard.ts b/src/panels/config/integrations/ha-config-integrations-dashboard.ts index ca4ec46f1dda..455f889f6471 100644 --- a/src/panels/config/integrations/ha-config-integrations-dashboard.ts +++ b/src/panels/config/integrations/ha-config-integrations-dashboard.ts @@ -204,7 +204,7 @@ class HaConfigIntegrationsDashboard extends SubscribeMixin(LitElement) { supports_remove_device: false, supports_unload: false, supports_reconfigure: false, - supported_subentries: [], + supported_subentry_flows: [], num_subentries: 0, pref_disable_new_entities: false, pref_disable_polling: false,