mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-25 13:57:21 +00:00
Add support for my links to create a helper config entry (#12155)
This commit is contained in:
parent
7ab54ee5ce
commit
624cb48f78
@ -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;
|
||||
|
@ -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>(
|
||||
@ -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) {
|
||||
|
@ -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 = (
|
||||
|
@ -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;
|
||||
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user