Skip to content

Commit

Permalink
allow duration and cps metadata to be added to mqtt messages (#1279)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaxu authored Feb 6, 2025
1 parent 981ad1e commit 8bde61f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/mqtt/mqtt.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Pattern.prototype.mqtt = function (
host = 'wss://localhost:8883/',
client = undefined,
latency = 0,
add_meta = true,
) {
const key = host + '-' + client;
let connected = false;
Expand Down Expand Up @@ -88,7 +89,12 @@ Pattern.prototype.mqtt = function (
}
let message = '';
if (typeof hap.value === 'object') {
message = JSON.stringify(hap.value);
let value = hap.value;
if (add_meta) {
const duration = hap.duration.div(cps);
value = { ...value, duration: duration.valueOf(), cps: cps };
}
message = JSON.stringify(value);
} else {
message = hap.value;
}
Expand Down

0 comments on commit 8bde61f

Please sign in to comment.