Skip to content

Commit

Permalink
fix: node name and location change not catched on value added (#3612)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando authored Feb 22, 2024
1 parent 09b107a commit fa37244
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions api/lib/ZwaveClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2367,6 +2367,23 @@ class ZwaveClient extends TypedEventEmitter<ZwaveClientEventCallbacks> {
)
}

private onNodeNameLocationChanged(
node: ZUINode,
valueId: ZUIValueId,
value: string,
) {
const prop = valueId.property
const observer =
observedCCProps[CommandClasses['Node Naming and Location']]?.[prop]

if (observer) {
observer.call(this, node, {
...valueId,
value,
})
}
}

/**
* Send an event to socket with `data`
*
Expand Down Expand Up @@ -6106,11 +6123,16 @@ class ZwaveClient extends TypedEventEmitter<ZwaveClientEventCallbacks> {
if (!node) {
logger.info(`ValueAdded: no such node: ${zwaveNode.id} error`)
} else {
// ignore node name and location CC, we already show the inputs for it
if (
zwaveValue.commandClass ===
CommandClasses['Node Naming and Location']
) {
this.onNodeNameLocationChanged(
node,
zwaveValue as ZUIValueId,
zwaveNode.getValue(zwaveValue),
)

return null
}

Expand Down Expand Up @@ -6230,23 +6252,16 @@ class ZwaveClient extends TypedEventEmitter<ZwaveClientEventCallbacks> {
// node name and location emit a value update but
// there could be no defined valueId as not all nodes
// support that CC but zwave-js does, also we ignore it
// on `_valueAdded`. Ref: (https://github.com/zwave-js/zwave-js-ui/issues/3591)
// on `_addvalue`. Ref: (https://github.com/zwave-js/zwave-js-ui/issues/3591)
if (
args.commandClass ===
CommandClasses['Node Naming and Location']
) {
const prop = args.property
const observer =
observedCCProps[
CommandClasses['Node Naming and Location']
]?.[prop]

if (observer) {
observer.call(this, node, {
...args,
value: args.newValue,
})
}
this.onNodeNameLocationChanged(
node,
args as ZUIValueId,
args.newValue,
)
}

return
Expand Down

0 comments on commit fa37244

Please sign in to comment.