Skip to content

Commit

Permalink
Return unique for each device instead of "00:11:22:33:44:55:66:77-88" (
Browse files Browse the repository at this point in the history
…#95)

Remove deviceid from meta.input
  • Loading branch information
datech committed Mar 5, 2020
1 parent 36251ac commit c6cc532
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/hue/templates/lights/all.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"function": "mixed",
"direction": "omnidirectional"
},
"uniqueid": "00:11:22:33:44:55:66:77-88",
"uniqueid": "{{ uniqueid }}",
"swversion": "5.105.0.21169"
},
{{/lights}}
Expand Down
20 changes: 15 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ module.exports = function(RED) {

if (config.processinput > 0 && nodeDeviceId !== null) {

msg.payload.deviceid = formatUUID(nodeDeviceId);
var deviceid = formatUUID(nodeDeviceId);

var meta = {
insert: {
Expand All @@ -110,13 +110,13 @@ module.exports = function(RED) {
}
}

var deviceAttributes = setDeviceAttributes(msg.payload.deviceid, msg.payload, meta, hubNode.context());
var deviceAttributes = setDeviceAttributes(deviceid, msg.payload, meta, hubNode.context());

// Output if
// 'Process and output' OR
// 'Process and output on state change' option is selected
if (config.processinput == 2 || (config.processinput == 3 && Object.keys(deviceAttributes.meta.changes).length > 0)) {
payloadHandler(hubNode, msg.payload.deviceid);
payloadHandler(hubNode, deviceid);
}

}
Expand Down Expand Up @@ -204,7 +204,10 @@ module.exports = function(RED) {
lights: getDevicesAttributes(hubNode.context()),
address: req.hostname,
username: req.params.username,
date: new Date().toISOString().split('.').shift()
date: new Date().toISOString().split('.').shift(),
uniqueid: function () {
return hueUniqueId(this.id);
}
}

var output = Mustache.render(template, data, {
Expand All @@ -221,7 +224,10 @@ module.exports = function(RED) {

var data = {
lights: getDevicesAttributes(hubNode.context()),
date: new Date().toISOString().split('.').shift()
date: new Date().toISOString().split('.').shift(),
uniqueid: function () {
return hueUniqueId(this.id);
}
}

var output = Mustache.render(template, data);
Expand Down Expand Up @@ -333,6 +339,10 @@ module.exports = function(RED) {
return ('' + id).replace('.', '').trim();
}

function hueUniqueId(id) {
return (id + '0000').replace(/(.{2})/g,"$1:").substring(0, 23) + '-00';
}

function getHueHubId(config) {

var uuid = '00112233-4455-6677-8899-';
Expand Down

0 comments on commit c6cc532

Please sign in to comment.