mirror of
https://github.com/home-assistant/frontend.git
synced 2025-08-01 21:47:46 +00:00
Show entity reg editor for helpers when not editable (#5056)
This commit is contained in:
parent
e9b5725d7b
commit
1db31fb0f7
@ -13,7 +13,10 @@ import { isComponentLoaded } from "../../../../../common/config/is_component_loa
|
|||||||
import { dynamicElement } from "../../../../../common/dom/dynamic-element-directive";
|
import { dynamicElement } from "../../../../../common/dom/dynamic-element-directive";
|
||||||
import { fireEvent } from "../../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../../common/dom/fire_event";
|
||||||
import { HaPaperDialog } from "../../../../../components/dialog/ha-paper-dialog";
|
import { HaPaperDialog } from "../../../../../components/dialog/ha-paper-dialog";
|
||||||
import { ExtEntityRegistryEntry } from "../../../../../data/entity_registry";
|
import {
|
||||||
|
ExtEntityRegistryEntry,
|
||||||
|
removeEntityRegistryEntry,
|
||||||
|
} from "../../../../../data/entity_registry";
|
||||||
import {
|
import {
|
||||||
deleteInputBoolean,
|
deleteInputBoolean,
|
||||||
fetchInputBoolean,
|
fetchInputBoolean,
|
||||||
@ -109,23 +112,7 @@ export class EntityRegistrySettingsHelper extends LitElement {
|
|||||||
if (this._item === undefined) {
|
if (this._item === undefined) {
|
||||||
return html``;
|
return html``;
|
||||||
}
|
}
|
||||||
if (!this._componentLoaded) {
|
const stateObj = this.hass.states[this.entry.entity_id];
|
||||||
return html`
|
|
||||||
<paper-dialog-scrollable .dialogElement=${this.dialogElement}>
|
|
||||||
The ${this.entry.platform} component is not loaded, please add it your
|
|
||||||
configuration. Either by adding 'default_config:' or
|
|
||||||
'${this.entry.platform}:'.
|
|
||||||
</paper-dialog-scrollable>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
if (this._item === null) {
|
|
||||||
return html`
|
|
||||||
<paper-dialog-scrollable .dialogElement=${this.dialogElement}>
|
|
||||||
This entity can not be edited from the UI. Only entities setup from
|
|
||||||
the UI are editable.
|
|
||||||
</paper-dialog-scrollable>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
return html`
|
return html`
|
||||||
<paper-dialog-scrollable .dialogElement=${this.dialogElement}>
|
<paper-dialog-scrollable .dialogElement=${this.dialogElement}>
|
||||||
${this._error
|
${this._error
|
||||||
@ -134,6 +121,15 @@ export class EntityRegistrySettingsHelper extends LitElement {
|
|||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
<div class="form">
|
<div class="form">
|
||||||
|
${!this._componentLoaded
|
||||||
|
? this.hass.localize(
|
||||||
|
"ui.dialogs.helper_settings.platform_not_loaded",
|
||||||
|
"platform",
|
||||||
|
this.entry.platform
|
||||||
|
)
|
||||||
|
: this._item === null
|
||||||
|
? this.hass.localize("ui.dialogs.helper_settings.yaml_not_editable")
|
||||||
|
: html`
|
||||||
<div @value-changed=${this._valueChanged}>
|
<div @value-changed=${this._valueChanged}>
|
||||||
${dynamicElement(`ha-${this.entry.platform}-form`, {
|
${dynamicElement(`ha-${this.entry.platform}-form`, {
|
||||||
hass: this.hass,
|
hass: this.hass,
|
||||||
@ -141,6 +137,7 @@ export class EntityRegistrySettingsHelper extends LitElement {
|
|||||||
entry: this.entry,
|
entry: this.entry,
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
|
`}
|
||||||
<ha-registry-basic-editor
|
<ha-registry-basic-editor
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.entry=${this.entry}
|
.entry=${this.entry}
|
||||||
@ -151,13 +148,14 @@ export class EntityRegistrySettingsHelper extends LitElement {
|
|||||||
<mwc-button
|
<mwc-button
|
||||||
class="warning"
|
class="warning"
|
||||||
@click=${this._confirmDeleteItem}
|
@click=${this._confirmDeleteItem}
|
||||||
.disabled=${this._submitting}
|
.disabled=${this._submitting ||
|
||||||
|
(!this._item && !stateObj?.attributes.restored)}
|
||||||
>
|
>
|
||||||
${this.hass.localize("ui.dialogs.entity_registry.editor.delete")}
|
${this.hass.localize("ui.dialogs.entity_registry.editor.delete")}
|
||||||
</mwc-button>
|
</mwc-button>
|
||||||
<mwc-button
|
<mwc-button
|
||||||
@click=${this._updateItem}
|
@click=${this._updateItem}
|
||||||
.disabled=${this._submitting || !this._item.name}
|
.disabled=${this._submitting || (this._item && !this._item.name)}
|
||||||
>
|
>
|
||||||
${this.hass.localize("ui.dialogs.entity_registry.editor.update")}
|
${this.hass.localize("ui.dialogs.entity_registry.editor.update")}
|
||||||
</mwc-button>
|
</mwc-button>
|
||||||
@ -178,16 +176,15 @@ export class EntityRegistrySettingsHelper extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _updateItem(): Promise<void> {
|
private async _updateItem(): Promise<void> {
|
||||||
if (!this._item) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this._submitting = true;
|
this._submitting = true;
|
||||||
try {
|
try {
|
||||||
|
if (this._componentLoaded && this._item) {
|
||||||
await HELPERS[this.entry.platform].update(
|
await HELPERS[this.entry.platform].update(
|
||||||
this.hass!,
|
this.hass!,
|
||||||
this._item.id,
|
this._item.id,
|
||||||
this._item
|
this._item
|
||||||
);
|
);
|
||||||
|
}
|
||||||
await this._registryEditor?.updateEntry();
|
await this._registryEditor?.updateEntry();
|
||||||
fireEvent(this, "close-dialog");
|
fireEvent(this, "close-dialog");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -198,9 +195,6 @@ export class EntityRegistrySettingsHelper extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _confirmDeleteItem(): Promise<void> {
|
private async _confirmDeleteItem(): Promise<void> {
|
||||||
if (!this._item) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (
|
if (
|
||||||
!(await showConfirmationDialog(this, {
|
!(await showConfirmationDialog(this, {
|
||||||
text: this.hass.localize(
|
text: this.hass.localize(
|
||||||
@ -214,7 +208,15 @@ export class EntityRegistrySettingsHelper extends LitElement {
|
|||||||
this._submitting = true;
|
this._submitting = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (this._componentLoaded && this._item) {
|
||||||
await HELPERS[this.entry.platform].delete(this.hass!, this._item.id);
|
await HELPERS[this.entry.platform].delete(this.hass!, this._item.id);
|
||||||
|
} else {
|
||||||
|
const stateObj = this.hass.states[this.entry.entity_id];
|
||||||
|
if (!stateObj?.attributes.restored) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await removeEntityRegistryEntry(this.hass!, this.entry.entity_id);
|
||||||
|
}
|
||||||
fireEvent(this, "close-dialog");
|
fireEvent(this, "close-dialog");
|
||||||
} finally {
|
} finally {
|
||||||
this._submitting = false;
|
this._submitting = false;
|
||||||
|
@ -659,8 +659,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"helper_settings": {
|
"helper_settings": {
|
||||||
"not_editable": "Not editable",
|
"platform_not_loaded": "The {platform} component is not loaded, please add it your configuration. Either by adding 'default_config:' or '{platform}:'.",
|
||||||
"not_editable_text": "This entity can't be changed from the UI because it is defined in configuration.yaml.",
|
"yaml_not_editable": "The settings of this entity can not be edited from the UI. Only entities setup from the UI are configurable from the UI.",
|
||||||
"required_error_msg": "This field is required",
|
"required_error_msg": "This field is required",
|
||||||
"generic": {
|
"generic": {
|
||||||
"name": "Name",
|
"name": "Name",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user