Default hide disabled entities from entity registry (#3863)

* Default hide disabled entities from entity registry

* localize

* Use memoize
This commit is contained in:
Bram Kragten 2019-10-02 21:20:47 +02:00 committed by GitHub
parent 7add8a2ea0
commit a6dda90b13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 34 deletions

View File

@ -7,6 +7,7 @@ import {
property,
} from "lit-element";
import "@polymer/paper-item/paper-icon-item";
import "@polymer/paper-item/paper-item";
import "@polymer/paper-item/paper-item-body";
import { HomeAssistant } from "../../../types";
@ -19,6 +20,7 @@ import "../../../layouts/hass-subpage";
import "../../../layouts/hass-loading-screen";
import "../../../components/ha-card";
import "../../../components/ha-icon";
import "../../../components/ha-switch";
import { domainIcon } from "../../../common/entity/domain_icon";
import { stateIcon } from "../../../common/entity/state_icon";
import { computeDomain } from "../../../common/entity/compute_domain";
@ -30,13 +32,24 @@ import {
import { UnsubscribeFunc } from "home-assistant-js-websocket";
import { compare } from "../../../common/string/compare";
import { classMap } from "lit-html/directives/class-map";
// tslint:disable-next-line
import { HaSwitch } from "../../../components/ha-switch";
import memoize from "memoize-one";
class HaConfigEntityRegistry extends LitElement {
@property() public hass!: HomeAssistant;
@property() public isWide?: boolean;
@property() private _entities?: EntityRegistryEntry[];
@property() private _showDisabled = false;
private _unsubEntities?: UnsubscribeFunc;
private _filteredEntities = memoize(
(entities: EntityRegistryEntry[], showDisabled: boolean) =>
showDisabled
? entities
: entities.filter((entity) => !Boolean(entity.disabled_by))
);
public disconnectedCallback() {
super.disconnectedCallback();
if (this._unsubEntities) {
@ -78,7 +91,17 @@ class HaConfigEntityRegistry extends LitElement {
</a>
</span>
<ha-card>
${this._entities.map((entry) => {
<paper-item>
<ha-switch
?checked=${this._showDisabled}
@change=${this._showDisabledChanged}
>${this.hass.localize(
"ui.panel.config.entity_registry.picker.show_disabled"
)}</ha-switch
></paper-item
>
${this._filteredEntities(this._entities, this._showDisabled).map(
(entry) => {
const state = this.hass!.states[entry.entity_id];
return html`
<paper-icon-item
@ -95,7 +118,9 @@ class HaConfigEntityRegistry extends LitElement {
<paper-item-body two-line>
<div class="name">
${computeEntityRegistryName(this.hass!, entry) ||
`(${this.hass!.localize("state.default.unavailable")})`}
`(${this.hass!.localize(
"state.default.unavailable"
)})`}
</div>
<div class="secondary entity-id">
${entry.entity_id}
@ -111,7 +136,8 @@ class HaConfigEntityRegistry extends LitElement {
</div>
</paper-icon-item>
`;
})}
}
)}
</ha-card>
</ha-config-section>
</hass-subpage>
@ -137,6 +163,10 @@ class HaConfigEntityRegistry extends LitElement {
}
}
private _showDisabledChanged(ev: Event) {
this._showDisabled = (ev.target as HaSwitch).checked;
}
private _openEditEntry(ev: MouseEvent): void {
const entry = (ev.currentTarget! as any).entry;
showEntityRegistryDetailDialog(this, {

View File

@ -921,7 +921,8 @@
"header": "Entity Registry",
"introduction": "Home Assistant keeps a registry of every entity it has ever seen that can be uniquely identified. Each of these entities will have an entity ID assigned which will be reserved for just this entity.",
"introduction2": "Use the entity registry to override the name, change the entity ID or remove the entry from Home Assistant. Note, removing the entity registry entry won't remove the entity. To do that, follow the link below and remove it from the integrations page.",
"integrations_page": "Integrations page"
"integrations_page": "Integrations page",
"show_disabled": "Show disabled entities"
},
"editor": {
"unavailable": "This entity is not currently available.",