import { html } from "lit"; import { caseInsensitiveStringCompare } from "../../common/string/compare"; import { createConfigFlow, deleteConfigFlow, fetchConfigFlow, getConfigFlowHandlers, handleConfigFlowStep, } from "../../data/config_flow"; import { domainToName } from "../../data/integration"; import { DataEntryFlowDialogParams, loadDataEntryFlowDialog, showFlowDialog, } from "./show-dialog-data-entry-flow"; export const loadConfigFlowDialog = loadDataEntryFlowDialog; export const showConfigFlowDialog = ( element: HTMLElement, dialogParams: Omit ): void => showFlowDialog(element, dialogParams, { loadDevicesAndAreas: true, getFlowHandlers: async (hass) => { const [handlers] = await Promise.all([ getConfigFlowHandlers(hass), hass.loadBackendTranslation("title", undefined, true), ]); return handlers.sort((handlerA, handlerB) => caseInsensitiveStringCompare( domainToName(hass.localize, handlerA), domainToName(hass.localize, handlerB) ) ); }, createFlow: async (hass, handler) => { const [step] = await Promise.all([ createConfigFlow(hass, handler), hass.loadBackendTranslation("config", handler), // Used as fallback if no header defined for step hass.loadBackendTranslation("title", handler), ]); return step; }, fetchFlow: async (hass, flowId) => { const step = await fetchConfigFlow(hass, flowId); await hass.loadBackendTranslation("config", step.handler); return step; }, handleFlowStep: handleConfigFlowStep, deleteFlow: deleteConfigFlow, renderAbortDescription(hass, step) { const description = hass.localize( `component.${step.handler}.config.abort.${step.reason}`, step.description_placeholders ); return description ? html` ` : ""; }, renderShowFormStepHeader(hass, step) { return ( hass.localize( `component.${step.handler}.config.step.${step.step_id}.title` ) || hass.localize(`component.${step.handler}.title`) ); }, renderShowFormStepDescription(hass, step) { const description = hass.localize( `component.${step.handler}.config.step.${step.step_id}.description`, step.description_placeholders ); return description ? html` ` : ""; }, renderShowFormStepFieldLabel(hass, step, field) { return hass.localize( `component.${step.handler}.config.step.${step.step_id}.data.${field.name}` ); }, renderShowFormStepFieldError(hass, step, error) { return hass.localize( `component.${step.handler}.config.error.${error}`, step.description_placeholders ); }, renderExternalStepHeader(hass, step) { return ( hass.localize( `component.${step.handler}.config.step.${step.step_id}.title` ) || hass.localize( "ui.panel.config.integrations.config_flow.external_step.open_site" ) ); }, renderExternalStepDescription(hass, step) { const description = hass.localize( `component.${step.handler}.config.${step.step_id}.description`, step.description_placeholders ); return html`

${hass.localize( "ui.panel.config.integrations.config_flow.external_step.description" )}

${description ? html` ` : ""} `; }, renderCreateEntryDescription(hass, step) { const description = hass.localize( `component.${step.handler}.config.create_entry.${ step.description || "default" }`, step.description_placeholders ); return html` ${description ? html` ` : ""}

${hass.localize( "ui.panel.config.integrations.config_flow.created_config", "name", step.title )}

`; }, renderShowFormProgressHeader(hass, step) { return ( hass.localize( `component.${step.handler}.config.step.${step.step_id}.title` ) || hass.localize(`component.${step.handler}.title`) ); }, renderShowFormProgressDescription(hass, step) { const description = hass.localize( `component.${step.handler}.config.progress.${step.progress_action}`, step.description_placeholders ); return description ? html` ` : ""; }, renderLoadingDescription(hass, reason, handler, step) { if (!["loading_flow", "loading_step"].includes(reason)) { return ""; } const domain = step?.handler || handler; return hass.localize( `ui.panel.config.integrations.config_flow.loading.${reason}`, { integration: domain ? domainToName(hass.localize, domain) : // when we are continuing a config flow, we only know the ID and not the domain hass.localize( "ui.panel.config.integrations.config_flow.loading.fallback_title" ), } ); }, });