Skip to content

Commit

Permalink
fix(mqtt): node added on fly not subscribed to changes (#2820)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Nov 25, 2022
1 parent 17c4fe6 commit 954b395
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/Gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,13 @@ export default class Gateway {
delete this.discovered[id]
}
}

// clean topicValues
for (const topic in this.topicValues) {
if (this.topicValues[topic].nodeId === node.id) {
delete this.topicValues[topic]
}
}
}

/**
Expand Down
23 changes: 21 additions & 2 deletions lib/ZwaveClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3357,7 +3357,9 @@ class ZwaveClient extends TypedEventEmitter<ZwaveClientEventCallbacks> {
true
)

if (res?.updated) {
// in case of writeable values whe always need to emit a
// value change event in order to subscribe mqtt topics
if (res?.updated || res.valueId.writeable) {
delayedUpdates.push(
this.emitValueChanged.bind(this, res.valueId, node, true)
)
Expand Down Expand Up @@ -4627,9 +4629,23 @@ class ZwaveClient extends TypedEventEmitter<ZwaveClientEventCallbacks> {
)
}

private zwaveNodeToJSON(node: ZWaveNode): Partial<ZWaveNode> {
private zwaveNodeToJSON(
node: ZWaveNode
): Partial<
ZWaveNode &
Pick<
ZUINode,
| 'inited'
| 'manufacturer'
| 'productDescription'
| 'productLabel'
>
> {
const zuiNode = this.nodes.get(node.id)

return {
id: node.id,
inited: zuiNode?.inited,
name: node.name,
location: node.location,
status: node.status,
Expand All @@ -4652,8 +4668,11 @@ class ZwaveClient extends TypedEventEmitter<ZwaveClientEventCallbacks> {
sdkVersion: node.sdkVersion,
firmwareVersion: node.firmwareVersion,
manufacturerId: node.manufacturerId,
manufacturer: zuiNode?.manufacturer,
productId: node.productId,
productDescription: zuiNode?.productDescription,
productType: node.productType,
productLabel: zuiNode?.productLabel,
deviceDatabaseUrl: node.deviceDatabaseUrl,
keepAwake: node.keepAwake,
}
Expand Down

0 comments on commit 954b395

Please sign in to comment.