mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-20 15:56:35 +00:00
Show helpers setup in YAML also in the UI (#21500)
This commit is contained in:
parent
a5786b4761
commit
8d20303d54
@ -71,7 +71,11 @@ import {
|
|||||||
subscribeEntityRegistry,
|
subscribeEntityRegistry,
|
||||||
updateEntityRegistryEntry,
|
updateEntityRegistryEntry,
|
||||||
} from "../../../data/entity_registry";
|
} from "../../../data/entity_registry";
|
||||||
import { domainToName } from "../../../data/integration";
|
import {
|
||||||
|
IntegrationManifest,
|
||||||
|
domainToName,
|
||||||
|
fetchIntegrationManifests,
|
||||||
|
} from "../../../data/integration";
|
||||||
import {
|
import {
|
||||||
LabelRegistryEntry,
|
LabelRegistryEntry,
|
||||||
createLabelRegistryEntry,
|
createLabelRegistryEntry,
|
||||||
@ -101,6 +105,7 @@ import {
|
|||||||
deserializeFilters,
|
deserializeFilters,
|
||||||
DataTableFilters,
|
DataTableFilters,
|
||||||
} from "../../../data/data_table_filters";
|
} from "../../../data/data_table_filters";
|
||||||
|
import { fetchEntitySourcesWithCache } from "../../../data/entity_sources";
|
||||||
|
|
||||||
type HelperItem = {
|
type HelperItem = {
|
||||||
id: string;
|
id: string;
|
||||||
@ -187,6 +192,8 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
@state() private _configEntries?: Record<string, ConfigEntry>;
|
@state() private _configEntries?: Record<string, ConfigEntry>;
|
||||||
|
|
||||||
|
@state() private _entitySource: Record<string, string> = {};
|
||||||
|
|
||||||
@state() private _selected: string[] = [];
|
@state() private _selected: string[] = [];
|
||||||
|
|
||||||
@state() private _activeFilters?: string[];
|
@state() private _activeFilters?: string[];
|
||||||
@ -409,7 +416,8 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
|
|||||||
configEntry !== undefined || entityState.attributes.editable,
|
configEntry !== undefined || entityState.attributes.editable,
|
||||||
type: configEntry
|
type: configEntry
|
||||||
? configEntry.domain
|
? configEntry.domain
|
||||||
: computeStateDomain(entityState),
|
: this._entitySource[entityState.entity_id] ||
|
||||||
|
computeStateDomain(entityState),
|
||||||
configEntry,
|
configEntry,
|
||||||
entity: entityState,
|
entity: entityState,
|
||||||
};
|
};
|
||||||
@ -441,11 +449,12 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
|
|||||||
const category = entityRegEntry?.categories.helpers;
|
const category = entityRegEntry?.categories.helpers;
|
||||||
return {
|
return {
|
||||||
...item,
|
...item,
|
||||||
localized_type: item.configEntry
|
localized_type:
|
||||||
? domainToName(localize, item.type)
|
domainToName(localize, item.type) ||
|
||||||
: localize(
|
localize(
|
||||||
`ui.panel.config.helpers.types.${item.type}` as LocalizeKeys
|
`ui.panel.config.helpers.types.${item.type}` as LocalizeKeys
|
||||||
) || item.type,
|
) ||
|
||||||
|
item.type,
|
||||||
label_entries: (labels || []).map(
|
label_entries: (labels || []).map(
|
||||||
(lbl) => labelReg!.find((label) => label.label_id === lbl)!
|
(lbl) => labelReg!.find((label) => label.label_id === lbl)!
|
||||||
),
|
),
|
||||||
@ -464,7 +473,7 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
|
|||||||
this._entityEntries === undefined ||
|
this._entityEntries === undefined ||
|
||||||
this._configEntries === undefined
|
this._configEntries === undefined
|
||||||
) {
|
) {
|
||||||
return html` <hass-loading-screen></hass-loading-screen> `;
|
return html`<hass-loading-screen></hass-loading-screen>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const categoryItems = html`${this._categories?.map(
|
const categoryItems = html`${this._categories?.map(
|
||||||
@ -923,11 +932,48 @@ ${rejected
|
|||||||
|
|
||||||
protected firstUpdated(changedProps: PropertyValues) {
|
protected firstUpdated(changedProps: PropertyValues) {
|
||||||
super.firstUpdated(changedProps);
|
super.firstUpdated(changedProps);
|
||||||
|
|
||||||
|
this._fetchEntitySources();
|
||||||
|
|
||||||
if (this.route.path === "/add") {
|
if (this.route.path === "/add") {
|
||||||
this._handleAdd();
|
this._handleAdd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _fetchEntitySources() {
|
||||||
|
const [entitySources, fetchedManifests] = await Promise.all([
|
||||||
|
fetchEntitySourcesWithCache(this.hass),
|
||||||
|
fetchIntegrationManifests(this.hass),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const manifests: { [domain: string]: IntegrationManifest } = {};
|
||||||
|
|
||||||
|
for (const manifest of fetchedManifests) {
|
||||||
|
manifests[manifest.domain] = manifest;
|
||||||
|
}
|
||||||
|
|
||||||
|
const entityDomains = {};
|
||||||
|
const domains = new Set<string>();
|
||||||
|
|
||||||
|
for (const [entity, source] of Object.entries(entitySources)) {
|
||||||
|
const domain = source.domain;
|
||||||
|
if (
|
||||||
|
!(domain in manifests) ||
|
||||||
|
manifests[domain].integration_type !== "helper"
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
entityDomains[entity] = domain;
|
||||||
|
domains.add(domain);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (domains.size) {
|
||||||
|
this.hass.loadBackendTranslation("title", [...domains]);
|
||||||
|
}
|
||||||
|
|
||||||
|
this._entitySource = entityDomains;
|
||||||
|
}
|
||||||
|
|
||||||
private async _handleAdd() {
|
private async _handleAdd() {
|
||||||
const domain = extractSearchParam("domain");
|
const domain = extractSearchParam("domain");
|
||||||
navigate("/config/helpers", { replace: true });
|
navigate("/config/helpers", { replace: true });
|
||||||
@ -994,7 +1040,8 @@ ${rejected
|
|||||||
let changed =
|
let changed =
|
||||||
!this._stateItems ||
|
!this._stateItems ||
|
||||||
changedProps.has("_entityEntries") ||
|
changedProps.has("_entityEntries") ||
|
||||||
changedProps.has("_configEntries");
|
changedProps.has("_configEntries") ||
|
||||||
|
changedProps.has("_entitySource");
|
||||||
|
|
||||||
if (!changed && changedProps.has("hass")) {
|
if (!changed && changedProps.has("hass")) {
|
||||||
const oldHass = changedProps.get("hass") as HomeAssistant | undefined;
|
const oldHass = changedProps.get("hass") as HomeAssistant | undefined;
|
||||||
@ -1004,20 +1051,11 @@ ${rejected
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const extraEntities = new Set<string>();
|
const entityIds = Object.keys(this._entitySource);
|
||||||
|
|
||||||
for (const entityEntry of Object.values(this._entityEntries)) {
|
|
||||||
if (
|
|
||||||
entityEntry.config_entry_id &&
|
|
||||||
entityEntry.config_entry_id in this._configEntries
|
|
||||||
) {
|
|
||||||
extraEntities.add(entityEntry.entity_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const newStates = Object.values(this.hass!.states).filter(
|
const newStates = Object.values(this.hass!.states).filter(
|
||||||
(entity) =>
|
(entity) =>
|
||||||
extraEntities.has(entity.entity_id) ||
|
entityIds.includes(entity.entity_id) ||
|
||||||
isHelperDomain(computeStateDomain(entity))
|
isHelperDomain(computeStateDomain(entity))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user