Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/common/url/marketplace-query-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
// The filters of the Marketplace tables. Search, sorting and grouping are kept
// by the data table, see data-table-query-params.
export const marketplaceFilterQueryParamConfig = {
list: ["status", "type", "source", "integration_category"],
list: ["status", "type", "source", "integration_category", "connectivity"],
} as const satisfies QueryParamConfig;

export type MarketplaceFilterQueryParams = QueryParamValues<
Expand Down
32 changes: 30 additions & 2 deletions src/data/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,20 +250,24 @@ export type IconCategory =
| "services"
| "triggers"
| "conditions"
| "integration_category";
| "integration_category"
| "integration_connectivity";

export type IntegrationCategoryIcons = Record<
string,
{ default: string; subcategory?: Record<string, { default: string }> }
>;

export type IntegrationConnectivityIcons = Record<string, { default: string }>;

interface CategoryType {
entity: PlatformIcons;
entity_component: ComponentIcons;
services: ServiceIcons;
triggers: TriggerIcons;
conditions: ConditionIcons;
integration_category: IntegrationCategoryIcons;
integration_connectivity: IntegrationConnectivityIcons;
}

export const getHassIcons = async <T extends IconCategory>(
Expand Down Expand Up @@ -334,7 +338,10 @@ export const getComponentIcons = async (
export const getCategoryIcons = async <
T extends Exclude<
IconCategory,
"entity" | "entity_component" | "integration_category"
| "entity"
| "entity_component"
| "integration_category"
| "integration_connectivity"
>,
>(
connection: Connection,
Expand Down Expand Up @@ -775,3 +782,24 @@ export const getIntegrationCategoryIcons = async (
return undefined;
}
};

let integrationConnectivityIcons:
ReturnType<typeof getHassIcons<"integration_connectivity">> | undefined;

export const getIntegrationConnectivityIcons = async (
connection: Connection
): Promise<IntegrationConnectivityIcons | undefined> => {
// Cache the request itself, so callers while it loads share it
integrationConnectivityIcons ??= getHassIcons(
connection,
"integration_connectivity",
"homeassistant"
);
try {
const result = await integrationConnectivityIcons;
return result.resources.homeassistant;
} catch (_err) {
integrationConnectivityIcons = undefined;
return undefined;
}
};
15 changes: 15 additions & 0 deletions src/data/integration_connectivity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { LocalizeFunc } from "../common/translations/localize";
import type { IntegrationConnectivityIcons } from "./icons";

// The name of a connectivity, like `zigbee`. Empty for one this Home Assistant
// doesn't know.
export const integrationConnectivityName = (
localize: LocalizeFunc,
slug: string
): string =>
localize(`component.homeassistant.integration_connectivity.${slug}.name`);

export const integrationConnectivityIcon = (
icons: IntegrationConnectivityIcons | undefined,
slug: string
): string | undefined => icons?.[slug]?.default;
3 changes: 3 additions & 0 deletions src/data/marketplace/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export interface RepositoryBase {
can_install: boolean;
category: RepositoryType;
config_flow: boolean;
// How an integration connects, like `zigbee` or `cloud`. Empty for other
// repositories and for integrations that don't set it.
connectivity?: string[];
custom: boolean;
description: string;
domain: string | null;
Expand Down
3 changes: 2 additions & 1 deletion src/data/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ export type TranslationCategory =
| "services"
| "triggers"
| "conditions"
| "integration_category";
| "integration_category"
| "integration_connectivity";

export const subscribeTranslationPreferences = (
hass: HomeAssistant,
Expand Down
35 changes: 31 additions & 4 deletions src/panels/marketplace/dashboards/dashboard-repositories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
inIntegrationCategory,
integrationCategoryName,
} from "../../../data/integration_category";
import { integrationConnectivityName } from "../../../data/integration_connectivity";
import type { RepositoryBase } from "../../../data/marketplace/repository";
import type { HomeAssistant } from "../../../types";
import type { MarketplaceTab } from "./ha-marketplace-dashboard";
Expand Down Expand Up @@ -45,6 +46,9 @@ export const SOURCE_FILTER = "source";
// Like `energy`, which takes in its subcategories, or `energy.solar`
export const INTEGRATION_CATEGORY_FILTER = "integration_category";

// How an integration connects, like `zigbee` or `cloud`
export const CONNECTIVITY_FILTER = "connectivity";

// Where a repository comes from, the community catalog or added from a link
export const SOURCE_ORDER = ["catalog", "custom"] as const;

Expand All @@ -59,7 +63,8 @@ export type RepositoryFilters = Partial<
| typeof STATUS_FILTER
| typeof TYPE_FILTER
| typeof SOURCE_FILTER
| typeof INTEGRATION_CATEGORY_FILTER,
| typeof INTEGRATION_CATEGORY_FILTER
| typeof CONNECTIVITY_FILTER,
string[]
>
>;
Expand Down Expand Up @@ -139,12 +144,14 @@ export const statusesOfTab = (

// The filters are kept for every tab. A status picked on another tab that this
// one can't list is left out here, instead of leaving the table empty. So is
// an integration category nothing on this tab is in, when the ones it lists
// are given. Before the repositories load it lists none, so the URL keeps them.
// an integration category or connectivity nothing on this tab has, when the
// ones it lists are given. Before the repositories load it lists none, so the
// URL keeps them.
export const filtersOfTab = (
filters: RepositoryFilters,
tab: MarketplaceTab,
integrationCategories?: readonly string[]
integrationCategories?: readonly string[],
connectivity?: readonly string[]
): RepositoryFilters => {
const statuses: readonly string[] = statusesOfTab(tab);

Expand All @@ -158,6 +165,11 @@ export const filtersOfTab = (
integrationCategories.includes(slug)
)
: filters[INTEGRATION_CATEGORY_FILTER],
[CONNECTIVITY_FILTER]: connectivity
? filters[CONNECTIVITY_FILTER]?.filter((slug) =>
connectivity.includes(slug)
)
: filters[CONNECTIVITY_FILTER],
};
};

Expand Down Expand Up @@ -215,6 +227,15 @@ const matchesFilters = (
return false;
}

const connectivity = filters[CONNECTIVITY_FILTER];

if (
connectivity?.length &&
!connectivity.some((slug) => repository.connectivity?.includes(slug))
) {
return false;
}

return true;
};

Expand Down Expand Up @@ -263,6 +284,11 @@ export const filterRepositories = (
.map((slug) => integrationCategoryName(localize, slug))
.filter(Boolean)
.join(", "),
// Ones this Home Assistant doesn't know are left out
translated_connectivity: (repository.connectivity ?? [])
.map((slug) => integrationConnectivityName(localize, slug))
.filter(Boolean)
.join(", "),
// A date as text or 0 without one, only numbers sort among each other
last_updated_timestamp: timestamp(repository.last_updated),
}));
Expand Down Expand Up @@ -328,6 +354,7 @@ export const browseLinkFromUrl = (
[SOURCE_FILTER]: lists.source?.filter(Boolean),
[INTEGRATION_CATEGORY_FILTER]:
lists.integration_category?.filter(Boolean),
[CONNECTIVITY_FILTER]: lists.connectivity?.filter(Boolean),
},
};
};
108 changes: 105 additions & 3 deletions src/panels/marketplace/dashboards/ha-marketplace-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import { haStyle } from "../../../resources/styles";
import {
applySkippedUpdates,
browseLinkFromUrl,
CONNECTIVITY_FILTER,
INTEGRATION_CATEGORY_FILTER,
filterRepositories,
filtersOfTab,
Expand All @@ -116,12 +117,22 @@ import type {
} from "./dashboard-repositories";
import { documentationUrl } from "../../../util/documentation-url";
import { renderRepositoryIcon } from "../tools/repository-icon";
import type { IntegrationCategoryIcons } from "../../../data/icons";
import { getIntegrationCategoryIcons } from "../../../data/icons";
import type {
IntegrationCategoryIcons,
IntegrationConnectivityIcons,
} from "../../../data/icons";
import {
getIntegrationCategoryIcons,
getIntegrationConnectivityIcons,
} from "../../../data/icons";
import {
integrationCategoryIcon,
integrationCategoryName,
} from "../../../data/integration_category";
import {
integrationConnectivityIcon,
integrationConnectivityName,
} from "../../../data/integration_connectivity";
import {
showAlertDialog,
showConfirmationDialog,
Expand Down Expand Up @@ -212,6 +223,8 @@ export class HaMarketplaceDashboard extends LitElement {

@state() private _integrationCategoryIcons?: IntegrationCategoryIcons;

@state() private _connectivityIcons?: IntegrationConnectivityIcons;

@state()
@consumeEntityStates({ entityIdPath: ["_marketplaceUpdateEntityIds"] })
private _states?: HassEntities;
Expand Down Expand Up @@ -301,6 +314,11 @@ export class HaMarketplaceDashboard extends LitElement {
getIntegrationCategoryIcons(this._connection.connection).then((icons) => {
this._integrationCategoryIcons = icons;
});
getIntegrationConnectivityIcons(this._connection.connection).then(
(icons) => {
this._connectivityIcons = icons;
}
);
}

// The states of these are only selected after this runs, so the skipped
Expand Down Expand Up @@ -372,10 +390,12 @@ export class HaMarketplaceDashboard extends LitElement {
this.tab
);
const integrationCategoryStates = this._tabIntegrationCategoryStates();
const connectivityStates = this._tabConnectivityStates();
const filters = this._filtersOfTab(
this._filters,
this.tab,
this._stateValues(integrationCategoryStates)
this._stateValues(integrationCategoryStates),
this._connectivityStateValues(connectivityStates)
);
const repositories = this._filterRepositories(
tabRepositories,
Expand Down Expand Up @@ -509,6 +529,20 @@ export class HaMarketplaceDashboard extends LitElement {
></ha-filter-states>`
: nothing
}
${
connectivityStates.length
? html`<ha-filter-states
slot="filter-pane"
.label=${this._i18n.localize(
"ui.panel.marketplace.filters.connectivity"
)}
.value=${filters[CONNECTIVITY_FILTER]}
.states=${connectivityStates}
.narrow=${this.narrow}
@data-table-filter-changed=${this._connectivityFilterChanged}
></ha-filter-states>`
: nothing
}
</hass-tabs-subpage-data-table>
<ha-dropdown
id="repository-overflow-menu"
Expand Down Expand Up @@ -619,6 +653,11 @@ export class HaMarketplaceDashboard extends LitElement {
options.map((option) => option.value)
);

// Its own cache, so the integration category values stay the same array
private _connectivityStateValues = memoize((options: { value: string }[]) =>
options.map((option) => option.value)
);

private _columns = memoize(
(
localizeFunc: LocalizeFunc,
Expand Down Expand Up @@ -769,6 +808,13 @@ export class HaMarketplaceDashboard extends LitElement {
hidden: false,
defaultHidden: true,
},
// Few custom integrations set their connectivity yet, so it starts hidden
translated_connectivity: {
...defaultKeyData,
title: localizeFunc("ui.panel.marketplace.column.connectivity"),
hidden: false,
defaultHidden: true,
},
description: defaultKeyData,
authors: defaultKeyData,
domain: defaultKeyData,
Expand Down Expand Up @@ -1143,6 +1189,36 @@ export class HaMarketplaceDashboard extends LitElement {
);
}

// Only what the repositories have, the list of all of them is long
private _connectivityStates = memoize(
(
repositories: RepositoryBase[],
localize: LocalizeFunc,
icons: IntegrationConnectivityIcons | undefined
) =>
[
...new Set(
repositories.flatMap((repository) => repository.connectivity ?? [])
),
]
.map((slug) => ({
value: slug,
label: integrationConnectivityName(localize, slug),
icon: integrationConnectivityIcon(icons, slug),
}))
// Ones this Home Assistant doesn't know are left out
.filter((option) => option.label)
.sort((a, b) => a.label.localeCompare(b.label))
);

private _tabConnectivityStates() {
return this._connectivityStates(
this._repositoriesOfTab(this._marketplaceRepositories(), this.tab),
this._i18n.localize,
this._connectivityIcons
);
}

private _sourceStates = memoize((localize: LocalizeFunc) =>
SOURCE_ORDER.map((source) => ({
value: source,
Expand Down Expand Up @@ -1264,6 +1340,32 @@ export class HaMarketplaceDashboard extends LitElement {
this._writeFilters();
}

private _connectivityFilterChanged(ev: CustomEvent<{ value: string[] }>) {
const listed = this._connectivityStateValues(this._tabConnectivityStates());
const filters = {
...this._filters,
[CONNECTIVITY_FILTER]: paneFilterOfTab(
this._filters[CONNECTIVITY_FILTER],
listed,
ev.detail.value
),
};

if (this._isUserChange(filters)) {
this._storageFilters = {
...this._storageFilters,
[CONNECTIVITY_FILTER]: paneFilterOfTab(
this._storageFilters[CONNECTIVITY_FILTER],
listed,
ev.detail.value
),
};
}

this._filters = filters;
this._writeFilters();
}

private _handleCollapseChanged(
ev: HASSDomEvent<HASSDomEvents["collapsed-changed"]>
) {
Expand Down
Loading