Skip to content

Commit

Permalink
Make 16 char telemetry ID actually 16 chars
Browse files Browse the repository at this point in the history
  • Loading branch information
Joolee committed Feb 26, 2022
1 parent 4ab2b94 commit 50b58b1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/Telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,18 @@ module.exports = class Telemetry extends Homey.SimpleClass {

if (!uid) {
// 16 semi-random hexadecimal nibbles
uid = ((new Date()).getTime().toString(16) + Math.random().toString(16).slice(2)).slice(16);
uid = ((new Date()).getTime().toString(16) + Math.random().toString(16).slice(2)).slice(0, 16);
Homey.ManagerSettings.set('telemetryId', uid);
}

// A smart developer can set their own 'username' but cid must be 16 char hex
if (!this.cid) {
this.cid = uid;
if (!/^[0-9a-zA-Z]{16}$/.test(this.cid)) {
this.cid = Array.from(this.uid).reduce((p, c) => p + c.charCodeAt(0).toString(16), '').slice(0, 16).padEnd(16, 0);
}
}

return uid;
}

Expand Down Expand Up @@ -220,6 +229,7 @@ module.exports = class Telemetry extends Homey.SimpleClass {

this.sending = true;
const now = new Date();

try {
url = url.replace(/^\//, '');
metrics = {
Expand All @@ -228,6 +238,7 @@ module.exports = class Telemetry extends Homey.SimpleClass {
url: `https://${this.host}/${url}`,
...metrics,
uid: this.uid,
cid: this.cid,
idsite: this.siteId,

lang: Homey.ManagerI18n.getLanguage(),
Expand Down

0 comments on commit 50b58b1

Please sign in to comment.