Skip to content

Commit

Permalink
Fix getting custom config parameters for Z-Wave JS (#23244)
Browse files Browse the repository at this point in the history
  • Loading branch information
MindFreeze authored Dec 12, 2024
1 parent f0ddc40 commit 9c04f57
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/data/zwave_js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,13 @@ export const getZwaveNodeRawConfigParameter = (
device_id: string,
property: number
): Promise<number> =>
hass.callWS({
type: "zwave_js/get_raw_config_parameter",
device_id,
property,
});
hass
.callWS<{ value: number }>({
type: "zwave_js/get_raw_config_parameter",
device_id,
property,
})
.then((res) => res.value);

export const reinterviewZwaveNode = (
hass: HomeAssistant,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getZwaveNodeRawConfigParameter,
setZwaveNodeRawConfigParameter,
} from "../../../../../data/zwave_js";
import { fireEvent } from "../../../../../common/dom/fire_event";

@customElement("zwave_js-custom-param")
class ZWaveJSCustomParam extends LitElement {
Expand Down Expand Up @@ -165,6 +166,10 @@ class ZWaveJSCustomParam extends LitElement {
this._customParamNumber
);
this._value = value;
fireEvent(this, "new-value", {
property: this._customParamNumber,
value: this._value,
});
} catch (err: any) {
this._error = err?.message || "Unknown error";
} finally {
Expand Down Expand Up @@ -206,6 +211,10 @@ class ZWaveJSCustomParam extends LitElement {
this._valueSize,
this._valueFormat
);
fireEvent(this, "new-value", {
property: this._customParamNumber,
value: this._value,
});
} catch (err: any) {
this._error = err?.message || "Unknown error";
} finally {
Expand Down Expand Up @@ -261,4 +270,10 @@ declare global {
interface HTMLElementTagNameMap {
"zwave_js-custom-param": ZWaveJSCustomParam;
}
interface HASSDomEvents {
"new-value": {
property: number;
value: number;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ class ZWaveJSNodeConfig extends LitElement {
<zwave_js-custom-param
.hass=${this.hass}
.deviceId=${this.deviceId}
@new-value=${this._handleNewValue}
></zwave_js-custom-param>
</ha-card>
</ha-config-section>
Expand Down Expand Up @@ -389,6 +390,10 @@ class ZWaveJSNodeConfig extends LitElement {
return false;
}

private _handleNewValue() {
this._fetchData();
}

private _switchToggled(ev) {
this._setResult(ev.target.key, undefined);
this._updateConfigParameter(ev.target, ev.detail.value ? 1 : 0);
Expand Down

0 comments on commit 9c04f57

Please sign in to comment.