mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Show all disabled helpers in config/helpers (#23377)
This commit is contained in:
parent
dcf97d4667
commit
5ccc3365fe
@ -121,6 +121,7 @@ type HelperItem = {
|
|||||||
entity?: HassEntity;
|
entity?: HassEntity;
|
||||||
category: string | undefined;
|
category: string | undefined;
|
||||||
label_entries: LabelRegistryEntry[];
|
label_entries: LabelRegistryEntry[];
|
||||||
|
disabled?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This groups items by a key but only returns last entry per key.
|
// This groups items by a key but only returns last entry per key.
|
||||||
@ -191,6 +192,8 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
@state() private _stateItems: HassEntity[] = [];
|
@state() private _stateItems: HassEntity[] = [];
|
||||||
|
|
||||||
|
@state() private _disabledEntityEntries?: EntityRegistryEntry[];
|
||||||
|
|
||||||
@state() private _entityEntries?: Record<string, EntityRegistryEntry>;
|
@state() private _entityEntries?: Record<string, EntityRegistryEntry>;
|
||||||
|
|
||||||
@state() private _configEntries?: Record<string, ConfigEntry>;
|
@state() private _configEntries?: Record<string, ConfigEntry>;
|
||||||
@ -201,6 +204,8 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
@state() private _activeFilters?: string[];
|
@state() private _activeFilters?: string[];
|
||||||
|
|
||||||
|
@state() private _helperManifests?: { [domain: string]: IntegrationManifest };
|
||||||
|
|
||||||
@storage({
|
@storage({
|
||||||
storage: "sessionStorage",
|
storage: "sessionStorage",
|
||||||
key: "helpers-table-filters",
|
key: "helpers-table-filters",
|
||||||
@ -427,6 +432,7 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
|
|||||||
(
|
(
|
||||||
localize: LocalizeFunc,
|
localize: LocalizeFunc,
|
||||||
stateItems: HassEntity[],
|
stateItems: HassEntity[],
|
||||||
|
disabledEntries: EntityRegistryEntry[],
|
||||||
entityEntries: Record<string, EntityRegistryEntry>,
|
entityEntries: Record<string, EntityRegistryEntry>,
|
||||||
configEntries: Record<string, ConfigEntry>,
|
configEntries: Record<string, ConfigEntry>,
|
||||||
entityReg: EntityRegistryEntry[],
|
entityReg: EntityRegistryEntry[],
|
||||||
@ -466,29 +472,43 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const entries = Object.values(configEntriesCopy).map((configEntry) => {
|
const entries = Object.values(configEntriesCopy)
|
||||||
const entityEntry = Object.values(entityEntries).find(
|
.map((configEntry) => {
|
||||||
(entry) => entry.config_entry_id === configEntry.entry_id
|
const entityEntry = Object.values(entityEntries).find(
|
||||||
);
|
(entry) => entry.config_entry_id === configEntry.entry_id
|
||||||
const entityIsDisabled = !!entityEntry?.disabled_by;
|
);
|
||||||
return {
|
return {
|
||||||
id: entityIsDisabled ? entityEntry.entity_id : configEntry.entry_id,
|
id: configEntry.entry_id,
|
||||||
entity_id: entityIsDisabled ? entityEntry.entity_id : "",
|
entity_id: "",
|
||||||
icon: entityIsDisabled
|
icon:
|
||||||
? mdiCancel
|
configEntry.state === "setup_in_progress"
|
||||||
: configEntry.state === "setup_in_progress"
|
? mdiProgressHelper
|
||||||
? mdiProgressHelper
|
: mdiAlertCircle,
|
||||||
: mdiAlertCircle,
|
name: configEntry.title || "",
|
||||||
name: configEntry.title || "",
|
editable: true,
|
||||||
editable: true,
|
type: configEntry.domain,
|
||||||
type: configEntry.domain,
|
configEntry,
|
||||||
configEntry,
|
entity: undefined,
|
||||||
entity: undefined,
|
selectable: false,
|
||||||
selectable: entityIsDisabled,
|
disabled: !!entityEntry?.disabled_by,
|
||||||
};
|
};
|
||||||
});
|
})
|
||||||
|
.filter((e) => !e.disabled);
|
||||||
|
|
||||||
return [...states, ...entries]
|
const disabledItems = (disabledEntries || []).map((e) => ({
|
||||||
|
id: e.entity_id,
|
||||||
|
entity_id: e.entity_id,
|
||||||
|
icon: mdiCancel,
|
||||||
|
name: e.original_name || e.entity_id,
|
||||||
|
editable: true,
|
||||||
|
type: e.platform,
|
||||||
|
configEntry: undefined,
|
||||||
|
entity: undefined,
|
||||||
|
selectable: true,
|
||||||
|
disabled: true,
|
||||||
|
}));
|
||||||
|
|
||||||
|
return [...states, ...entries, ...disabledItems]
|
||||||
.filter((item) =>
|
.filter((item) =>
|
||||||
filteredStateItems
|
filteredStateItems
|
||||||
? filteredStateItems?.includes(item.entity_id)
|
? filteredStateItems?.includes(item.entity_id)
|
||||||
@ -519,6 +539,14 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
private _labelsForEntity(entityId: string): string[] {
|
||||||
|
return (
|
||||||
|
this.hass.entities[entityId]?.labels ||
|
||||||
|
this._entityReg.find((e) => e.entity_id === entityId)?.labels ||
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
if (
|
if (
|
||||||
!this.hass ||
|
!this.hass ||
|
||||||
@ -557,12 +585,12 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
|
|||||||
const labelItems = html`${this._labels?.map((label) => {
|
const labelItems = html`${this._labels?.map((label) => {
|
||||||
const color = label.color ? computeCssColor(label.color) : undefined;
|
const color = label.color ? computeCssColor(label.color) : undefined;
|
||||||
const selected = this._selected.every((entityId) =>
|
const selected = this._selected.every((entityId) =>
|
||||||
this.hass.entities[entityId]?.labels.includes(label.label_id)
|
this._labelsForEntity(entityId).includes(label.label_id)
|
||||||
);
|
);
|
||||||
const partial =
|
const partial =
|
||||||
!selected &&
|
!selected &&
|
||||||
this._selected.some((entityId) =>
|
this._selected.some((entityId) =>
|
||||||
this.hass.entities[entityId]?.labels.includes(label.label_id)
|
this._labelsForEntity(entityId).includes(label.label_id)
|
||||||
);
|
);
|
||||||
return html`<ha-md-menu-item
|
return html`<ha-md-menu-item
|
||||||
.value=${label.label_id}
|
.value=${label.label_id}
|
||||||
@ -595,6 +623,7 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
|
|||||||
const helpers = this._getItems(
|
const helpers = this._getItems(
|
||||||
this.hass.localize,
|
this.hass.localize,
|
||||||
this._stateItems,
|
this._stateItems,
|
||||||
|
this._disabledEntityEntries || [],
|
||||||
this._entityEntries,
|
this._entityEntries,
|
||||||
this._configEntries,
|
this._configEntries,
|
||||||
this._entityReg,
|
this._entityReg,
|
||||||
@ -854,6 +883,9 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
|
|||||||
?.labels.some((lbl) => filter.includes(lbl))
|
?.labels.some((lbl) => filter.includes(lbl))
|
||||||
)
|
)
|
||||||
.forEach((stateItem) => labelItems.add(stateItem.entity_id));
|
.forEach((stateItem) => labelItems.add(stateItem.entity_id));
|
||||||
|
(this._disabledEntityEntries || [])
|
||||||
|
.filter((entry) => entry.labels.some((lbl) => filter.includes(lbl)))
|
||||||
|
.forEach((entry) => labelItems.add(entry.entity_id));
|
||||||
if (!items) {
|
if (!items) {
|
||||||
items = labelItems;
|
items = labelItems;
|
||||||
continue;
|
continue;
|
||||||
@ -879,6 +911,9 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
|
|||||||
)?.categories.helpers
|
)?.categories.helpers
|
||||||
)
|
)
|
||||||
.forEach((stateItem) => categoryItems.add(stateItem.entity_id));
|
.forEach((stateItem) => categoryItems.add(stateItem.entity_id));
|
||||||
|
(this._disabledEntityEntries || [])
|
||||||
|
.filter((entry) => filter[0] === entry.categories.helpers)
|
||||||
|
.forEach((entry) => categoryItems.add(entry.entity_id));
|
||||||
if (!items) {
|
if (!items) {
|
||||||
items = categoryItems;
|
items = categoryItems;
|
||||||
continue;
|
continue;
|
||||||
@ -960,14 +995,13 @@ ${rejected
|
|||||||
private async _bulkLabel(label: string, action: "add" | "remove") {
|
private async _bulkLabel(label: string, action: "add" | "remove") {
|
||||||
const promises: Promise<UpdateEntityRegistryEntryResult>[] = [];
|
const promises: Promise<UpdateEntityRegistryEntryResult>[] = [];
|
||||||
this._selected.forEach((entityId) => {
|
this._selected.forEach((entityId) => {
|
||||||
|
const labels = this._labelsForEntity(entityId);
|
||||||
promises.push(
|
promises.push(
|
||||||
updateEntityRegistryEntry(this.hass, entityId, {
|
updateEntityRegistryEntry(this.hass, entityId, {
|
||||||
labels:
|
labels:
|
||||||
action === "add"
|
action === "add"
|
||||||
? this.hass.entities[entityId].labels.concat(label)
|
? labels.concat(label)
|
||||||
: this.hass.entities[entityId].labels.filter(
|
: labels.filter((lbl) => lbl !== label),
|
||||||
(lbl) => lbl !== label
|
|
||||||
),
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -1012,18 +1046,19 @@ ${rejected
|
|||||||
const manifests: { [domain: string]: IntegrationManifest } = {};
|
const manifests: { [domain: string]: IntegrationManifest } = {};
|
||||||
|
|
||||||
for (const manifest of fetchedManifests) {
|
for (const manifest of fetchedManifests) {
|
||||||
manifests[manifest.domain] = manifest;
|
if (manifest.integration_type === "helper") {
|
||||||
|
manifests[manifest.domain] = manifest;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._helperManifests = manifests;
|
||||||
|
|
||||||
const entityDomains = {};
|
const entityDomains = {};
|
||||||
const domains = new Set<string>();
|
const domains = new Set<string>();
|
||||||
|
|
||||||
for (const [entity, source] of Object.entries(entitySources)) {
|
for (const [entity, source] of Object.entries(entitySources)) {
|
||||||
const domain = source.domain;
|
const domain = source.domain;
|
||||||
if (
|
if (!(domain in manifests)) {
|
||||||
!(domain in manifests) ||
|
|
||||||
manifests[domain].integration_type !== "helper"
|
|
||||||
) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
entityDomains[entity] = domain;
|
entityDomains[entity] = domain;
|
||||||
@ -1101,6 +1136,20 @@ ${rejected
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
(changedProps.has("_helperManifests") ||
|
||||||
|
changedProps.has("_entityEntries") ||
|
||||||
|
changedProps.has("_configEntries")) &&
|
||||||
|
this._helperManifests
|
||||||
|
) {
|
||||||
|
this._disabledEntityEntries = Object.values(this._entityEntries).filter(
|
||||||
|
(e) =>
|
||||||
|
e.disabled_by &&
|
||||||
|
(e.platform in this._helperManifests! ||
|
||||||
|
(e.config_entry_id && e.config_entry_id in this._configEntries!))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let changed =
|
let changed =
|
||||||
!this._stateItems ||
|
!this._stateItems ||
|
||||||
changedProps.has("_entityEntries") ||
|
changedProps.has("_entityEntries") ||
|
||||||
|
Loading…
x
Reference in New Issue
Block a user