Skip to content
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
2 changes: 1 addition & 1 deletion src/panels/config/helpers/dialog-helper-detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class DialogHelperDetail extends LitElement {

public async showDialog(params: ShowDialogHelperDetailParams): Promise<void> {
this._params = params;
this._domain = undefined;
this._domain = params.domain;
this._item = undefined;
this._opened = true;
await this.updateComplete;
Expand Down
69 changes: 69 additions & 0 deletions src/panels/config/helpers/ha-config-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ import { showEntityEditorDialog } from "../entities/show-dialog-entity-editor";
import { configSections } from "../ha-panel-config";
import { HELPER_DOMAINS } from "./const";
import { showHelperDetailDialog } from "./show-dialog-helper-detail";
import { navigate } from "../../../common/navigate";
import { extractSearchParam } from "../../../common/url/search-params";
import { getConfigFlowHandlers } from "../../../data/config_flow";
import { showConfigFlowDialog } from "../../../dialogs/config-flow/show-dialog-config-flow";
import {
showAlertDialog,
showConfirmationDialog,
} from "../../../dialogs/generic/show-dialog-box";

// This groups items by a key but only returns last entry per key.
const groupByOne = <T>(
Expand Down Expand Up @@ -219,6 +227,67 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
protected firstUpdated(changedProps: PropertyValues) {
super.firstUpdated(changedProps);
this._getConfigEntries();
if (this.route.path === "/add") {
this._handleAdd();
}
}

private async _handleAdd() {
const domain = extractSearchParam("domain");
navigate("/config/helpers", { replace: true });
if (!domain) {
return;
}
if (HELPER_DOMAINS.includes(domain)) {
showHelperDetailDialog(this, {
domain,
});
return;
}
const handlers = await getConfigFlowHandlers(this.hass, "helper");

if (!handlers.includes(domain)) {
const integrations = await getConfigFlowHandlers(
this.hass,
"integration"
);
if (integrations.includes(domain)) {
navigate(`/config/integrations/add?domain=${domain}`, {
replace: true,
});
return;
}
showAlertDialog(this, {
title: this.hass.localize(
"ui.panel.config.integrations.config_flow.error"
),
text: this.hass.localize(
"ui.panel.config.integrations.config_flow.no_config_flow"
),
});
return;
}
const localize = await this.hass.loadBackendTranslation(
"title",
domain,
true
);
if (
!(await showConfirmationDialog(this, {
title: this.hass.localize("ui.panel.config.integrations.confirm_new", {
integration: domainToName(localize, domain),
}),
}))
) {
return;
}
showConfigFlowDialog(this, {
dialogClosedCallback: () => {
this._getConfigEntries();
},
startFlowHandler: domain,
showAdvanced: this.hass.userData?.showAdvanced,
});
}

protected willUpdate(changedProps: PropertyValues) {
Expand Down
3 changes: 2 additions & 1 deletion src/panels/config/helpers/show-dialog-helper-detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { DataEntryFlowDialogParams } from "../../../dialogs/config-flow/show-dia
export const loadHelperDetailDialog = () => import("./dialog-helper-detail");

export interface ShowDialogHelperDetailParams {
domain?: string;
// Only used for config entries
dialogClosedCallback: DataEntryFlowDialogParams["dialogClosedCallback"];
dialogClosedCallback?: DataEntryFlowDialogParams["dialogClosedCallback"];
}

export const showHelperDetailDialog = (
Expand Down
14 changes: 14 additions & 0 deletions src/panels/config/integrations/ha-config-integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import "./ha-ignored-config-entry-card";
import "./ha-integration-card";
import type { HaIntegrationCard } from "./ha-integration-card";
import { fetchDiagnosticHandlers } from "../../../data/diagnostics";
import { HELPER_DOMAINS } from "../helpers/const";

export interface ConfigEntryUpdatedEvent {
entry: ConfigEntry;
Expand Down Expand Up @@ -661,6 +662,19 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
const handlers = await getConfigFlowHandlers(this.hass, "integration");

if (!handlers.includes(domain)) {
if (HELPER_DOMAINS.includes(domain)) {
navigate(`/config/helpers/add?domain=${domain}`, {
replace: true,
});
return;
}
const helpers = await getConfigFlowHandlers(this.hass, "helper");
if (helpers.includes(domain)) {
navigate(`/config/helpers/add?domain=${domain}`, {
replace: true,
});
return;
}
showAlertDialog(this, {
title: this.hass.localize(
"ui.panel.config.integrations.config_flow.error"
Expand Down