Integrations v2.1: compatibility with hubs, devices and services (#14114)

This commit is contained in:
Franck Nijhof 2022-10-19 12:41:57 +02:00 committed by GitHub
parent 6393d59035
commit fbb8ff4362
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 36 additions and 20 deletions

View File

@ -105,7 +105,7 @@ class HaConfigEntryPicker extends LitElement {
private async _getConfigEntries() { private async _getConfigEntries() {
getConfigEntries(this.hass, { getConfigEntries(this.hass, {
type: "integration", type: ["device", "hub", "service"],
domain: this.integration, domain: this.integration,
}).then((configEntries) => { }).then((configEntries) => {
this._configEntries = configEntries this._configEntries = configEntries

View File

@ -1,5 +1,6 @@
import { UnsubscribeFunc } from "home-assistant-js-websocket"; import { UnsubscribeFunc } from "home-assistant-js-websocket";
import { HomeAssistant } from "../types"; import { HomeAssistant } from "../types";
import { integrationType } from "./integration";
export interface ConfigEntry { export interface ConfigEntry {
entry_id: string; entry_id: string;
@ -54,7 +55,10 @@ export interface ConfigEntryUpdate {
export const subscribeConfigEntries = ( export const subscribeConfigEntries = (
hass: HomeAssistant, hass: HomeAssistant,
callbackFunction: (message: ConfigEntryUpdate[]) => void, callbackFunction: (message: ConfigEntryUpdate[]) => void,
filters?: { type?: "helper" | "integration"; domain?: string } filters?: {
type?: Array<integrationType>;
domain?: string;
}
): Promise<UnsubscribeFunc> => { ): Promise<UnsubscribeFunc> => {
const params: any = { const params: any = {
type: "config_entries/subscribe", type: "config_entries/subscribe",
@ -70,7 +74,10 @@ export const subscribeConfigEntries = (
export const getConfigEntries = ( export const getConfigEntries = (
hass: HomeAssistant, hass: HomeAssistant,
filters?: { type?: "helper" | "integration"; domain?: string } filters?: {
type?: Array<integrationType>;
domain?: string;
}
): Promise<ConfigEntry[]> => { ): Promise<ConfigEntry[]> => {
const params: any = {}; const params: any = {};
if (filters) { if (filters) {

View File

@ -3,7 +3,7 @@ import { LocalizeFunc } from "../common/translations/localize";
import { debounce } from "../common/util/debounce"; import { debounce } from "../common/util/debounce";
import { HomeAssistant } from "../types"; import { HomeAssistant } from "../types";
import { DataEntryFlowProgress, DataEntryFlowStep } from "./data_entry_flow"; import { DataEntryFlowProgress, DataEntryFlowStep } from "./data_entry_flow";
import { domainToName } from "./integration"; import { domainToName, integrationType } from "./integration";
export const DISCOVERY_SOURCES = [ export const DISCOVERY_SOURCES = [
"bluetooth", "bluetooth",
@ -68,7 +68,7 @@ export const deleteConfigFlow = (hass: HomeAssistant, flowId: string) =>
export const getConfigFlowHandlers = ( export const getConfigFlowHandlers = (
hass: HomeAssistant, hass: HomeAssistant,
type?: "helper" | "integration" type?: Array<integrationType>
) => ) =>
hass.callApi<string[]>( hass.callApi<string[]>(
"GET", "GET",

View File

@ -1,6 +1,8 @@
import { LocalizeFunc } from "../common/translations/localize"; import { LocalizeFunc } from "../common/translations/localize";
import { HomeAssistant } from "../types"; import { HomeAssistant } from "../types";
export type integrationType = "device" | "helper" | "hub" | "service";
export interface IntegrationManifest { export interface IntegrationManifest {
is_built_in: boolean; is_built_in: boolean;
domain: string; domain: string;
@ -15,6 +17,7 @@ export interface IntegrationManifest {
ssdp?: Array<{ manufacturer?: string; modelName?: string; st?: string }>; ssdp?: Array<{ manufacturer?: string; modelName?: string; st?: string }>;
zeroconf?: string[]; zeroconf?: string[];
homekit?: { models: string[] }; homekit?: { models: string[] };
integration_type?: integrationType;
quality_scale?: "gold" | "internal" | "platinum" | "silver"; quality_scale?: "gold" | "internal" | "platinum" | "silver";
iot_class: iot_class:
| "assumed_state" | "assumed_state"
@ -23,7 +26,6 @@ export interface IntegrationManifest {
| "local_polling" | "local_polling"
| "local_push"; | "local_push";
} }
export interface IntegrationSetup { export interface IntegrationSetup {
domain: string; domain: string;
seconds?: number; seconds?: number;

View File

@ -180,7 +180,9 @@ class OnboardingIntegrations extends LitElement {
} }
private async _loadConfigEntries() { 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. // 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 // It is one that we create automatically and it will confuse the user
// if it starts showing up during onboarding. // if it starts showing up during onboarding.

View File

@ -179,10 +179,10 @@ export class DialogEnergySolarSettings
? [] ? []
: domains.length === 1 : domains.length === 1
? await getConfigEntries(this.hass, { ? await getConfigEntries(this.hass, {
type: "integration", type: ["service"],
domain: domains[0], domain: domains[0],
}) })
: (await getConfigEntries(this.hass, { type: "integration" })).filter( : (await getConfigEntries(this.hass, { type: ["service"] })).filter(
(entry) => domains.includes(entry.domain) (entry) => domains.includes(entry.domain)
); );
} }

View File

@ -201,7 +201,7 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
super.firstUpdated(changedProps); super.firstUpdated(changedProps);
if (this.entry.config_entry_id) { if (this.entry.config_entry_id) {
getConfigEntries(this.hass, { getConfigEntries(this.hass, {
type: "helper", type: ["helper"],
domain: this.entry.platform, domain: this.entry.platform,
}).then((entries) => { }).then((entries) => {
this._helperConfigEntry = entries.find( this._helperConfigEntry = entries.find(

View File

@ -76,7 +76,7 @@ export class DialogHelperDetail extends LitElement {
this._opened = true; this._opened = true;
await this.updateComplete; await this.updateComplete;
Promise.all([ Promise.all([
getConfigFlowHandlers(this.hass, "helper"), getConfigFlowHandlers(this.hass, ["helper"]),
// Ensure the titles are loaded before we render the flows. // Ensure the titles are loaded before we render the flows.
this.hass.loadBackendTranslation("title", undefined, true), this.hass.loadBackendTranslation("title", undefined, true),
]).then(([flows]) => { ]).then(([flows]) => {

View File

@ -249,13 +249,14 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
}); });
return; return;
} }
const handlers = await getConfigFlowHandlers(this.hass, "helper"); const handlers = await getConfigFlowHandlers(this.hass, ["helper"]);
if (!handlers.includes(domain)) { if (!handlers.includes(domain)) {
const integrations = await getConfigFlowHandlers( const integrations = await getConfigFlowHandlers(this.hass, [
this.hass, "device",
"integration" "hub",
); "service",
]);
if (integrations.includes(domain)) { if (integrations.includes(domain)) {
navigate(`/config/integrations/add?domain=${domain}`, { navigate(`/config/integrations/add?domain=${domain}`, {
replace: true, replace: true,
@ -350,7 +351,7 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
private async _getConfigEntries() { private async _getConfigEntries() {
this._configEntries = groupByOne( this._configEntries = groupByOne(
await getConfigEntries(this.hass, { type: "helper" }), await getConfigEntries(this.hass, { type: ["helper"] }),
(entry) => entry.entry_id (entry) => entry.entry_id
); );
} }

View File

@ -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; 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 // Integration exists, so we can just create a flow
if (handlers.includes(domain)) { if (handlers.includes(domain)) {
@ -760,7 +764,7 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
}); });
return; return;
} }
const helpers = await getConfigFlowHandlers(this.hass, "helper"); const helpers = await getConfigFlowHandlers(this.hass, ["helper"]);
if (helpers.includes(domain)) { if (helpers.includes(domain)) {
navigate(`/config/helpers/add?domain=${domain}`, { navigate(`/config/helpers/add?domain=${domain}`, {
replace: true, replace: true,