Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reconfigure config entry #19794

Merged
merged 3 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions demo/src/stubs/config_entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const mockConfigEntries = (hass: MockHomeAssistant) => {
supports_options: false,
supports_remove_device: false,
supports_unload: true,
supports_reconfigure: true,
pref_disable_new_entities: false,
pref_disable_polling: false,
disabled_by: null,
Expand Down
1 change: 1 addition & 0 deletions gallery/src/pages/misc/integration-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const createConfigEntry = (
supports_options: false,
supports_remove_device: false,
supports_unload: true,
supports_reconfigure: true,
disabled_by: null,
pref_disable_new_entities: false,
pref_disable_polling: false,
Expand Down
1 change: 1 addition & 0 deletions src/data/config_entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface ConfigEntry {
supports_options: boolean;
supports_remove_device: boolean;
supports_unload: boolean;
supports_reconfigure: boolean;
pref_disable_new_entities: boolean;
pref_disable_polling: boolean;
disabled_by: "user" | null;
Expand Down
7 changes: 6 additions & 1 deletion src/data/config_flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ const HEADERS = {
"HA-Frontend-Base": `${location.protocol}//${location.host}`,
};

export const createConfigFlow = (hass: HomeAssistant, handler: string) =>
export const createConfigFlow = (
hass: HomeAssistant,
handler: string,
entry_id?: string
) =>
hass.callApi<DataEntryFlowStep>(
"POST",
"config/config_entries/flow",
{
handler,
show_advanced_options: Boolean(hass.userData?.showAdvanced),
entry_id,
},
HEADERS
);
Expand Down
2 changes: 1 addition & 1 deletion src/dialogs/config-flow/show-dialog-config-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const showConfigFlowDialog = (
loadDevicesAndAreas: true,
createFlow: async (hass, handler) => {
const [step] = await Promise.all([
createConfigFlow(hass, handler),
createConfigFlow(hass, handler, dialogParams.entryId),
hass.loadFragmentTranslation("config"),
hass.loadBackendTranslation("config", handler),
hass.loadBackendTranslation("selector", handler),
Expand Down
1 change: 1 addition & 0 deletions src/dialogs/config-flow/show-dialog-data-entry-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export interface DataEntryFlowDialogParams {
}) => void;
flowConfig: FlowConfig;
showAdvanced?: boolean;
entryId?: string;
dialogParentElement?: HTMLElement;
}

Expand Down
32 changes: 32 additions & 0 deletions src/panels/config/integrations/ha-config-integration-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
mdiRenameBox,
mdiShapeOutline,
mdiStopCircleOutline,
mdiWrench,
} from "@mdi/js";
import { UnsubscribeFunc } from "home-assistant-js-websocket";
import {
Expand Down Expand Up @@ -806,6 +807,19 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
</ha-list-item>
</a>`
: ""}
${!item.disabled_by &&
item.supports_reconfigure &&
item.source !== "system"
? html`<ha-list-item
@request-selected=${this._handleReconfigure}
graphic="icon"
>
${this.hass.localize(
"ui.panel.config.integrations.config_entry.reconfigure"
)}
<ha-svg-icon slot="graphic" .path=${mdiWrench}></ha-svg-icon>
</ha-list-item>`
: ""}

<ha-list-item
@request-selected=${this._handleSystemOptions}
Expand Down Expand Up @@ -1040,6 +1054,15 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
);
}

private _handleReconfigure(ev: CustomEvent<RequestSelectedDetail>): void {
if (!shouldHandleRequestSelectedEvent(ev)) {
return;
}
this._reconfigureIntegration(
((ev.target as HTMLElement).closest(".config_entry") as any).configEntry
);
}

private _handleDelete(ev: CustomEvent<RequestSelectedDetail>): void {
if (!shouldHandleRequestSelectedEvent(ev)) {
return;
Expand Down Expand Up @@ -1259,6 +1282,15 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
});
}

private async _reconfigureIntegration(configEntry: ConfigEntry) {
showConfigFlowDialog(this, {
startFlowHandler: configEntry.domain,
showAdvanced: this.hass.userData?.showAdvanced,
manifest: await fetchIntegrationManifest(this.hass, configEntry.domain),
entryId: configEntry.entry_id,
});
}

private async _editEntryName(configEntry: ConfigEntry) {
const newName = await showPromptDialog(this, {
title: this.hass.localize("ui.panel.config.integrations.rename_dialog"),
Expand Down
1 change: 1 addition & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3921,6 +3921,7 @@
"delete_confirm_title": "Delete {title}?",
"delete_confirm_text": "Its devices and entities will be permanently deleted.",
"enable_debug_logging": "Enable debug logging",
"reconfigure": "Reconfigure",
Copy link
Member

@frenck frenck Feb 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the step is called reconfigure, but from a user perspective, I think it is really confusing.

This shows best I guess:

CleanShot 2024-02-14 at 18 40 34

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are not the same as "Configure" is the options flow but "Reconfigure" is the reconfigure step within the config flow.
Not sure why "Configure" isn't actually called "Options" but anyhow yes, we need to think of some naming here or it might be confusing what's what.

Copy link
Member

@frenck frenck Feb 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are not the same as "Configure" is the options flow but "Reconfigure" is the reconfigure step within the config flow.

I have the context, hence me raising it 😉

Not sure why "Configure" isn't actually called "Options" but anyhow yes, we need to think of some naming here or it might be confusing what's what.

Honestly, I personally think that is the solution. Renaming existing "Configure" to "Options".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure it actually was called "Options" back in the days somewhere so not sure why it was renamed but I prefer also "Options" as the go to solution here. Thanks 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now updated the screenshot in the PR description to also include the change from "Configure" to "Options" for config entry options.

"reload": "Reload",
"restart_confirm": "Restart Home Assistant to finish removing this integration",
"reload_confirm": "The integration was reloaded",
Expand Down
Loading