Skip to content

Commit

Permalink
fix: use prefixed node.id in mqtt discovery topic (#920)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmaroschik authored Mar 22, 2021
1 parent fbb194f commit 2c8bccb
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/Gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,8 +676,10 @@ function deviceInfo (node, nodeName) {
* @param {string} nodeName Node name from getNodeName function
* @returns The topic string for this device discovery
*/
function getDiscoveryTopic (hassDevice, nodeName) {
return `${hassDevice.type}/${nodeName}/${hassDevice.object_id}/config`
function getDiscoveryTopic (hassDevice, nodeId) {
return `${hassDevice.type}/${NODE_PREFIX + nodeId}/${
hassDevice.object_id
}/config`
}

/**
Expand Down Expand Up @@ -1456,7 +1458,7 @@ Gateway.prototype.discoverDevice = function (node, hassDevice) {
'_' +
hassDevice.object_id

const discoveryTopic = getDiscoveryTopic(hassDevice, nodeName)
const discoveryTopic = getDiscoveryTopic(hassDevice, node.id)
hassDevice.discoveryTopic = discoveryTopic

// This configuration is not stored in nodes.json
Expand Down Expand Up @@ -2157,7 +2159,7 @@ Gateway.prototype.discoverValue = function (node, vId) {
'_' +
utils.sanitizeTopic(valueId.id, true)

const discoveryTopic = getDiscoveryTopic(cfg, nodeName)
const discoveryTopic = getDiscoveryTopic(cfg, node.id)

cfg.discoveryTopic = discoveryTopic
cfg.values = cfg.values || []
Expand Down

0 comments on commit 2c8bccb

Please sign in to comment.