Skip to content

Commit

Permalink
WIP, not functional
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten committed Jan 6, 2025
1 parent f53d3e4 commit 7908c06
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 10 deletions.
2 changes: 1 addition & 1 deletion demo/src/stubs/config_entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion gallery/src/pages/misc/integration-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const createConfigEntry = (
supports_remove_device: false,
supports_unload: true,
supports_reconfigure: true,
supported_subentries: [],
supported_subentry_flows: [],

Check failure on line 35 in gallery/src/pages/misc/integration-card.ts

View workflow job for this annotation

GitHub Actions / Lint and check format

Type 'never[]' is not assignable to type '{ [key: string]: { supports_reconfigure: boolean; }; }'.
num_subentries: 0,
disabled_by: null,
pref_disable_new_entities: false,
Expand Down
4 changes: 3 additions & 1 deletion src/data/config_entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/data/sub_config_flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ const HEADERS = {
export const createSubConfigFlow = (
hass: HomeAssistant,
configEntryId: string,
subFlowType: string
subFlowType: string,
subentry_id?: string
) =>
hass.callApi<DataEntryFlowStep>(
"POST",
"config/config_entries/subentries/flow",
{
handler: [configEntryId, subFlowType],
show_advanced_options: Boolean(hass.userData?.showAdvanced),
subentry_id,
source: subentry_id ? "reconfigure" : "user",
},
HEADERS
);
Expand Down
4 changes: 3 additions & 1 deletion src/dialogs/config-flow/show-dialog-config-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export const loadConfigFlowDialog = loadDataEntryFlowDialog;

export const showConfigFlowDialog = (
element: HTMLElement,
dialogParams: Omit<DataEntryFlowDialogParams, "flowConfig">
dialogParams: Omit<DataEntryFlowDialogParams, "flowConfig"> & {
entryId?: string;
}
): void =>
showFlowDialog(element, dialogParams, {
flowType: "config_flow",
Expand Down
1 change: 0 additions & 1 deletion src/dialogs/config-flow/show-dialog-data-entry-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ export interface DataEntryFlowDialogParams {
}) => void;
flowConfig: FlowConfig;
showAdvanced?: boolean;
entryId?: string;
dialogParentElement?: HTMLElement;
}

Expand Down
6 changes: 4 additions & 2 deletions src/dialogs/config-flow/show-dialog-sub-config-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ export const showSubConfigFlowDialog = (
element: HTMLElement,
configEntry: ConfigEntry,
flowType: string,
dialogParams: Omit<DataEntryFlowDialogParams, "flowConfig">
dialogParams: Omit<DataEntryFlowDialogParams, "flowConfig"> & {
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),
Expand Down
31 changes: 30 additions & 1 deletion src/panels/config/integrations/ha-config-integration-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
)}
</ha-md-menu-item>
${item.supported_subentries.map(
${Object.keys(item.supported_subentry_flows).map(
(flowType) =>
html`<ha-md-menu-item
@click=${this._addSubEntry}
Expand Down Expand Up @@ -1065,6 +1065,15 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
subEntry
)}</span
>
${configEntry.supported_subentry_flows.add_entity?.supports_reconfigure
? html`
<ha-button slot="end" @click=${this._handleReconfigureSub}>
${this.hass.localize(
"ui.panel.config.integrations.config_entry.configure"
)}
</ha-button>
`
: nothing}
<ha-md-button-menu positioning="popover" slot="end">
<ha-icon-button
slot="trigger"
Expand Down Expand Up @@ -1291,6 +1300,26 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
);
}

private async _handleReconfigureSub(ev: Event): Promise<void> {
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<void> {
const configEntry = (
(ev.target as HTMLElement).closest(".sub-entry") as any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7908c06

Please sign in to comment.