mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Always deduplicate found integrations in onboarding (#18091)
always deduplicate found integrations in onboarding
This commit is contained in:
parent
a3400a2f9c
commit
2f6297ec17
@ -15,7 +15,6 @@ import { stringCompare } from "../common/string/compare";
|
|||||||
import { LocalizeFunc } from "../common/translations/localize";
|
import { LocalizeFunc } from "../common/translations/localize";
|
||||||
import { ConfigEntry, subscribeConfigEntries } from "../data/config_entries";
|
import { ConfigEntry, subscribeConfigEntries } from "../data/config_entries";
|
||||||
import { subscribeConfigFlowInProgress } from "../data/config_flow";
|
import { subscribeConfigFlowInProgress } from "../data/config_flow";
|
||||||
import { DataEntryFlowProgress } from "../data/data_entry_flow";
|
|
||||||
import { domainToName } from "../data/integration";
|
import { domainToName } from "../data/integration";
|
||||||
import { scanUSBDevices } from "../data/usb";
|
import { scanUSBDevices } from "../data/usb";
|
||||||
import { SubscribeMixin } from "../mixins/subscribe-mixin";
|
import { SubscribeMixin } from "../mixins/subscribe-mixin";
|
||||||
@ -41,19 +40,20 @@ class OnboardingIntegrations extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
@state() private _entries: ConfigEntry[] = [];
|
@state() private _entries: ConfigEntry[] = [];
|
||||||
|
|
||||||
@state() private _discovered?: DataEntryFlowProgress[];
|
@state() private _discoveredDomains?: Set<string>;
|
||||||
|
|
||||||
public hassSubscribe(): Array<UnsubscribeFunc | Promise<UnsubscribeFunc>> {
|
public hassSubscribe(): Array<UnsubscribeFunc | Promise<UnsubscribeFunc>> {
|
||||||
return [
|
return [
|
||||||
subscribeConfigFlowInProgress(this.hass, (flows) => {
|
subscribeConfigFlowInProgress(this.hass, (flows) => {
|
||||||
this._discovered = flows.filter(
|
this._discoveredDomains = new Set(
|
||||||
(flow) => !HIDDEN_DOMAINS.has(flow.handler)
|
flows
|
||||||
|
.filter((flow) => !HIDDEN_DOMAINS.has(flow.handler))
|
||||||
|
.map((flow) => flow.handler)
|
||||||
|
);
|
||||||
|
this.hass.loadBackendTranslation(
|
||||||
|
"title",
|
||||||
|
Array.from(this._discoveredDomains)
|
||||||
);
|
);
|
||||||
const integrations: Set<string> = new Set();
|
|
||||||
for (const flow of this._discovered) {
|
|
||||||
integrations.add(flow.handler);
|
|
||||||
}
|
|
||||||
this.hass.loadBackendTranslation("title", Array.from(integrations));
|
|
||||||
}),
|
}),
|
||||||
subscribeConfigEntries(
|
subscribeConfigEntries(
|
||||||
this.hass,
|
this.hass,
|
||||||
@ -98,41 +98,27 @@ class OnboardingIntegrations extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
if (!this._discovered) {
|
if (!this._discoveredDomains) {
|
||||||
return nothing;
|
return nothing;
|
||||||
}
|
}
|
||||||
// Render discovered and existing entries together sorted by localized title.
|
// Render discovered and existing entries together sorted by localized title.
|
||||||
const entries: Array<[string, string]> = this._entries.map((entry) => [
|
let uniqueDomains: Set<string> = new Set();
|
||||||
entry.domain,
|
this._entries.forEach((entry) => {
|
||||||
domainToName(this.hass.localize, entry.domain),
|
uniqueDomains.add(entry.domain);
|
||||||
]);
|
});
|
||||||
const discovered: Array<[string, string]> = this._discovered.map((flow) => [
|
uniqueDomains = new Set([...uniqueDomains, ...this._discoveredDomains]);
|
||||||
flow.handler,
|
let domains: Array<[string, string]> = [];
|
||||||
domainToName(this.hass.localize, flow.handler),
|
for (const domain of uniqueDomains.values()) {
|
||||||
]);
|
domains.push([domain, domainToName(this.hass.localize, domain)]);
|
||||||
let domains = [...entries, ...discovered].sort((a, b) =>
|
}
|
||||||
|
domains = domains.sort((a, b) =>
|
||||||
stringCompare(a[0], b[0], this.hass.locale.language)
|
stringCompare(a[0], b[0], this.hass.locale.language)
|
||||||
);
|
);
|
||||||
|
|
||||||
const foundDevices = domains.length;
|
const foundIntegrations = domains.length;
|
||||||
|
|
||||||
if (domains.length > 12) {
|
if (domains.length > 12) {
|
||||||
const uniqueDomains: Set<string> = new Set();
|
domains = domains.slice(0, 11);
|
||||||
domains.forEach(([domain]) => {
|
|
||||||
uniqueDomains.add(domain);
|
|
||||||
});
|
|
||||||
if (uniqueDomains.size < domains.length) {
|
|
||||||
domains = domains.filter(([domain]) => {
|
|
||||||
if (uniqueDomains.has(domain)) {
|
|
||||||
uniqueDomains.delete(domain);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (domains.length > 12) {
|
|
||||||
domains = domains.slice(0, 11);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
@ -153,11 +139,11 @@ class OnboardingIntegrations extends SubscribeMixin(LitElement) {
|
|||||||
.darkOptimizedIcon=${this.hass.themes?.darkMode}
|
.darkOptimizedIcon=${this.hass.themes?.darkMode}
|
||||||
></integration-badge>`
|
></integration-badge>`
|
||||||
)}
|
)}
|
||||||
${foundDevices > domains.length
|
${foundIntegrations > domains.length
|
||||||
? html`<div class="more">
|
? html`<div class="more">
|
||||||
${this.onboardingLocalize(
|
${this.onboardingLocalize(
|
||||||
"ui.panel.page-onboarding.integration.more_integrations",
|
"ui.panel.page-onboarding.integration.more_integrations",
|
||||||
{ count: foundDevices - domains.length }
|
{ count: foundIntegrations - domains.length }
|
||||||
)}
|
)}
|
||||||
</div>`
|
</div>`
|
||||||
: nothing}
|
: nothing}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user