mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Remove device subscription from zwave node config (#21891)
remove device subscription from zwave node config
This commit is contained in:
parent
0ff2f1bf75
commit
618cd9d9e5
@ -6,19 +6,18 @@ import {
|
|||||||
mdiCloseCircle,
|
mdiCloseCircle,
|
||||||
mdiProgressClock,
|
mdiProgressClock,
|
||||||
} from "@mdi/js";
|
} from "@mdi/js";
|
||||||
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
|
||||||
import {
|
import {
|
||||||
css,
|
|
||||||
CSSResultGroup,
|
CSSResultGroup,
|
||||||
html,
|
|
||||||
LitElement,
|
LitElement,
|
||||||
nothing,
|
|
||||||
PropertyValues,
|
PropertyValues,
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
|
css,
|
||||||
|
html,
|
||||||
|
nothing,
|
||||||
} from "lit";
|
} from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
import memoizeOne from "memoize-one";
|
import { groupBy } from "../../../../../common/util/group-by";
|
||||||
import "../../../../../components/ha-alert";
|
import "../../../../../components/ha-alert";
|
||||||
import "../../../../../components/ha-card";
|
import "../../../../../components/ha-card";
|
||||||
import "../../../../../components/ha-icon-next";
|
import "../../../../../components/ha-icon-next";
|
||||||
@ -27,25 +26,19 @@ import "../../../../../components/ha-settings-row";
|
|||||||
import "../../../../../components/ha-svg-icon";
|
import "../../../../../components/ha-svg-icon";
|
||||||
import "../../../../../components/ha-switch";
|
import "../../../../../components/ha-switch";
|
||||||
import "../../../../../components/ha-textfield";
|
import "../../../../../components/ha-textfield";
|
||||||
import { groupBy } from "../../../../../common/util/group-by";
|
import { computeDeviceName } from "../../../../../data/device_registry";
|
||||||
import {
|
|
||||||
computeDeviceName,
|
|
||||||
DeviceRegistryEntry,
|
|
||||||
subscribeDeviceRegistry,
|
|
||||||
} from "../../../../../data/device_registry";
|
|
||||||
import {
|
import {
|
||||||
|
ZWaveJSNodeConfigParam,
|
||||||
|
ZWaveJSNodeConfigParams,
|
||||||
|
ZWaveJSSetConfigParamResult,
|
||||||
|
ZwaveJSNodeMetadata,
|
||||||
fetchZwaveNodeConfigParameters,
|
fetchZwaveNodeConfigParameters,
|
||||||
fetchZwaveNodeMetadata,
|
fetchZwaveNodeMetadata,
|
||||||
setZwaveNodeConfigParameter,
|
setZwaveNodeConfigParameter,
|
||||||
ZWaveJSNodeConfigParam,
|
|
||||||
ZWaveJSNodeConfigParams,
|
|
||||||
ZwaveJSNodeMetadata,
|
|
||||||
ZWaveJSSetConfigParamResult,
|
|
||||||
} from "../../../../../data/zwave_js";
|
} from "../../../../../data/zwave_js";
|
||||||
import "../../../../../layouts/hass-error-screen";
|
import "../../../../../layouts/hass-error-screen";
|
||||||
import "../../../../../layouts/hass-loading-screen";
|
import "../../../../../layouts/hass-loading-screen";
|
||||||
import "../../../../../layouts/hass-tabs-subpage";
|
import "../../../../../layouts/hass-tabs-subpage";
|
||||||
import { SubscribeMixin } from "../../../../../mixins/subscribe-mixin";
|
|
||||||
import { haStyle } from "../../../../../resources/styles";
|
import { haStyle } from "../../../../../resources/styles";
|
||||||
import type { HomeAssistant, Route } from "../../../../../types";
|
import type { HomeAssistant, Route } from "../../../../../types";
|
||||||
import "../../../ha-config-section";
|
import "../../../ha-config-section";
|
||||||
@ -57,16 +50,8 @@ const icons = {
|
|||||||
error: mdiCloseCircle,
|
error: mdiCloseCircle,
|
||||||
};
|
};
|
||||||
|
|
||||||
const getDevice = memoizeOne(
|
|
||||||
(
|
|
||||||
deviceId: string,
|
|
||||||
entries?: DeviceRegistryEntry[]
|
|
||||||
): DeviceRegistryEntry | undefined =>
|
|
||||||
entries?.find((device) => device.id === deviceId)
|
|
||||||
);
|
|
||||||
|
|
||||||
@customElement("zwave_js-node-config")
|
@customElement("zwave_js-node-config")
|
||||||
class ZWaveJSNodeConfig extends SubscribeMixin(LitElement) {
|
class ZWaveJSNodeConfig extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
@property({ attribute: false }) public route!: Route;
|
@property({ attribute: false }) public route!: Route;
|
||||||
@ -79,8 +64,6 @@ class ZWaveJSNodeConfig extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
@property() public deviceId!: string;
|
@property() public deviceId!: string;
|
||||||
|
|
||||||
@state() private _deviceRegistryEntries?: DeviceRegistryEntry[];
|
|
||||||
|
|
||||||
@state() private _nodeMetadata?: ZwaveJSNodeMetadata;
|
@state() private _nodeMetadata?: ZwaveJSNodeMetadata;
|
||||||
|
|
||||||
@state() private _config?: ZWaveJSNodeConfigParams;
|
@state() private _config?: ZWaveJSNodeConfigParams;
|
||||||
@ -94,19 +77,8 @@ class ZWaveJSNodeConfig extends SubscribeMixin(LitElement) {
|
|||||||
this.deviceId = this.route.path.substr(1);
|
this.deviceId = this.route.path.substr(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public hassSubscribe(): UnsubscribeFunc[] {
|
|
||||||
return [
|
|
||||||
subscribeDeviceRegistry(this.hass.connection, (entries) => {
|
|
||||||
this._deviceRegistryEntries = entries;
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected updated(changedProps: PropertyValues): void {
|
protected updated(changedProps: PropertyValues): void {
|
||||||
if (
|
if (!this._config || changedProps.has("deviceId")) {
|
||||||
(!this._config || changedProps.has("deviceId")) &&
|
|
||||||
changedProps.has("_deviceRegistryEntries")
|
|
||||||
) {
|
|
||||||
this._fetchData();
|
this._fetchData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,7 +97,7 @@ class ZWaveJSNodeConfig extends SubscribeMixin(LitElement) {
|
|||||||
return html`<hass-loading-screen></hass-loading-screen>`;
|
return html`<hass-loading-screen></hass-loading-screen>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const device = this._device!;
|
const device = this.hass.devices[this.deviceId];
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<hass-tabs-subpage
|
<hass-tabs-subpage
|
||||||
@ -392,7 +364,7 @@ class ZWaveJSNodeConfig extends SubscribeMixin(LitElement) {
|
|||||||
try {
|
try {
|
||||||
const result = await setZwaveNodeConfigParameter(
|
const result = await setZwaveNodeConfigParameter(
|
||||||
this.hass,
|
this.hass,
|
||||||
this._device!.id,
|
this.deviceId,
|
||||||
target.property,
|
target.property,
|
||||||
target.endpoint,
|
target.endpoint,
|
||||||
value,
|
value,
|
||||||
@ -420,16 +392,12 @@ class ZWaveJSNodeConfig extends SubscribeMixin(LitElement) {
|
|||||||
this._results = { ...this._results, [key]: errorParam };
|
this._results = { ...this._results, [key]: errorParam };
|
||||||
}
|
}
|
||||||
|
|
||||||
private get _device(): DeviceRegistryEntry | undefined {
|
|
||||||
return getDevice(this.deviceId, this._deviceRegistryEntries);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async _fetchData() {
|
private async _fetchData() {
|
||||||
if (!this.configEntryId || !this._deviceRegistryEntries) {
|
if (!this.configEntryId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const device = this._device;
|
const device = this.hass.devices[this.deviceId];
|
||||||
if (!device) {
|
if (!device) {
|
||||||
this._error = "device_not_found";
|
this._error = "device_not_found";
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user