From 07368eee517e2bd9bdce5a4086bcfde397dba564 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Tue, 13 Feb 2024 20:12:11 +0000 Subject: [PATCH 1/3] Add reconfigure config entry --- demo/src/stubs/config_entries.ts | 1 + gallery/src/pages/misc/integration-card.ts | 1 + src/data/config_entries.ts | 1 + src/data/config_flow.ts | 7 +++- .../config-flow/show-dialog-config-flow.ts | 2 +- .../show-dialog-data-entry-flow.ts | 1 + .../ha-config-integration-page.ts | 33 +++++++++++++++++++ src/translations/en.json | 1 + 8 files changed, 45 insertions(+), 2 deletions(-) diff --git a/demo/src/stubs/config_entries.ts b/demo/src/stubs/config_entries.ts index 01a6da133e72..7891d08db5c7 100644 --- a/demo/src/stubs/config_entries.ts +++ b/demo/src/stubs/config_entries.ts @@ -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, diff --git a/gallery/src/pages/misc/integration-card.ts b/gallery/src/pages/misc/integration-card.ts index ad0e1f2bca38..c2b2f2c24d93 100644 --- a/gallery/src/pages/misc/integration-card.ts +++ b/gallery/src/pages/misc/integration-card.ts @@ -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, diff --git a/src/data/config_entries.ts b/src/data/config_entries.ts index f4c4cea7ca54..ab3d7480fd1d 100644 --- a/src/data/config_entries.ts +++ b/src/data/config_entries.ts @@ -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; diff --git a/src/data/config_flow.ts b/src/data/config_flow.ts index 27a2926a0d8c..279b00c2fe31 100644 --- a/src/data/config_flow.ts +++ b/src/data/config_flow.ts @@ -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, + source?: string +) => hass.callApi( "POST", "config/config_entries/flow", { handler, show_advanced_options: Boolean(hass.userData?.showAdvanced), + source: source, }, HEADERS ); diff --git a/src/dialogs/config-flow/show-dialog-config-flow.ts b/src/dialogs/config-flow/show-dialog-config-flow.ts index 9ccc58184015..30f549552068 100644 --- a/src/dialogs/config-flow/show-dialog-config-flow.ts +++ b/src/dialogs/config-flow/show-dialog-config-flow.ts @@ -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.source), hass.loadFragmentTranslation("config"), hass.loadBackendTranslation("config", handler), hass.loadBackendTranslation("selector", handler), 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 5dbd48e7b364..3df7547ba4f4 100644 --- a/src/dialogs/config-flow/show-dialog-data-entry-flow.ts +++ b/src/dialogs/config-flow/show-dialog-data-entry-flow.ts @@ -139,6 +139,7 @@ export interface DataEntryFlowDialogParams { }) => void; flowConfig: FlowConfig; showAdvanced?: boolean; + source?: string; dialogParentElement?: HTMLElement; } diff --git a/src/panels/config/integrations/ha-config-integration-page.ts b/src/panels/config/integrations/ha-config-integration-page.ts index 10e3fcd85fba..7b7b05dfa7f7 100644 --- a/src/panels/config/integrations/ha-config-integration-page.ts +++ b/src/panels/config/integrations/ha-config-integration-page.ts @@ -23,6 +23,7 @@ import { mdiRenameBox, mdiShapeOutline, mdiStopCircleOutline, + mdiWrench, } from "@mdi/js"; import { UnsubscribeFunc } from "home-assistant-js-websocket"; import { @@ -806,6 +807,20 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) { ` : ""} + ${!item.disabled_by && + RECOVERABLE_STATES.includes(item.state) && + item.supports_reconfigure && + item.source !== "system" + ? html` + ${this.hass.localize( + "ui.panel.config.integrations.config_entry.reconfigure" + )} + + ` + : ""} ): void { + if (!shouldHandleRequestSelectedEvent(ev)) { + return; + } + this._reconfigureIntegration( + ((ev.target as HTMLElement).closest(".config_entry") as any).configEntry + ); + } + private _handleDelete(ev: CustomEvent): void { if (!shouldHandleRequestSelectedEvent(ev)) { return; @@ -1259,6 +1283,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), + source: "reconfigure", + }); + } + private async _editEntryName(configEntry: ConfigEntry) { const newName = await showPromptDialog(this, { title: this.hass.localize("ui.panel.config.integrations.rename_dialog"), diff --git a/src/translations/en.json b/src/translations/en.json index 972c6753f50b..5c88e72e7de3 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -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", "reload": "Reload", "restart_confirm": "Restart Home Assistant to finish removing this integration", "reload_confirm": "The integration was reloaded", From a8d8c650e5aabec9aaff20cf06a5972acfe4b542 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Wed, 14 Feb 2024 17:16:06 +0000 Subject: [PATCH 2/3] Add entry id --- src/data/config_flow.ts | 4 +++- src/dialogs/config-flow/show-dialog-config-flow.ts | 7 ++++++- src/dialogs/config-flow/show-dialog-data-entry-flow.ts | 1 + .../config/integrations/ha-config-integration-page.ts | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/data/config_flow.ts b/src/data/config_flow.ts index 279b00c2fe31..fb845deec49e 100644 --- a/src/data/config_flow.ts +++ b/src/data/config_flow.ts @@ -29,7 +29,8 @@ const HEADERS = { export const createConfigFlow = ( hass: HomeAssistant, handler: string, - source?: string + source?: string, + entryId?: string ) => hass.callApi( "POST", @@ -38,6 +39,7 @@ export const createConfigFlow = ( handler, show_advanced_options: Boolean(hass.userData?.showAdvanced), source: source, + entry_id: entryId, }, HEADERS ); diff --git a/src/dialogs/config-flow/show-dialog-config-flow.ts b/src/dialogs/config-flow/show-dialog-config-flow.ts index 30f549552068..6e3be7ebe607 100644 --- a/src/dialogs/config-flow/show-dialog-config-flow.ts +++ b/src/dialogs/config-flow/show-dialog-config-flow.ts @@ -23,7 +23,12 @@ export const showConfigFlowDialog = ( loadDevicesAndAreas: true, createFlow: async (hass, handler) => { const [step] = await Promise.all([ - createConfigFlow(hass, handler, dialogParams.source), + createConfigFlow( + hass, + handler, + dialogParams.source, + dialogParams.entryId + ), hass.loadFragmentTranslation("config"), hass.loadBackendTranslation("config", handler), hass.loadBackendTranslation("selector", handler), 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 3df7547ba4f4..b77ef9f0647d 100644 --- a/src/dialogs/config-flow/show-dialog-data-entry-flow.ts +++ b/src/dialogs/config-flow/show-dialog-data-entry-flow.ts @@ -140,6 +140,7 @@ export interface DataEntryFlowDialogParams { flowConfig: FlowConfig; showAdvanced?: boolean; source?: string; + entryId?: string; dialogParentElement?: HTMLElement; } diff --git a/src/panels/config/integrations/ha-config-integration-page.ts b/src/panels/config/integrations/ha-config-integration-page.ts index 7b7b05dfa7f7..599e891ce332 100644 --- a/src/panels/config/integrations/ha-config-integration-page.ts +++ b/src/panels/config/integrations/ha-config-integration-page.ts @@ -1289,6 +1289,7 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) { showAdvanced: this.hass.userData?.showAdvanced, manifest: await fetchIntegrationManifest(this.hass, configEntry.domain), source: "reconfigure", + entryId: configEntry.entry_id, }); } From c3f9a3529db762c1011431093aa6375220be062c Mon Sep 17 00:00:00 2001 From: G Johansson Date: Thu, 22 Feb 2024 20:13:32 +0000 Subject: [PATCH 3/3] Review changes --- src/data/config_flow.ts | 6 ++---- src/dialogs/config-flow/show-dialog-config-flow.ts | 7 +------ src/dialogs/config-flow/show-dialog-data-entry-flow.ts | 1 - .../config/integrations/ha-config-integration-page.ts | 2 -- 4 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/data/config_flow.ts b/src/data/config_flow.ts index fb845deec49e..5c58cf789cf4 100644 --- a/src/data/config_flow.ts +++ b/src/data/config_flow.ts @@ -29,8 +29,7 @@ const HEADERS = { export const createConfigFlow = ( hass: HomeAssistant, handler: string, - source?: string, - entryId?: string + entry_id?: string ) => hass.callApi( "POST", @@ -38,8 +37,7 @@ export const createConfigFlow = ( { handler, show_advanced_options: Boolean(hass.userData?.showAdvanced), - source: source, - entry_id: entryId, + entry_id, }, HEADERS ); diff --git a/src/dialogs/config-flow/show-dialog-config-flow.ts b/src/dialogs/config-flow/show-dialog-config-flow.ts index 6e3be7ebe607..869dc50e1857 100644 --- a/src/dialogs/config-flow/show-dialog-config-flow.ts +++ b/src/dialogs/config-flow/show-dialog-config-flow.ts @@ -23,12 +23,7 @@ export const showConfigFlowDialog = ( loadDevicesAndAreas: true, createFlow: async (hass, handler) => { const [step] = await Promise.all([ - createConfigFlow( - hass, - handler, - dialogParams.source, - dialogParams.entryId - ), + createConfigFlow(hass, handler, dialogParams.entryId), hass.loadFragmentTranslation("config"), hass.loadBackendTranslation("config", handler), hass.loadBackendTranslation("selector", handler), 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 b77ef9f0647d..3594188455c0 100644 --- a/src/dialogs/config-flow/show-dialog-data-entry-flow.ts +++ b/src/dialogs/config-flow/show-dialog-data-entry-flow.ts @@ -139,7 +139,6 @@ export interface DataEntryFlowDialogParams { }) => void; flowConfig: FlowConfig; showAdvanced?: boolean; - source?: string; entryId?: string; dialogParentElement?: HTMLElement; } diff --git a/src/panels/config/integrations/ha-config-integration-page.ts b/src/panels/config/integrations/ha-config-integration-page.ts index 599e891ce332..b53f46e855fb 100644 --- a/src/panels/config/integrations/ha-config-integration-page.ts +++ b/src/panels/config/integrations/ha-config-integration-page.ts @@ -808,7 +808,6 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) { ` : ""} ${!item.disabled_by && - RECOVERABLE_STATES.includes(item.state) && item.supports_reconfigure && item.source !== "system" ? html`