Utilize Hide Hidden Entities

This commit is contained in:
Zack 2022-03-14 14:22:45 -05:00
parent 3358fc2b18
commit e01cb3ca82
7 changed files with 186 additions and 99 deletions

View File

@ -14,6 +14,7 @@ export interface EntityRegistryEntry {
device_id: string | null;
area_id: string | null;
disabled_by: string | null;
hidden_by: string | null;
entity_category: "config" | "diagnostic" | null;
}
@ -38,6 +39,7 @@ export interface EntityRegistryEntryUpdateParams {
device_class?: string | null;
area_id?: string | null;
disabled_by?: string | null;
hidden_by: string | null;
new_entity_id?: string;
}

View File

@ -40,7 +40,7 @@ export class HaDeviceEntitiesCard extends LitElement {
@property() public entities!: EntityRegistryStateEntry[];
@property() public showDisabled = false;
@property() public showHidden = false;
@state() private _extDisabledEntityEntries?: Record<
string,
@ -60,51 +60,55 @@ export class HaDeviceEntitiesCard extends LitElement {
}
protected render(): TemplateResult {
const disabledEntities: EntityRegistryStateEntry[] = [];
this._entityRows = [];
if (!this.entities.length) {
return html`
<ha-card .header=${this.header}>
${this.entities.length
? html`
<div id="entities" @hass-more-info=${this._overrideMoreInfo}>
${this.entities.map((entry: EntityRegistryStateEntry) => {
if (entry.disabled_by) {
<div class="empty card-content">
${this.hass.localize("ui.panel.config.devices.entities.none")}
</div>
`;
}
const shownEntities: EntityRegistryStateEntry[] = [];
const hiddenEntities: EntityRegistryStateEntry[] = [];
this._entityRows = [];
this.entities.forEach((entry) => {
if (entry.disabled_by || entry.hidden_by) {
if (this._extDisabledEntityEntries) {
disabledEntities.push(
hiddenEntities.push(
this._extDisabledEntityEntries[entry.entity_id] || entry
);
} else {
disabledEntities.push(entry);
hiddenEntities.push(entry);
}
return "";
} else {
shownEntities.push(entry);
}
return this.hass.states[entry.entity_id]
});
return html`
<ha-card .header=${this.header}>
<div id="entities" @hass-more-info=${this._overrideMoreInfo}>
${shownEntities.map((entry) =>
this.hass.states[entry.entity_id]
? this._renderEntity(entry)
: this._renderEntry(entry);
})}
: this._renderEntry(entry)
)}
</div>
${disabledEntities.length
? !this.showDisabled
${hiddenEntities.length
? !this.showHidden
? html`
<button
class="show-more"
@click=${this._toggleShowDisabled}
>
<button class="show-more" @click=${this._toggleShowHidden}>
${this.hass.localize(
"ui.panel.config.devices.entities.disabled_entities",
"count",
disabledEntities.length
hiddenEntities.length
)}
</button>
`
: html`
${disabledEntities.map((entry) =>
this._renderEntry(entry)
)}
<button
class="show-more"
@click=${this._toggleShowDisabled}
>
${hiddenEntities.map((entry) => this._renderEntry(entry))}
<button class="show-more" @click=${this._toggleShowHidden}>
${this.hass.localize(
"ui.panel.config.devices.entities.hide_disabled"
)}
@ -118,19 +122,13 @@ export class HaDeviceEntitiesCard extends LitElement {
)}
</mwc-button>
</div>
`
: html`
<div class="empty card-content">
${this.hass.localize("ui.panel.config.devices.entities.none")}
</div>
`}
</ha-card>
`;
}
private _toggleShowDisabled() {
this.showDisabled = !this.showDisabled;
if (!this.showDisabled || this._extDisabledEntityEntries !== undefined) {
private _toggleShowHidden() {
this.showHidden = !this.showHidden;
if (!this.showHidden || this._extDisabledEntityEntries !== undefined) {
return;
}
this._extDisabledEntityEntries = {};

View File

@ -557,7 +557,7 @@ export class HaConfigDevicePage extends LitElement {
)}
.deviceName=${deviceName}
.entities=${entitiesByCategory[category]}
.showDisabled=${device.disabled_by !== null}
.showHidden=${device.disabled_by !== null}
>
</ha-device-entities-card>
`

View File

@ -76,6 +76,8 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
@state() private _disabledBy!: string | null;
@state() private _hiddenBy!: string | null;
private _deviceLookup?: Record<string, DeviceRegistryEntry>;
@state() private _device?: DeviceRegistryEntry;
@ -112,6 +114,7 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
this._areaId = this.entry.area_id;
this._entityId = this.entry.entity_id;
this._disabledBy = this.entry.disabled_by;
this._hiddenBy = this.entry.hidden_by;
this._device =
this.entry.device_id && this._deviceLookup
? this._deviceLookup[this.entry.device_id]
@ -244,8 +247,41 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
</div>
</div>
<div class="row">
<ha-switch
.checked=${this._hiddenBy !== null}
.disabled=${this._hiddenBy && this._hiddenBy !== "user"}
@change=${this._hiddenByChanged}
>
</ha-switch>
<div>
<div>
${this.hass.localize(
"ui.dialogs.entity_registry.editor.hidden_label"
)}
</div>
<div class="secondary">
${this._hiddenBy && this._hiddenBy !== "user"
? this.hass.localize(
"ui.dialogs.entity_registry.editor.hidden_cause",
"cause",
this.hass.localize(
`config_entry.hidden_by.${this._hiddenBy}`
)
)
: ""}
${this.hass.localize(
"ui.dialogs.entity_registry.editor.hidden_description"
)}
<br />${this.hass.localize(
"ui.dialogs.entity_registry.editor.note"
)}
</div>
</div>
</div>
${this.entry.device_id
? html`<ha-expansion-panel
? html`
<ha-expansion-panel
.header=${this.hass.localize(
"ui.dialogs.entity_registry.editor.advanced"
)}
@ -277,8 +313,9 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
"ui.dialogs.entity_registry.editor.area"
)}
@value-changed=${this._areaPicked}
></ha-area-picker
></ha-expansion-panel>`
></ha-area-picker>
</ha-expansion-panel>
`
: ""}
</div>
<div class="buttons">
@ -354,6 +391,12 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
) {
params.disabled_by = this._disabledBy;
}
if (
this.entry.hidden_by !== this._hiddenBy &&
(this._hiddenBy === null || this._hiddenBy === "user")
) {
params.hidden_by = this._hiddenBy;
}
try {
const result = await updateEntityRegistryEntry(
this.hass!,
@ -409,6 +452,10 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
this._disabledBy = (ev.target as HaSwitch).checked ? null : "user";
}
private _hiddenByChanged(ev: Event): void {
this._hiddenBy = (ev.target as HaSwitch).checked ? "user" : null;
}
static get styles(): CSSResultGroup {
return [
haStyle,

View File

@ -101,6 +101,8 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
@state() private _showDisabled = false;
@state() private _showHidden = false;
@state() private _showUnavailable = true;
@state() private _showReadOnly = true;
@ -301,6 +303,7 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
showDisabled: boolean,
showUnavailable: boolean,
showReadOnly: boolean,
showHidden: boolean,
entries?: ConfigEntry[]
) => {
const result: EntityRow[] = [];
@ -362,6 +365,12 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
);
}
if (!showHidden) {
filteredEntities = filteredEntities.filter(
(entity) => !entity.hidden_by
);
}
for (const entry of filteredEntities) {
const entity = this.hass.states[entry.entity_id];
const unavailable = entity?.state === UNAVAILABLE;
@ -465,6 +474,7 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
this._showDisabled,
this._showUnavailable,
this._showReadOnly,
this._showHidden,
this._entries
);
@ -603,6 +613,15 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
"ui.panel.config.entities.picker.filter.show_disabled"
)}
</ha-check-list-item>
<ha-check-list-item
@request-selected=${this._showHiddenChanged}
.selected=${this._showHidden}
left
>
${this.hass!.localize(
"ui.panel.config.entities.picker.filter.show_hidden"
)}
</ha-check-list-item>
<ha-check-list-item
@request-selected=${this._showRestoredChanged}
graphic="control"
@ -671,6 +690,7 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
entity_id: entityId,
platform: computeDomain(entityId),
disabled_by: null,
hidden_by: null,
area_id: null,
config_entry_id: null,
device_id: null,
@ -693,6 +713,13 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
this._showDisabled = ev.detail.selected;
}
private _showHiddenChanged(ev: CustomEvent<RequestSelectedDetail>) {
if (ev.detail.source !== "property") {
return;
}
this._showHidden = ev.detail.selected;
}
private _showRestoredChanged(ev: CustomEvent<RequestSelectedDetail>) {
if (ev.detail.source !== "property") {
return;

View File

@ -238,7 +238,10 @@ const computeDefaultViewStates = (
const hiddenEntities = new Set(
entityEntries
.filter(
(entry) => entry.entity_category || HIDE_PLATFORM.has(entry.platform)
(entry) =>
entry.entity_category ||
HIDE_PLATFORM.has(entry.platform) ||
entry.hidden_by
)
.map((entry) => entry.entity_id)
);

View File

@ -102,6 +102,12 @@
"integration": "Integration",
"config_entry": "Config entry",
"device": "Device"
},
"hidden_by": {
"user": "User",
"integration": "Integration",
"config_entry": "Config entry",
"device": "Device"
}
},
"ui": {
@ -785,11 +791,14 @@
"unavailable": "This entity is unavailable.",
"enabled_label": "Enable entity",
"enabled_cause": "Disabled by {cause}.",
"hidden_label": "Hide entity",
"hidden_cause": "Hidden by {cause}.",
"device_disabled": "The device of this entity is disabled.",
"open_device_settings": "Open device settings",
"enabled_description": "Disabled entities will not be added to Home Assistant.",
"enabled_delay_confirm": "The enabled entities will be added to Home Assistant in {delay} seconds",
"enabled_restart_confirm": "Restart Home Assistant to finish enabling the entities",
"hidden_description": "Hidden entities will not be shown in Home Assistant UI.",
"delete": "Delete",
"confirm_delete": "Are you sure you want to delete this entity?",
"update": "Update",
@ -2364,8 +2373,8 @@
"config": "Configuration",
"add_entities_lovelace": "Add to Lovelace",
"none": "This device has no entities",
"hide_disabled": "Hide disabled",
"disabled_entities": "+{count} {count, plural,\n one {disabled entity}\n other {disabled entities}\n}"
"hide_disabled": "Hide hidden",
"disabled_entities": "+{count} {count, plural,\n one {hidden entity}\n other {hidden entities}\n}"
},
"confirm_rename_entity_ids": "Do you also want to rename the entity IDs of your entities?",
"confirm_rename_entity_ids_warning": "This will not change any configuration (like automations, scripts, scenes, dashboards) that is currently using these entities! You will have to update them yourself to use the new entity IDs!",
@ -2405,6 +2414,7 @@
"search": "Search entities",
"filter": {
"filter": "Filter",
"show_hidden": "Show hidden entities",
"show_disabled": "Show disabled entities",
"show_unavailable": "Show unavailable entities",
"show_readonly": "Show read-only entities",