mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 08:16:36 +00:00
Integrations v2.1: compatibility with hubs, devices and services (#14114)
This commit is contained in:
parent
6393d59035
commit
fbb8ff4362
@ -105,7 +105,7 @@ class HaConfigEntryPicker extends LitElement {
|
||||
|
||||
private async _getConfigEntries() {
|
||||
getConfigEntries(this.hass, {
|
||||
type: "integration",
|
||||
type: ["device", "hub", "service"],
|
||||
domain: this.integration,
|
||||
}).then((configEntries) => {
|
||||
this._configEntries = configEntries
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||
import { HomeAssistant } from "../types";
|
||||
import { integrationType } from "./integration";
|
||||
|
||||
export interface ConfigEntry {
|
||||
entry_id: string;
|
||||
@ -54,7 +55,10 @@ export interface ConfigEntryUpdate {
|
||||
export const subscribeConfigEntries = (
|
||||
hass: HomeAssistant,
|
||||
callbackFunction: (message: ConfigEntryUpdate[]) => void,
|
||||
filters?: { type?: "helper" | "integration"; domain?: string }
|
||||
filters?: {
|
||||
type?: Array<integrationType>;
|
||||
domain?: string;
|
||||
}
|
||||
): Promise<UnsubscribeFunc> => {
|
||||
const params: any = {
|
||||
type: "config_entries/subscribe",
|
||||
@ -70,7 +74,10 @@ export const subscribeConfigEntries = (
|
||||
|
||||
export const getConfigEntries = (
|
||||
hass: HomeAssistant,
|
||||
filters?: { type?: "helper" | "integration"; domain?: string }
|
||||
filters?: {
|
||||
type?: Array<integrationType>;
|
||||
domain?: string;
|
||||
}
|
||||
): Promise<ConfigEntry[]> => {
|
||||
const params: any = {};
|
||||
if (filters) {
|
||||
|
@ -3,7 +3,7 @@ import { LocalizeFunc } from "../common/translations/localize";
|
||||
import { debounce } from "../common/util/debounce";
|
||||
import { HomeAssistant } from "../types";
|
||||
import { DataEntryFlowProgress, DataEntryFlowStep } from "./data_entry_flow";
|
||||
import { domainToName } from "./integration";
|
||||
import { domainToName, integrationType } from "./integration";
|
||||
|
||||
export const DISCOVERY_SOURCES = [
|
||||
"bluetooth",
|
||||
@ -68,7 +68,7 @@ export const deleteConfigFlow = (hass: HomeAssistant, flowId: string) =>
|
||||
|
||||
export const getConfigFlowHandlers = (
|
||||
hass: HomeAssistant,
|
||||
type?: "helper" | "integration"
|
||||
type?: Array<integrationType>
|
||||
) =>
|
||||
hass.callApi<string[]>(
|
||||
"GET",
|
||||
|
@ -1,6 +1,8 @@
|
||||
import { LocalizeFunc } from "../common/translations/localize";
|
||||
import { HomeAssistant } from "../types";
|
||||
|
||||
export type integrationType = "device" | "helper" | "hub" | "service";
|
||||
|
||||
export interface IntegrationManifest {
|
||||
is_built_in: boolean;
|
||||
domain: string;
|
||||
@ -15,6 +17,7 @@ export interface IntegrationManifest {
|
||||
ssdp?: Array<{ manufacturer?: string; modelName?: string; st?: string }>;
|
||||
zeroconf?: string[];
|
||||
homekit?: { models: string[] };
|
||||
integration_type?: integrationType;
|
||||
quality_scale?: "gold" | "internal" | "platinum" | "silver";
|
||||
iot_class:
|
||||
| "assumed_state"
|
||||
@ -23,7 +26,6 @@ export interface IntegrationManifest {
|
||||
| "local_polling"
|
||||
| "local_push";
|
||||
}
|
||||
|
||||
export interface IntegrationSetup {
|
||||
domain: string;
|
||||
seconds?: number;
|
||||
|
@ -180,7 +180,9 @@ class OnboardingIntegrations extends LitElement {
|
||||
}
|
||||
|
||||
private async _loadConfigEntries() {
|
||||
const entries = await getConfigEntries(this.hass!, { type: "integration" });
|
||||
const entries = await getConfigEntries(this.hass!, {
|
||||
type: ["device", "hub", "service"],
|
||||
});
|
||||
// We filter out the config entries that are automatically created during onboarding.
|
||||
// It is one that we create automatically and it will confuse the user
|
||||
// if it starts showing up during onboarding.
|
||||
|
@ -179,10 +179,10 @@ export class DialogEnergySolarSettings
|
||||
? []
|
||||
: domains.length === 1
|
||||
? await getConfigEntries(this.hass, {
|
||||
type: "integration",
|
||||
type: ["service"],
|
||||
domain: domains[0],
|
||||
})
|
||||
: (await getConfigEntries(this.hass, { type: "integration" })).filter(
|
||||
: (await getConfigEntries(this.hass, { type: ["service"] })).filter(
|
||||
(entry) => domains.includes(entry.domain)
|
||||
);
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
|
||||
super.firstUpdated(changedProps);
|
||||
if (this.entry.config_entry_id) {
|
||||
getConfigEntries(this.hass, {
|
||||
type: "helper",
|
||||
type: ["helper"],
|
||||
domain: this.entry.platform,
|
||||
}).then((entries) => {
|
||||
this._helperConfigEntry = entries.find(
|
||||
|
@ -76,7 +76,7 @@ export class DialogHelperDetail extends LitElement {
|
||||
this._opened = true;
|
||||
await this.updateComplete;
|
||||
Promise.all([
|
||||
getConfigFlowHandlers(this.hass, "helper"),
|
||||
getConfigFlowHandlers(this.hass, ["helper"]),
|
||||
// Ensure the titles are loaded before we render the flows.
|
||||
this.hass.loadBackendTranslation("title", undefined, true),
|
||||
]).then(([flows]) => {
|
||||
|
@ -249,13 +249,14 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
|
||||
});
|
||||
return;
|
||||
}
|
||||
const handlers = await getConfigFlowHandlers(this.hass, "helper");
|
||||
const handlers = await getConfigFlowHandlers(this.hass, ["helper"]);
|
||||
|
||||
if (!handlers.includes(domain)) {
|
||||
const integrations = await getConfigFlowHandlers(
|
||||
this.hass,
|
||||
"integration"
|
||||
);
|
||||
const integrations = await getConfigFlowHandlers(this.hass, [
|
||||
"device",
|
||||
"hub",
|
||||
"service",
|
||||
]);
|
||||
if (integrations.includes(domain)) {
|
||||
navigate(`/config/integrations/add?domain=${domain}`, {
|
||||
replace: true,
|
||||
@ -350,7 +351,7 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
|
||||
|
||||
private async _getConfigEntries() {
|
||||
this._configEntries = groupByOne(
|
||||
await getConfigEntries(this.hass, { type: "helper" }),
|
||||
await getConfigEntries(this.hass, { type: ["helper"] }),
|
||||
(entry) => entry.entry_id
|
||||
);
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
|
||||
)
|
||||
);
|
||||
},
|
||||
{ type: "integration" }
|
||||
{ type: ["device", "hub", "service"] }
|
||||
),
|
||||
];
|
||||
}
|
||||
@ -693,7 +693,11 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
const handlers = await getConfigFlowHandlers(this.hass, "integration");
|
||||
const handlers = await getConfigFlowHandlers(this.hass, [
|
||||
"device",
|
||||
"hub",
|
||||
"service",
|
||||
]);
|
||||
|
||||
// Integration exists, so we can just create a flow
|
||||
if (handlers.includes(domain)) {
|
||||
@ -760,7 +764,7 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
|
||||
});
|
||||
return;
|
||||
}
|
||||
const helpers = await getConfigFlowHandlers(this.hass, "helper");
|
||||
const helpers = await getConfigFlowHandlers(this.hass, ["helper"]);
|
||||
if (helpers.includes(domain)) {
|
||||
navigate(`/config/helpers/add?domain=${domain}`, {
|
||||
replace: true,
|
||||
|
Loading…
x
Reference in New Issue
Block a user