mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 19:26:36 +00:00
Allow disabling entity in entity registry (#3496)
* Allow disabling entitiy in entity registry * Make strings translatable * Update dialog-entity-registry-detail.ts * Change to enabled
This commit is contained in:
parent
355e3d7911
commit
01da25d2d6
@ -9,12 +9,13 @@ export interface EntityRegistryEntry {
|
||||
platform: string;
|
||||
config_entry_id?: string;
|
||||
device_id?: string;
|
||||
disabled_by?: string;
|
||||
disabled_by: string | null;
|
||||
}
|
||||
|
||||
export interface EntityRegistryEntryUpdateParams {
|
||||
name: string | null;
|
||||
new_entity_id: string;
|
||||
name?: string | null;
|
||||
disabled_by?: string | null;
|
||||
new_entity_id?: string;
|
||||
}
|
||||
|
||||
export const computeEntityRegistryName = (
|
||||
|
@ -2,12 +2,13 @@ import {
|
||||
LitElement,
|
||||
html,
|
||||
css,
|
||||
PropertyDeclarations,
|
||||
CSSResult,
|
||||
TemplateResult,
|
||||
property,
|
||||
} from "lit-element";
|
||||
import "@polymer/paper-dialog-scrollable/paper-dialog-scrollable";
|
||||
import "@polymer/paper-input/paper-input";
|
||||
import "@polymer/paper-toggle-button/paper-toggle-button";
|
||||
|
||||
import "../../../components/dialog/ha-paper-dialog";
|
||||
|
||||
@ -20,21 +21,13 @@ import { HassEntity } from "home-assistant-js-websocket";
|
||||
import computeStateName from "../../../common/entity/compute_state_name";
|
||||
|
||||
class DialogEntityRegistryDetail extends LitElement {
|
||||
public hass!: HomeAssistant;
|
||||
private _name!: string;
|
||||
private _entityId!: string;
|
||||
private _error?: string;
|
||||
private _params?: EntityRegistryDetailDialogParams;
|
||||
private _submitting?: boolean;
|
||||
|
||||
static get properties(): PropertyDeclarations {
|
||||
return {
|
||||
_error: {},
|
||||
_name: {},
|
||||
_entityId: {},
|
||||
_params: {},
|
||||
};
|
||||
}
|
||||
@property() public hass!: HomeAssistant;
|
||||
@property() private _name!: string;
|
||||
@property() private _entityId!: string;
|
||||
@property() private _disabledBy!: string | null;
|
||||
@property() private _error?: string;
|
||||
@property() private _params?: EntityRegistryDetailDialogParams;
|
||||
@property() private _submitting?: boolean;
|
||||
|
||||
public async showDialog(
|
||||
params: EntityRegistryDetailDialogParams
|
||||
@ -43,6 +36,7 @@ class DialogEntityRegistryDetail extends LitElement {
|
||||
this._error = undefined;
|
||||
this._name = this._params.entry.name || "";
|
||||
this._entityId = this._params.entry.entity_id;
|
||||
this._disabledBy = this._params.entry.disabled_by;
|
||||
await this.updateComplete;
|
||||
}
|
||||
|
||||
@ -62,7 +56,11 @@ class DialogEntityRegistryDetail extends LitElement {
|
||||
opened
|
||||
@opened-changed="${this._openedChanged}"
|
||||
>
|
||||
<h2>${entry.entity_id}</h2>
|
||||
<h2>
|
||||
${stateObj
|
||||
? computeStateName(stateObj)
|
||||
: entry.name || entry.entity_id}
|
||||
</h2>
|
||||
<paper-dialog-scrollable>
|
||||
${!stateObj
|
||||
? html`
|
||||
@ -96,6 +94,35 @@ class DialogEntityRegistryDetail extends LitElement {
|
||||
.invalid=${invalidDomainUpdate}
|
||||
.disabled=${this._submitting}
|
||||
></paper-input>
|
||||
<div class="row">
|
||||
<paper-toggle-button
|
||||
.checked=${!this._disabledBy}
|
||||
@checked-changed=${this._disabledByChanged}
|
||||
>
|
||||
<div>
|
||||
<div>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.entity_registry.editor.enabled_label"
|
||||
)}
|
||||
</div>
|
||||
<div class="secondary">
|
||||
${this._disabledBy && this._disabledBy !== "user"
|
||||
? this.hass.localize(
|
||||
"ui.panel.config.entity_registry.editor.enabled_cause",
|
||||
"cause",
|
||||
this.hass.localize(
|
||||
`config_entry.disabled_by.${this._disabledBy}`
|
||||
)
|
||||
)
|
||||
: ""}
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.entity_registry.editor.enabled_description"
|
||||
)}
|
||||
<br />Note: this might not work yet with all integrations.
|
||||
</div>
|
||||
</div>
|
||||
</paper-toggle-button>
|
||||
</div>
|
||||
</div>
|
||||
</paper-dialog-scrollable>
|
||||
<div class="paper-dialog-buttons">
|
||||
@ -136,6 +163,7 @@ class DialogEntityRegistryDetail extends LitElement {
|
||||
try {
|
||||
await this._params!.updateEntry({
|
||||
name: this._name.trim() || null,
|
||||
disabled_by: this._disabledBy,
|
||||
new_entity_id: this._entityId.trim(),
|
||||
});
|
||||
this._params = undefined;
|
||||
@ -162,6 +190,9 @@ class DialogEntityRegistryDetail extends LitElement {
|
||||
this._params = undefined;
|
||||
}
|
||||
}
|
||||
private _disabledByChanged(ev: PolymerChangedEvent<boolean>): void {
|
||||
this._disabledBy = ev.detail.value ? null : "user";
|
||||
}
|
||||
|
||||
static get styles(): CSSResult[] {
|
||||
return [
|
||||
@ -169,6 +200,7 @@ class DialogEntityRegistryDetail extends LitElement {
|
||||
css`
|
||||
ha-paper-dialog {
|
||||
min-width: 400px;
|
||||
max-width: 450px;
|
||||
}
|
||||
.form {
|
||||
padding-bottom: 24px;
|
||||
@ -179,6 +211,13 @@ class DialogEntityRegistryDetail extends LitElement {
|
||||
.error {
|
||||
color: var(--google-red-500);
|
||||
}
|
||||
.row {
|
||||
margin-top: 8px;
|
||||
color: var(--primary-text-color);
|
||||
}
|
||||
.secondary {
|
||||
color: var(--secondary-text-color);
|
||||
}
|
||||
`,
|
||||
];
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ import {
|
||||
} from "./show-dialog-entity-registry-detail";
|
||||
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||
import { compare } from "../../../common/string/compare";
|
||||
import { classMap } from "lit-html/directives/class-map";
|
||||
|
||||
class HaConfigEntityRegistry extends LitElement {
|
||||
@property() public hass!: HomeAssistant;
|
||||
@ -82,7 +83,11 @@ class HaConfigEntityRegistry extends LitElement {
|
||||
${this._entities.map((entry) => {
|
||||
const state = this.hass!.states[entry.entity_id];
|
||||
return html`
|
||||
<paper-icon-item @click=${this._openEditEntry} .entry=${entry}>
|
||||
<paper-icon-item
|
||||
@click=${this._openEditEntry}
|
||||
.entry=${entry}
|
||||
class=${classMap({ "disabled-entry": !!entry.disabled_by })}
|
||||
>
|
||||
<ha-icon
|
||||
slot="item-icon"
|
||||
.icon=${state
|
||||
@ -92,15 +97,20 @@ class HaConfigEntityRegistry extends LitElement {
|
||||
<paper-item-body two-line>
|
||||
<div class="name">
|
||||
${computeEntityRegistryName(this.hass!, entry) ||
|
||||
this.hass!.localize(
|
||||
"ui.panel.config.entity_registry.picker.unavailable"
|
||||
)}
|
||||
`(${this.hass!.localize("state.default.unavailable")})`}
|
||||
</div>
|
||||
<div class="secondary entity-id">
|
||||
${entry.entity_id}
|
||||
</div>
|
||||
</paper-item-body>
|
||||
<div class="platform">${entry.platform}</div>
|
||||
<div class="platform">
|
||||
${entry.platform}
|
||||
${entry.disabled_by
|
||||
? html`
|
||||
<br />(disabled)
|
||||
`
|
||||
: ""}
|
||||
</div>
|
||||
</paper-icon-item>
|
||||
`;
|
||||
})}
|
||||
@ -171,15 +181,23 @@ Deleting an entry will not remove the entity from Home Assistant. To do this, yo
|
||||
color: var(--primary-color);
|
||||
}
|
||||
ha-card {
|
||||
margin-bottom: 24px;
|
||||
direction: ltr;
|
||||
overflow: hidden;
|
||||
}
|
||||
paper-icon-item {
|
||||
cursor: pointer;
|
||||
color: var(--primary-text-color);
|
||||
}
|
||||
ha-icon {
|
||||
margin-left: 8px;
|
||||
}
|
||||
.platform {
|
||||
text-align: right;
|
||||
margin: 0 0 0 8px;
|
||||
}
|
||||
.disabled-entry {
|
||||
color: var(--secondary-text-color);
|
||||
}
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
@ -367,6 +367,13 @@
|
||||
"system-users": "Users",
|
||||
"system-read-only": "Read-Only Users"
|
||||
},
|
||||
"config_entry": {
|
||||
"disabled_by": {
|
||||
"user": "User",
|
||||
"integration": "Integration",
|
||||
"config_entry": "Config Entry"
|
||||
}
|
||||
},
|
||||
"ui": {
|
||||
"auth_store": {
|
||||
"ask": "Do you want to save this login?",
|
||||
@ -847,12 +854,14 @@
|
||||
"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",
|
||||
"unavailable": "(unavailable)"
|
||||
"integrations_page": "Integrations page"
|
||||
},
|
||||
"editor": {
|
||||
"unavailable": "This entity is not currently available.",
|
||||
"default_name": "New Area",
|
||||
"enabled_label": "Enable entity",
|
||||
"enabled_cause": "Disabled by {cause}.",
|
||||
"enabled_description": "Disabled entities will not be added to Home Assistant.",
|
||||
"delete": "DELETE",
|
||||
"update": "UPDATE"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user