Fix helper entity settings (removing) (#16320)

This commit is contained in:
Bram Kragten 2023-04-26 15:29:59 +02:00 committed by GitHub
parent 9852186ff7
commit a5759e36b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 23 deletions

View File

@ -43,7 +43,7 @@ import {
STREAM_TYPE_HLS,
updateCameraPrefs,
} from "../../../data/camera";
import { ConfigEntry, getConfigEntries } from "../../../data/config_entries";
import { ConfigEntry } from "../../../data/config_entries";
import {
createConfigFlow,
handleConfigFlowStep,
@ -129,6 +129,8 @@ export class EntityRegistrySettingsEditor extends LitElement {
@property({ type: Boolean }) public disabled = false;
@property() public helperConfigEntry?: ConfigEntry;
@state() private _name!: string;
@state() private _icon!: string;
@ -147,8 +149,6 @@ export class EntityRegistrySettingsEditor extends LitElement {
@state() private _device?: DeviceRegistryEntry;
@state() private _helperConfigEntry?: ConfigEntry;
@state() private _unit_of_measurement?: string | null;
@state() private _precision?: number | null;
@ -177,20 +177,6 @@ export class EntityRegistrySettingsEditor extends LitElement {
private _deviceClassOptions?: string[][];
protected firstUpdated(changedProps: PropertyValues): void {
super.firstUpdated(changedProps);
if (this.entry.config_entry_id) {
getConfigEntries(this.hass, {
type: ["helper"],
domain: this.entry.platform,
}).then((entries) => {
this._helperConfigEntry = entries.find(
(ent) => ent.entry_id === this.entry.config_entry_id
);
});
}
}
protected willUpdate(changedProperties: PropertyValues) {
super.willUpdate(changedProperties);
if (!changedProperties.has("entry")) {
@ -686,7 +672,7 @@ export class EntityRegistrySettingsEditor extends LitElement {
</ha-settings-row>
`
: ""}
${this._helperConfigEntry && this._helperConfigEntry.supports_options
${this.helperConfigEntry && this.helperConfigEntry.supports_options
? html`
<ha-list-item
class="menu-item"
@ -701,7 +687,7 @@ export class EntityRegistrySettingsEditor extends LitElement {
"integration",
domainToName(
this.hass.localize,
this._helperConfigEntry.domain
this.helperConfigEntry.domain
)
)}</span
>
@ -711,7 +697,7 @@ export class EntityRegistrySettingsEditor extends LitElement {
"integration",
domainToName(
this.hass.localize,
this._helperConfigEntry.domain
this.helperConfigEntry.domain
)
)}</span
>
@ -1124,7 +1110,7 @@ export class EntityRegistrySettingsEditor extends LitElement {
}
private async _showOptionsFlow() {
showOptionsFlowDialog(this, this._helperConfigEntry!, null);
showOptionsFlowDialog(this, this.helperConfigEntry!, null);
}
private _switchAsDomainsSorted = memoizeOne(

View File

@ -2,11 +2,15 @@ import "@material/mwc-button/mwc-button";
import "@material/mwc-formfield/mwc-formfield";
import "@material/mwc-list/mwc-list-item";
import { HassEntity } from "home-assistant-js-websocket";
import { css, CSSResultGroup, html, LitElement } from "lit";
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import { fireEvent } from "../../../common/dom/fire_event";
import "../../../components/ha-alert";
import { ConfigEntry, deleteConfigEntry } from "../../../data/config_entries";
import {
ConfigEntry,
deleteConfigEntry,
getConfigEntries,
} from "../../../data/config_entries";
import { updateDeviceRegistryEntry } from "../../../data/device_registry";
import {
ExtEntityRegistryEntry,
@ -41,6 +45,20 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
@query("entity-registry-settings-editor")
private _registryEditor?: EntityRegistrySettingsEditor;
protected firstUpdated(changedProps: PropertyValues): void {
super.firstUpdated(changedProps);
if (this.entry.config_entry_id) {
getConfigEntries(this.hass, {
type: ["helper"],
domain: this.entry.platform,
}).then((entries) => {
this._helperConfigEntry = entries.find(
(ent) => ent.entry_id === this.entry.config_entry_id
);
});
}
}
protected render() {
const stateObj: HassEntity | undefined =
this.hass.states[this.entry.entity_id];
@ -90,6 +108,7 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
<entity-registry-settings-editor
.hass=${this.hass}
.entry=${this.entry}
.helperConfigEntry=${this._helperConfigEntry}
.disabled=${this._submitting}
@change=${this._entityRegistryChanged}
></entity-registry-settings-editor>