ot-gateway 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/VERSION +1 -1
  2. package/apps/gateway/src/main.mjs +371 -90
  3. package/apps/web/out/404/index.html +1 -0
  4. package/apps/web/out/404.html +1 -1
  5. package/apps/web/out/__next.__PAGE__.txt +28 -26
  6. package/apps/web/out/__next._full.txt +23 -21
  7. package/apps/web/out/__next._tree.txt +2 -2
  8. package/apps/web/out/_next/static/chunks/03_syxbyimnor.js +1 -0
  9. package/apps/web/out/_next/static/chunks/1-_c1aqhwim5t.css +1 -0
  10. package/apps/web/out/_next/static/chunks/10i96w66fwhkr.js +31 -0
  11. package/apps/web/out/_next/static/chunks/1bh2-eknm9t8k.js +1 -0
  12. package/apps/web/out/_next/static/chunks/259s9pubapqip.js +1 -0
  13. package/apps/web/out/_next/static/chunks/25dqruymh00rk.js +1 -0
  14. package/apps/web/out/_next/static/chunks/2r_w-j--qdreu.js +22 -0
  15. package/apps/web/out/_next/static/chunks/3b0ql-jh_xg_k.js +12 -0
  16. package/apps/web/out/_next/static/chunks/3o5cr1y-sws-u.js +1 -0
  17. package/apps/web/out/_not-found/__next._full.txt +21 -19
  18. package/apps/web/out/_not-found/__next._not-found.__PAGE__.txt +27 -25
  19. package/apps/web/out/_not-found/__next._tree.txt +2 -2
  20. package/apps/web/out/_not-found/index.html +1 -0
  21. package/apps/web/out/_not-found/index.txt +22 -0
  22. package/apps/web/out/index.html +1 -1
  23. package/apps/web/out/index.txt +23 -21
  24. package/apps/web/out/messages/__next._full.txt +27 -0
  25. package/apps/web/out/messages/__next._tree.txt +4 -0
  26. package/apps/web/out/messages/__next.messages.__PAGE__.txt +33 -0
  27. package/apps/web/out/messages/index.html +1 -0
  28. package/apps/web/out/messages/index.txt +27 -0
  29. package/apps/web/out/points/__next._full.txt +27 -0
  30. package/apps/web/out/points/__next._tree.txt +4 -0
  31. package/apps/web/out/points/__next.points.__PAGE__.txt +33 -0
  32. package/apps/web/out/points/index.html +1 -0
  33. package/apps/web/out/points/index.txt +27 -0
  34. package/apps/web/out/settings/__next._full.txt +27 -0
  35. package/apps/web/out/settings/__next._tree.txt +4 -0
  36. package/apps/web/out/settings/__next.settings.__PAGE__.txt +33 -0
  37. package/apps/web/out/settings/index.html +1 -0
  38. package/apps/web/out/settings/index.txt +27 -0
  39. package/examples/gateway.json +37 -37
  40. package/package.json +1 -1
  41. package/packaging/compose.yaml +1 -1
  42. package/apps/web/out/_next/static/chunks/0csls39kpdzgy.js +0 -22
  43. package/apps/web/out/_next/static/chunks/162tvyao0-i49.js +0 -12
  44. package/apps/web/out/_next/static/chunks/29-6f2cs5ih9t.css +0 -1
  45. package/apps/web/out/_next/static/chunks/3oyy-mvhhfmq3.js +0 -31
  46. package/apps/web/out/_not-found.html +0 -1
  47. package/apps/web/out/_not-found.txt +0 -20
  48. /package/apps/web/out/_next/static/{s63QEywZ_oAqimFgcqV1S → r5hL3CDxDJkHMarR92YKm}/_buildManifest.js +0 -0
  49. /package/apps/web/out/_next/static/{s63QEywZ_oAqimFgcqV1S → r5hL3CDxDJkHMarR92YKm}/_clientMiddlewareManifest.js +0 -0
  50. /package/apps/web/out/_next/static/{s63QEywZ_oAqimFgcqV1S → r5hL3CDxDJkHMarR92YKm}/_ssgManifest.js +0 -0
@@ -40,9 +40,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
40
40
  mod
41
41
  ));
42
42
 
43
- // ../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/constants.js
43
+ // ../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/constants.js
44
44
  var require_constants = __commonJS({
45
- "../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/constants.js"(exports, module) {
45
+ "../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/constants.js"(exports, module) {
46
46
  "use strict";
47
47
  var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
48
48
  var hasBlob = typeof Blob !== "undefined";
@@ -63,9 +63,9 @@ var require_constants = __commonJS({
63
63
  }
64
64
  });
65
65
 
66
- // ../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/buffer-util.js
66
+ // ../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/buffer-util.js
67
67
  var require_buffer_util = __commonJS({
68
- "../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/buffer-util.js"(exports, module) {
68
+ "../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/buffer-util.js"(exports, module) {
69
69
  "use strict";
70
70
  var { websocketMask, websocketUnmask } = __require("http");
71
71
  var { EMPTY_BUFFER } = require_constants();
@@ -148,9 +148,9 @@ var require_buffer_util = __commonJS({
148
148
  }
149
149
  });
150
150
 
151
- // ../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/limiter.js
151
+ // ../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/limiter.js
152
152
  var require_limiter = __commonJS({
153
- "../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/limiter.js"(exports, module) {
153
+ "../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/limiter.js"(exports, module) {
154
154
  "use strict";
155
155
  var kDone = /* @__PURE__ */ Symbol("kDone");
156
156
  var kRun = /* @__PURE__ */ Symbol("kRun");
@@ -198,9 +198,9 @@ var require_limiter = __commonJS({
198
198
  }
199
199
  });
200
200
 
201
- // ../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/permessage-deflate.js
201
+ // ../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/permessage-deflate.js
202
202
  var require_permessage_deflate = __commonJS({
203
- "../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/permessage-deflate.js"(exports, module) {
203
+ "../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/permessage-deflate.js"(exports, module) {
204
204
  "use strict";
205
205
  var zlib = __require("zlib");
206
206
  var bufferUtil = require_buffer_util();
@@ -581,9 +581,9 @@ var require_permessage_deflate = __commonJS({
581
581
  }
582
582
  });
583
583
 
584
- // ../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/validation.js
584
+ // ../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/validation.js
585
585
  var require_validation = __commonJS({
586
- "../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/validation.js"(exports, module) {
586
+ "../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/validation.js"(exports, module) {
587
587
  "use strict";
588
588
  var { isUtf8 } = __require("buffer");
589
589
  var { hasBlob } = require_constants();
@@ -782,9 +782,9 @@ var require_validation = __commonJS({
782
782
  }
783
783
  });
784
784
 
785
- // ../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/receiver.js
785
+ // ../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/receiver.js
786
786
  var require_receiver = __commonJS({
787
- "../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/receiver.js"(exports, module) {
787
+ "../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/receiver.js"(exports, module) {
788
788
  "use strict";
789
789
  var { Writable } = __require("stream");
790
790
  var PerMessageDeflate2 = require_permessage_deflate();
@@ -1194,6 +1194,7 @@ var require_receiver = __commonJS({
1194
1194
  unmask(data, this._mask);
1195
1195
  }
1196
1196
  }
1197
+ this._mask = void 0;
1197
1198
  if (this._opcode > 7) {
1198
1199
  this.controlMessage(data, cb);
1199
1200
  return;
@@ -1405,9 +1406,9 @@ var require_receiver = __commonJS({
1405
1406
  }
1406
1407
  });
1407
1408
 
1408
- // ../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/sender.js
1409
+ // ../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/sender.js
1409
1410
  var require_sender = __commonJS({
1410
- "../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/sender.js"(exports, module) {
1411
+ "../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/sender.js"(exports, module) {
1411
1412
  "use strict";
1412
1413
  var { Duplex: Duplex2 } = __require("stream");
1413
1414
  var { randomFillSync } = __require("crypto");
@@ -1901,9 +1902,9 @@ var require_sender = __commonJS({
1901
1902
  }
1902
1903
  });
1903
1904
 
1904
- // ../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/event-target.js
1905
+ // ../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/event-target.js
1905
1906
  var require_event_target = __commonJS({
1906
- "../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/event-target.js"(exports, module) {
1907
+ "../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/event-target.js"(exports, module) {
1907
1908
  "use strict";
1908
1909
  var { kForOnEventAttribute, kListener } = require_constants();
1909
1910
  var kCode = /* @__PURE__ */ Symbol("kCode");
@@ -2130,9 +2131,9 @@ var require_event_target = __commonJS({
2130
2131
  }
2131
2132
  });
2132
2133
 
2133
- // ../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/extension.js
2134
+ // ../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/extension.js
2134
2135
  var require_extension = __commonJS({
2135
- "../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/extension.js"(exports, module) {
2136
+ "../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/extension.js"(exports, module) {
2136
2137
  "use strict";
2137
2138
  var { tokenChars } = require_validation();
2138
2139
  function push(dest, name, elem) {
@@ -2283,14 +2284,15 @@ var require_extension = __commonJS({
2283
2284
  }
2284
2285
  });
2285
2286
 
2286
- // ../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/websocket.js
2287
+ // ../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/websocket.js
2287
2288
  var require_websocket = __commonJS({
2288
- "../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/websocket.js"(exports, module) {
2289
+ "../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/websocket.js"(exports, module) {
2289
2290
  "use strict";
2290
2291
  var EventEmitter = __require("events");
2291
2292
  var https = __require("https");
2292
2293
  var http2 = __require("http");
2293
2294
  var net = __require("net");
2295
+ var querystring = __require("querystring");
2294
2296
  var tls = __require("tls");
2295
2297
  var { randomBytes: randomBytes2, createHash } = __require("crypto");
2296
2298
  var { Duplex: Duplex2, Readable: Readable6 } = __require("stream");
@@ -2817,10 +2819,9 @@ var require_websocket = __commonJS({
2817
2819
  throw new SyntaxError(`Invalid URL: ${address}`);
2818
2820
  }
2819
2821
  }
2820
- if (parsedUrl.protocol === "http:") {
2821
- parsedUrl.protocol = "ws:";
2822
- } else if (parsedUrl.protocol === "https:") {
2823
- parsedUrl.protocol = "wss:";
2822
+ if (parsedUrl.protocol === "http:" || parsedUrl.protocol === "https:") {
2823
+ parsedUrl = new URL4(parsedUrl);
2824
+ parsedUrl.protocol = parsedUrl.protocol === "http:" ? "ws:" : "wss:";
2824
2825
  }
2825
2826
  websocket._url = parsedUrl.href;
2826
2827
  const isSecure = parsedUrl.protocol === "wss:";
@@ -2889,7 +2890,9 @@ var require_websocket = __commonJS({
2889
2890
  }
2890
2891
  }
2891
2892
  if (parsedUrl.username || parsedUrl.password) {
2892
- opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
2893
+ const username = querystring.unescape(parsedUrl.username);
2894
+ const password = querystring.unescape(parsedUrl.password);
2895
+ opts.auth = `${username}:${password}`;
2893
2896
  }
2894
2897
  if (isIpcUrl) {
2895
2898
  const i = opts.path.indexOf(":");
@@ -3094,8 +3097,13 @@ var require_websocket = __commonJS({
3094
3097
  function receiverOnConclude(code, reason) {
3095
3098
  const websocket = this[kWebSocket];
3096
3099
  websocket._closeFrameReceived = true;
3097
- websocket._closeMessage = reason;
3098
3100
  websocket._closeCode = code;
3101
+ if (reason.length === 0) {
3102
+ websocket._closeMessage = EMPTY_BUFFER;
3103
+ } else {
3104
+ websocket._closeMessage = Buffer.allocUnsafeSlow(reason.length);
3105
+ websocket._closeMessage.set(reason);
3106
+ }
3099
3107
  if (websocket._socket[kWebSocket] === void 0) return;
3100
3108
  websocket._socket.removeListener("data", socketOnData);
3101
3109
  process.nextTick(resume, websocket._socket);
@@ -3197,9 +3205,9 @@ var require_websocket = __commonJS({
3197
3205
  }
3198
3206
  });
3199
3207
 
3200
- // ../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/stream.js
3208
+ // ../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/stream.js
3201
3209
  var require_stream = __commonJS({
3202
- "../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/stream.js"(exports, module) {
3210
+ "../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/stream.js"(exports, module) {
3203
3211
  "use strict";
3204
3212
  var WebSocket3 = require_websocket();
3205
3213
  var { Duplex: Duplex2 } = __require("stream");
@@ -3295,9 +3303,9 @@ var require_stream = __commonJS({
3295
3303
  }
3296
3304
  });
3297
3305
 
3298
- // ../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/subprotocol.js
3306
+ // ../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/subprotocol.js
3299
3307
  var require_subprotocol = __commonJS({
3300
- "../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/subprotocol.js"(exports, module) {
3308
+ "../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/subprotocol.js"(exports, module) {
3301
3309
  "use strict";
3302
3310
  var { tokenChars } = require_validation();
3303
3311
  function parse9(header) {
@@ -3340,9 +3348,9 @@ var require_subprotocol = __commonJS({
3340
3348
  }
3341
3349
  });
3342
3350
 
3343
- // ../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/websocket-server.js
3351
+ // ../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/websocket-server.js
3344
3352
  var require_websocket_server = __commonJS({
3345
- "../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/lib/websocket-server.js"(exports, module) {
3353
+ "../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/lib/websocket-server.js"(exports, module) {
3346
3354
  "use strict";
3347
3355
  var EventEmitter = __require("events");
3348
3356
  var http2 = __require("http");
@@ -51203,7 +51211,7 @@ var closeWindow = (window2, atMono, toMs, intervalMs, unit) => {
51203
51211
  var Slug = Schema_exports.String.pipe(
51204
51212
  Schema_exports.check(
51205
51213
  Schema_exports.isPattern(/^[a-z0-9][a-z0-9_-]*$/, {
51206
- message: "Expected a slug: lowercase letters, digits, - and _, starting with a letter or digit (vienna-hq, not Vienna HQ)"
51214
+ message: "Expected a slug: lowercase letters, digits, - and _, starting with a letter or digit (site-1, not Site 1)"
51207
51215
  }),
51208
51216
  Schema_exports.isMaxLength(64)
51209
51217
  )
@@ -53135,7 +53143,9 @@ var runDevice = Effect_exports.fn("runDevice")(function* (ctx, driver) {
53135
53143
  }
53136
53144
  }
53137
53145
  });
53146
+ let unavailable2;
53138
53147
  const send = Effect_exports.fnUntraced(function* (pointId, message) {
53148
+ if (unavailable2 !== void 0) return false;
53139
53149
  const sent = yield* publishPoint(pointTopic(topicFor(pointId)), JSON.stringify(message)).pipe(
53140
53150
  Effect_exports.as(true),
53141
53151
  Effect_exports.catchTag("PublishError", (error2) => Effect_exports.as(skipRefused(error2), false))
@@ -53192,10 +53202,26 @@ var runDevice = Effect_exports.fn("runDevice")(function* (ctx, driver) {
53192
53202
  const readAt = yield* Clock_exports.currentTimeMillis;
53193
53203
  yield* Metric_exports.update(deviceLastSuccess, readAt / 1e3);
53194
53204
  yield* Effect_exports.annotateCurrentSpan("ot_gateway.readings", readings.length);
53195
- const published = yield* handling.withPermit(Effect_exports.forEach(readings, (reading) => handleReading(reading, polledSince), { discard: true })).pipe(Effect_exports.result);
53205
+ const failedPublish = yield* handling.withPermit(
53206
+ Effect_exports.gen(function* () {
53207
+ unavailable2 = void 0;
53208
+ for (const reading of readings) {
53209
+ const handled = yield* Effect_exports.result(handleReading(reading, polledSince));
53210
+ if (Result_exports.isFailure(handled)) unavailable2 ??= handled.failure;
53211
+ }
53212
+ return unavailable2;
53213
+ }).pipe(
53214
+ // Also when the cycle's deadline interrupts it: pushed values and closing windows must not skip publishing.
53215
+ Effect_exports.ensuring(
53216
+ Effect_exports.sync(() => {
53217
+ unavailable2 = void 0;
53218
+ })
53219
+ )
53220
+ )
53221
+ );
53196
53222
  ctx.health?.recordSuccess(driver.deviceId, readAt);
53197
53223
  yield* deviceRecovered;
53198
- if (Result_exports.isFailure(published)) return yield* published.failure;
53224
+ if (failedPublish !== void 0) return yield* failedPublish;
53199
53225
  yield* countCycle("ok");
53200
53226
  }).pipe(
53201
53227
  deadline("poll-cycle"),
@@ -53993,7 +54019,7 @@ var NativeSocket = class {
53993
54019
  // ../../node_modules/.pnpm/@effect+platform-node-shared@4.1.2_effect@4.1.2/node_modules/@effect/platform-node-shared/dist/NodeSocketServer.js
53994
54020
  import * as Net3 from "node:net";
53995
54021
 
53996
- // ../../node_modules/.pnpm/ws@8.22.1/node_modules/ws/wrapper.mjs
54022
+ // ../../node_modules/.pnpm/ws@8.22.2/node_modules/ws/wrapper.mjs
53997
54023
  var import_stream3 = __toESM(require_stream(), 1);
53998
54024
  var import_extension = __toESM(require_extension(), 1);
53999
54025
  var import_permessage_deflate = __toESM(require_permessage_deflate(), 1);
@@ -58954,7 +58980,7 @@ var MqttPublisher = (settings, options3 = {}) => Layer_exports.effect(
58954
58980
  }
58955
58981
  const openTimeout2 = options3.connectTimeout ?? "10 seconds";
58956
58982
  const socket = options3.network ? yield* options3.network.tcp({ host: address.host, port: address.port, openTimeout: openTimeout2 }) : address.tls ? yield* makeTls({ host: address.host, port: address.port, servername: address.host, openTimeout: openTimeout2 }) : yield* makeNet({ host: address.host, port: address.port, openTimeout: openTimeout2 });
58957
- const { health, network: _network, ...clientOptions } = options3;
58983
+ const { health, network: _network, onConnected, ...clientOptions } = options3;
58958
58984
  const retained = /* @__PURE__ */ new Map();
58959
58985
  let connection = 0;
58960
58986
  const publishRetained = Effect_exports.fnUntraced(function* (client2, topic, payload) {
@@ -58963,6 +58989,8 @@ var MqttPublisher = (settings, options3 = {}) => Layer_exports.effect(
58963
58989
  });
58964
58990
  const onConnect = Effect_exports.fnUntraced(function* (client2) {
58965
58991
  connection++;
58992
+ const info2 = yield* client2.connection;
58993
+ if (info2 !== void 0 && onConnected !== void 0) yield* onConnected(info2);
58966
58994
  if (health !== void 0) {
58967
58995
  yield* publishRetained(client2, health.topic, yield* health.online).pipe(
58968
58996
  Effect_exports.catchTag(
@@ -59226,8 +59254,8 @@ var paceOf = (speed) => ({
59226
59254
  update: Schedule_exports.spaced(Math.max(50, Math.round(1e3 / speed)))
59227
59255
  });
59228
59256
  var rangeByUnit = {
59229
- "unit:DEG_C": [12, 24],
59230
- "unit:DEG_F": [54, 75],
59257
+ "unit:DEG_C": [25, 40],
59258
+ "unit:DEG_F": [77, 104],
59231
59259
  "unit:PERCENT_RelativeHumidity": [30, 60],
59232
59260
  "unit:PPM": [400, 1200],
59233
59261
  "unit:PA": [100, 400]
@@ -60262,7 +60290,7 @@ var describePointsListSchema = () => {
60262
60290
  };
60263
60291
  var templateRows = [
60264
60292
  {
60265
- device: "Main meter",
60293
+ device: "Energy meter",
60266
60294
  point: "Active power",
60267
60295
  unit: "kW",
60268
60296
  interval_s: "5",
@@ -60274,7 +60302,7 @@ var templateRows = [
60274
60302
  byte_order: "CDAB"
60275
60303
  },
60276
60304
  {
60277
- device: "Main meter",
60305
+ device: "Energy meter",
60278
60306
  point: "Energy",
60279
60307
  unit: "kWh",
60280
60308
  interval_s: "5",
@@ -60296,8 +60324,8 @@ var templateRows = [
60296
60324
  profile: "eastron-sdm630"
60297
60325
  },
60298
60326
  {
60299
- device: "AHU 2",
60300
- point: "Supply air temperature",
60327
+ device: "Heat pump",
60328
+ point: "Flow temperature",
60301
60329
  unit: "\xB0C",
60302
60330
  interval_s: "30",
60303
60331
  deadband: "0.2",
@@ -60306,8 +60334,8 @@ var templateRows = [
60306
60334
  object_instance: "1"
60307
60335
  },
60308
60336
  {
60309
- device: "AHU 2",
60310
- point: "Fan running",
60337
+ device: "Heat pump",
60338
+ point: "Compressor running",
60311
60339
  interval_s: "30",
60312
60340
  publish: "change",
60313
60341
  device_instance: "2001",
@@ -60559,22 +60587,22 @@ var simulatedDevice = {
60559
60587
  pollIntervalMs: 2e3,
60560
60588
  points: [
60561
60589
  {
60562
- id: "supply-air-temp",
60563
- name: "Simulated supply air temperature",
60590
+ id: "flow-temp",
60591
+ name: "Simulated flow temperature",
60564
60592
  unit: "unit:DEG_C",
60565
60593
  deadband: 0.2,
60566
60594
  waveform: "sine",
60567
- min: 16,
60568
- max: 22,
60595
+ min: 30,
60596
+ max: 38,
60569
60597
  periodSeconds: 60
60570
60598
  },
60571
60599
  {
60572
- id: "fan-speed",
60573
- name: "Simulated fan speed",
60574
- unit: "unit:PERCENT",
60600
+ id: "power",
60601
+ name: "Simulated power",
60602
+ unit: "unit:KiloW",
60575
60603
  waveform: "ramp",
60576
60604
  min: 0,
60577
- max: 100,
60605
+ max: 8,
60578
60606
  periodSeconds: 30
60579
60607
  }
60580
60608
  ]
@@ -60604,7 +60632,7 @@ var lanInterfaces = (interfaces) => Object.entries(interfaces).flatMap(
60604
60632
  return [{ name, address: info2.address, broadcast: broadcast2 }];
60605
60633
  })
60606
60634
  );
60607
- var slugMessage = "lowercase letters, digits, - and _, starting with a letter or digit (vienna-hq, not Vienna HQ)";
60635
+ var slugMessage = "lowercase letters, digits, - and _, starting with a letter or digit (site-1, not Site 1)";
60608
60636
  var validSlug = (value4) => Schema_exports.is(Slug)(value4) ? Effect_exports.succeed(value4) : Effect_exports.fail(slugMessage);
60609
60637
  var validBrokerUrl = (value4) => parseBrokerUrl(value4).pipe(
60610
60638
  Effect_exports.as(value4),
@@ -71022,6 +71050,8 @@ var DeviceStatus = Schema_exports.Struct({
71022
71050
  /** Why the device is failing (the health topic's reason). */
71023
71051
  reason: Schema_exports.optionalKey(Schema_exports.String),
71024
71052
  lastSuccess: Schema_exports.optionalKey(Schema_exports.Number),
71053
+ /** How many points the config gives it, also when `points` is left out (`/api/status?points=none`). */
71054
+ pointCount: Schema_exports.Number,
71025
71055
  points: Schema_exports.Array(PointStatus)
71026
71056
  });
71027
71057
  var CommandStatus = Schema_exports.Struct({
@@ -71068,6 +71098,41 @@ var MessageStatus = Schema_exports.Struct({
71068
71098
  /** Messages on this topic since the gateway started. */
71069
71099
  count: Schema_exports.Number
71070
71100
  });
71101
+ var BrokerConnection = Schema_exports.Struct({
71102
+ protocolVersion: Schema_exports.Literals(["5", "3.1.1"]),
71103
+ maximumQoS: Schema_exports.Literals([0, 1]),
71104
+ retainAvailable: Schema_exports.Boolean,
71105
+ /** Seconds between pings, the broker's if it set one. */
71106
+ keepAliveSeconds: Schema_exports.Number,
71107
+ /** Unacknowledged QoS 1 publishes the gateway allows itself. */
71108
+ receiveMaximum: Schema_exports.Number,
71109
+ /** Bytes; absent when the broker announced no limit. */
71110
+ maximumPacketSize: Schema_exports.optionalKey(Schema_exports.Number)
71111
+ });
71112
+ var BrokerStatus = Schema_exports.Struct({
71113
+ url: Schema_exports.String,
71114
+ connected: Schema_exports.Boolean,
71115
+ /** Unix ms of the latest successful connect, and what the broker allowed then; absent before the first. */
71116
+ connectedAt: Schema_exports.optionalKey(Schema_exports.Number),
71117
+ connection: Schema_exports.optionalKey(BrokerConnection),
71118
+ /** Successful connects (the first one and every reconnect), and attempts that failed or the broker refused. */
71119
+ connects: Schema_exports.Number,
71120
+ failedConnects: Schema_exports.Number,
71121
+ /** Point values published, and messages that could not be published (without a buffer, those are lost). */
71122
+ published: Schema_exports.Number,
71123
+ publishFailures: Schema_exports.Number
71124
+ });
71125
+ var BufferStatus = Schema_exports.Struct({
71126
+ path: Schema_exports.String,
71127
+ rows: Schema_exports.Number,
71128
+ maxRows: Schema_exports.Number,
71129
+ dropped: Schema_exports.Number,
71130
+ written: Schema_exports.Number,
71131
+ delivered: Schema_exports.Number,
71132
+ droppedBy: Schema_exports.Record(Schema_exports.String, Schema_exports.Number),
71133
+ failures: Schema_exports.Number,
71134
+ disabled: Schema_exports.Boolean
71135
+ });
71071
71136
  var GatewayStatus = Schema_exports.Struct({
71072
71137
  site: Schema_exports.String,
71073
71138
  building: Schema_exports.String,
@@ -71075,25 +71140,52 @@ var GatewayStatus = Schema_exports.Struct({
71075
71140
  /** Unix ms when the gateway started, and when this snapshot was taken. */
71076
71141
  since: Schema_exports.Number,
71077
71142
  now: Schema_exports.Number,
71078
- broker: Schema_exports.Struct({ url: Schema_exports.String, connected: Schema_exports.Boolean }),
71079
- /**
71080
- * Absent without a `buffer` in the config. `rows` wait for the broker, out of `maxRows`; `dropped` counts the
71081
- * messages the buffer gave up on since the gateway started (overflow past `maxRows`, refused, unreadable, ...).
71082
- */
71083
- buffer: Schema_exports.optionalKey(
71084
- Schema_exports.Struct({ path: Schema_exports.String, rows: Schema_exports.Number, maxRows: Schema_exports.Number, dropped: Schema_exports.Number })
71085
- ),
71143
+ broker: BrokerStatus,
71144
+ /** Absent without a `buffer` in the config. */
71145
+ buffer: Schema_exports.optionalKey(BufferStatus),
71086
71146
  /** Absent until the host monitor's first sample. */
71087
71147
  host: Schema_exports.optionalKey(HostStatus),
71088
71148
  devices: Schema_exports.Array(DeviceStatus),
71089
71149
  /** The most recent commands, newest first. */
71090
71150
  commands: Schema_exports.Array(CommandStatus)
71091
71151
  });
71152
+ var PointReading = Schema_exports.Struct({
71153
+ device: Schema_exports.String,
71154
+ point: Schema_exports.String,
71155
+ value: Schema_exports.optionalKey(Schema_exports.Union([Schema_exports.Number, Schema_exports.Boolean])),
71156
+ ts: Schema_exports.optionalKey(Schema_exports.Number)
71157
+ });
71158
+ var PointReadings = Schema_exports.Struct({ readings: Schema_exports.Array(PointReading) });
71159
+ var MAX_VALUES_PER_REQUEST = 500;
71160
+ var ValuesQueryInvalid = class extends Schema_exports.TaggedError()(
71161
+ "ValuesQueryInvalid",
71162
+ { message: Schema_exports.String },
71163
+ { httpApiStatus: 400 }
71164
+ ) {
71165
+ };
71092
71166
  var Messages = Schema_exports.Struct({
71093
71167
  messages: Schema_exports.Array(MessageStatus),
71094
71168
  /** Topics left out because the gateway keeps at most this many. */
71095
71169
  droppedTopics: Schema_exports.Number
71096
71170
  });
71171
+ var PointInfo = Schema_exports.Struct({
71172
+ device: Schema_exports.String,
71173
+ id: Schema_exports.String,
71174
+ name: Schema_exports.String,
71175
+ unit: Schema_exports.optionalKey(Schema_exports.String),
71176
+ writable: Schema_exports.Boolean,
71177
+ /** The MQTT topic its values go to (`site/building/device/point`). */
71178
+ topic: Schema_exports.String,
71179
+ /** Where the gateway reads it, in the config's words: `holding 40 · float32 CDAB`, `analog-input 3 · present-value`. */
71180
+ source: Schema_exports.String,
71181
+ /** How its values go out: `every read`, `on change ≥ 0.5`, `aggregate every 15 min`. */
71182
+ publish: Schema_exports.String,
71183
+ limits: Schema_exports.optionalKey(Schema_exports.Struct({ min: Schema_exports.Number, max: Schema_exports.Number })),
71184
+ scaling: Schema_exports.optionalKey(Schema_exports.Struct({ factor: Schema_exports.Number, offset: Schema_exports.Number })),
71185
+ brick: Schema_exports.optionalKey(Schema_exports.String),
71186
+ haystack: Schema_exports.optionalKey(Schema_exports.Array(Schema_exports.String))
71187
+ });
71188
+ var PointCatalog = Schema_exports.Struct({ points: Schema_exports.Array(PointInfo) });
71097
71189
  var HistoryBucket = Schema_exports.Struct({
71098
71190
  t: Schema_exports.Number,
71099
71191
  min: Schema_exports.Number,
@@ -71122,7 +71214,36 @@ var HistoryQueryInvalid = class extends Schema_exports.TaggedError()(
71122
71214
  { httpApiStatus: 400 }
71123
71215
  ) {
71124
71216
  };
71125
- var StatusGroup = class extends HttpApiGroup_exports.make("status").add(HttpApiEndpoint_exports.get("status", "/api/status", { success: GatewayStatus })).add(HttpApiEndpoint_exports.get("messages", "/api/messages", { success: Messages })).add(
71217
+ var ConfigEntry = Schema_exports.Struct({ key: Schema_exports.String, value: Schema_exports.Json });
71218
+ var ConfigView = Schema_exports.Struct({
71219
+ sections: Schema_exports.Array(Schema_exports.Struct({ key: Schema_exports.String, entries: Schema_exports.Array(ConfigEntry) })),
71220
+ devices: Schema_exports.Array(
71221
+ Schema_exports.Struct({
71222
+ id: Schema_exports.String,
71223
+ protocol: Schema_exports.String,
71224
+ pointCount: Schema_exports.Number,
71225
+ entries: Schema_exports.Array(ConfigEntry)
71226
+ })
71227
+ )
71228
+ });
71229
+ var StatusGroup = class extends HttpApiGroup_exports.make("status").add(
71230
+ HttpApiEndpoint_exports.get("status", "/api/status", {
71231
+ query: {
71232
+ /** `none` leaves each device's `points` empty: health without every value, for a page that pages them. */
71233
+ points: Schema_exports.optional(Schema_exports.Literals(["all", "none"]))
71234
+ },
71235
+ success: GatewayStatus
71236
+ })
71237
+ ).add(
71238
+ HttpApiEndpoint_exports.get("values", "/api/values", {
71239
+ query: {
71240
+ /** Comma-separated `device/point` keys (ids are slugs, so neither has a comma or a slash). */
71241
+ points: Schema_exports.String
71242
+ },
71243
+ success: PointReadings,
71244
+ error: ValuesQueryInvalid
71245
+ })
71246
+ ).add(HttpApiEndpoint_exports.get("messages", "/api/messages", { success: Messages })).add(HttpApiEndpoint_exports.get("points", "/api/points", { success: PointCatalog })).add(HttpApiEndpoint_exports.get("config", "/api/config", { success: ConfigView })).add(
71126
71247
  HttpApiEndpoint_exports.get("history", "/api/history", {
71127
71248
  query: {
71128
71249
  device: Schema_exports.String,
@@ -71630,13 +71751,13 @@ var formatStatus = (status3) => {
71630
71751
  ...status3.devices.map((device) => {
71631
71752
  const lastRead = device.lastSuccess === void 0 ? "no read yet" : `read ${ago(status3.now - device.lastSuccess)} ago`;
71632
71753
  const reason = device.reason === void 0 ? "" : ` (${device.reason})`;
71633
- return ` ${device.id.padEnd(width3)} ${device.status.padEnd(8)} ${device.protocol}, ${device.points.length} point(s), ${lastRead}${reason}`;
71754
+ return ` ${device.id.padEnd(width3)} ${device.status.padEnd(8)} ${device.protocol}, ${device.pointCount} point(s), ${lastRead}${reason}`;
71634
71755
  })
71635
71756
  ].join("\n");
71636
71757
  };
71637
71758
  var advice = "Is the gateway running (ot-gateway run, or ot-gateway demo)? If its status page is elsewhere, pass --url.";
71638
- var fetchGatewayStatus = (url) => HttpApiClient_exports.make(OtGatewayApi, { baseUrl: url }).pipe(
71639
- Effect_exports.flatMap((client) => client.status.status()),
71759
+ var fetchGatewayStatus = (url, points2 = "all") => HttpApiClient_exports.make(OtGatewayApi, { baseUrl: url }).pipe(
71760
+ Effect_exports.flatMap((client) => client.status.status({ query: { points: points2 } })),
71640
71761
  Effect_exports.provide(FetchHttpClient_exports.layer),
71641
71762
  // Unreachable, a timeout or an answer that does not decode: the same advice for each.
71642
71763
  Effect_exports.mapError(
@@ -71648,7 +71769,7 @@ var fetchGatewayStatus = (url) => HttpApiClient_exports.make(OtGatewayApi, { bas
71648
71769
  })
71649
71770
  );
71650
71771
  var statusReport = Effect_exports.fn("statusReport")(function* (url, options3 = {}) {
71651
- const status3 = yield* fetchGatewayStatus(url);
71772
+ const status3 = yield* fetchGatewayStatus(url, options3.json === true ? "all" : "none");
71652
71773
  yield* options3.json === true ? printJson(status3) : Console_exports.log(formatStatus(status3));
71653
71774
  });
71654
71775
 
@@ -72502,6 +72623,8 @@ var monotonicMillis2 = Effect_exports.map(Clock_exports.monotonicTimeNanos, (nan
72502
72623
  var cannotOpen = "buffer file cannot be opened: running WITHOUT store-and-forward, values are lost while the broker is down";
72503
72624
  var makeBufferedPublisher = Effect_exports.fnUntraced(function* (settings, options3) {
72504
72625
  const inner = yield* Publisher;
72626
+ const ownAttributes = yield* Metric_exports.CurrentMetricAttributes;
72627
+ const setGauge = (gauge3, value4) => Metric_exports.update(gauge3, value4).pipe(Effect_exports.provideService(Metric_exports.CurrentMetricAttributes, ownAttributes));
72505
72628
  const batchSize = options3.batchSize ?? 100;
72506
72629
  const retryDelay = options3.retryDelay ?? "5 seconds";
72507
72630
  const checkInterval = options3.checkInterval ?? "30 seconds";
@@ -72522,20 +72645,20 @@ var makeBufferedPublisher = Effect_exports.fnUntraced(function* (settings, optio
72522
72645
  const setPending = Effect_exports.fnUntraced(function* (target, rows) {
72523
72646
  target.pending = Math.max(0, rows);
72524
72647
  if (target !== current) return;
72525
- yield* Metric_exports.update(bufferRows, target.pending);
72648
+ yield* setGauge(bufferRows, target.pending);
72526
72649
  if (target.pending > 0) yield* Latch_exports.open(hasRows);
72527
72650
  else yield* Latch_exports.close(hasRows);
72528
72651
  });
72529
72652
  const install = Effect_exports.fnUntraced(function* (database) {
72530
72653
  if (database === void 0) {
72531
72654
  current = void 0;
72532
- yield* Metric_exports.update(bufferDisabled, 1);
72533
- yield* Metric_exports.update(bufferRows, 0);
72655
+ yield* setGauge(bufferDisabled, 1);
72656
+ yield* setGauge(bufferRows, 0);
72534
72657
  return yield* Latch_exports.close(hasRows);
72535
72658
  }
72536
72659
  const target = makeStore(database, yield* database.outbox.count());
72537
72660
  current = target;
72538
- yield* Metric_exports.update(bufferDisabled, 0);
72661
+ yield* setGauge(bufferDisabled, 0);
72539
72662
  yield* setPending(target, target.pending);
72540
72663
  if (target.pending > 0) {
72541
72664
  yield* Effect_exports.logInfo("buffered messages waiting from a previous run").pipe(
@@ -74540,6 +74663,96 @@ var handleCause = (nodeResponse, originalResponse) => (originalCause) => flatMap
74540
74663
  return failCause4(headersSent ? combine2(originalCause, die2(originalResponse)) : cause);
74541
74664
  });
74542
74665
 
74666
+ // src/PointCatalog.ts
74667
+ var durationLabel = (ms) => {
74668
+ if (ms < 6e4) return `${Number((ms / 1e3).toFixed(1))} s`;
74669
+ if (ms < 36e5) return `${Number((ms / 6e4).toFixed(1))} min`;
74670
+ return `${Number((ms / 36e5).toFixed(1))} h`;
74671
+ };
74672
+ var publishLabel = (publish2) => {
74673
+ switch (publish2.mode) {
74674
+ case "sample":
74675
+ return publish2.intervalMs === void 0 ? "every read" : `latest, every ${durationLabel(publish2.intervalMs)}`;
74676
+ case "aggregate":
74677
+ return `aggregate every ${durationLabel(publish2.intervalMs)}`;
74678
+ case "change": {
74679
+ const change = publish2.deadband === void 0 || publish2.deadband === 0 ? "on change" : `on change \u2265 ${publish2.deadband}`;
74680
+ return publish2.maxSilenceMs === void 0 ? change : `${change}, at least every ${durationLabel(publish2.maxSilenceMs)}`;
74681
+ }
74682
+ }
74683
+ };
74684
+ var modbusSource = (point) => {
74685
+ const bit = point.bit === void 0 ? "" : ` bit ${point.bit}`;
74686
+ const order = point.table === "holding" || point.table === "input" ? ` ${point.byteOrder}` : "";
74687
+ return `${point.table} ${point.address}${bit} \xB7 ${point.dataType}${order}`;
74688
+ };
74689
+ var bacnetSource = (point) => `${point.objectType} ${point.instance} \xB7 ${point.property}${point.writable ? ` \xB7 priority ${point.priority}` : ""}`;
74690
+ var simulatedSource = (point) => point.waveform === "constant" ? `constant ${point.min}` : `${point.waveform} ${point.min} to ${point.max} \xB7 ${durationLabel(point.periodSeconds * 1e3)}`;
74691
+ var sourcedPoints = (device) => {
74692
+ switch (device.protocol) {
74693
+ case "modbus-tcp":
74694
+ return device.points.map((point) => [point, modbusSource(point)]);
74695
+ case "bacnet-ip":
74696
+ return device.points.map((point) => [point, bacnetSource(point)]);
74697
+ case "simulator":
74698
+ return device.points.map((point) => [point, simulatedSource(point)]);
74699
+ }
74700
+ };
74701
+ var pointCatalog = (config) => ({
74702
+ points: config.devices.flatMap(
74703
+ (device) => sourcedPoints(device).map(([point, source]) => {
74704
+ const semantics = point.semantics;
74705
+ return {
74706
+ device: device.id,
74707
+ id: point.id,
74708
+ name: point.name,
74709
+ ...point.unit === void 0 ? {} : { unit: point.unit },
74710
+ writable: point.writable,
74711
+ topic: pointTopic({ site: config.site, building: config.building, device: device.id, point: point.id }),
74712
+ source,
74713
+ publish: publishLabel(publishOf(device.publish, point)),
74714
+ ...point.limits === void 0 ? {} : { limits: point.limits },
74715
+ ...point.scaling === void 0 ? {} : { scaling: point.scaling },
74716
+ ...semantics?.brick === void 0 ? {} : { brick: semantics.brick },
74717
+ ...semantics?.haystack === void 0 ? {} : { haystack: semantics.haystack }
74718
+ };
74719
+ })
74720
+ )
74721
+ });
74722
+
74723
+ // src/ConfigView.ts
74724
+ var encodeConfig = Schema_exports.encodeSync(GatewayConfig);
74725
+ var asJson = Schema_exports.decodeUnknownSync(Schema_exports.Json);
74726
+ var isObject2 = (value4) => typeof value4 === "object" && value4 !== null && !Array.isArray(value4);
74727
+ var entriesOf = (object, skip2 = []) => Object.entries(object).filter(([key5]) => !skip2.includes(key5)).map(([key5, value4]) => ({ key: key5, value: value4 }));
74728
+ var configView = (config) => {
74729
+ const encoded = asJson(encodeConfig(config));
74730
+ if (!isObject2(encoded)) return { sections: [], devices: [] };
74731
+ const usesBacnet = config.devices.some((device) => device.protocol === "bacnet-ip");
74732
+ const top = Object.entries(encoded);
74733
+ const sections = [
74734
+ { key: "gateway", entries: top.filter(([, value4]) => !isObject2(value4) && !Array.isArray(value4)) },
74735
+ ...top.filter(([key5, value4]) => isObject2(value4) && (key5 !== "bacnet" || usesBacnet)).map(([key5, value4]) => ({ key: key5, entries: isObject2(value4) ? Object.entries(value4) : [] }))
74736
+ ].map((section) => ({
74737
+ key: section.key,
74738
+ entries: section.entries.map(([key5, value4]) => ({ key: key5, value: value4 }))
74739
+ }));
74740
+ const devices = config.devices.map((device, index2) => {
74741
+ const raw3 = Array.isArray(encoded["devices"]) ? encoded["devices"][index2] : void 0;
74742
+ return {
74743
+ id: device.id,
74744
+ protocol: device.protocol,
74745
+ pointCount: device.points.length,
74746
+ // The publish mode in words, as the Points tab shows it, and the default spelled out when the file has none.
74747
+ entries: [
74748
+ ...raw3 !== void 0 && isObject2(raw3) ? entriesOf(raw3, ["id", "protocol", "points", "publish"]) : [],
74749
+ { key: "publish", value: publishLabel(device.publish ?? everyRead) }
74750
+ ]
74751
+ };
74752
+ });
74753
+ return { sections, devices };
74754
+ };
74755
+
74543
74756
  // src/Status.ts
74544
74757
  import { createServer as createServer2 } from "node:http";
74545
74758
  import { fileURLToPath as fileURLToPath5 } from "node:url";
@@ -74559,6 +74772,14 @@ var makeStatusState = (config, health, since, host) => {
74559
74772
  const latest = /* @__PURE__ */ new Map();
74560
74773
  const droppedTopics = /* @__PURE__ */ new Set();
74561
74774
  const commands2 = [];
74775
+ let broker;
74776
+ const catalog = pointCatalog(config);
74777
+ const settings = configView(config);
74778
+ const configured = new Set(catalog.points.map((point) => `${point.device}/${point.id}`));
74779
+ const lastRead = (key5) => {
74780
+ const payload = payloads.get(key5);
74781
+ return reads.get(key5) ?? Option_exports.getOrUndefined(payload === void 0 ? Option_exports.none() : decodeValue2(payload));
74782
+ };
74562
74783
  const attributes = { site: config.site, building: config.building };
74563
74784
  return {
74564
74785
  recordPublish: (topic, payload, message) => {
@@ -74581,6 +74802,9 @@ var makeStatusState = (config, health, since, host) => {
74581
74802
  reads.set(`${device}/${point}`, { value: value4, ts });
74582
74803
  }
74583
74804
  },
74805
+ recordBrokerConnection: (at, connection) => {
74806
+ broker = { at, connection };
74807
+ },
74584
74808
  recordCommand: (at, command, outcome) => {
74585
74809
  commands2.unshift({
74586
74810
  at,
@@ -74591,14 +74815,16 @@ var makeStatusState = (config, health, since, host) => {
74591
74815
  });
74592
74816
  if (commands2.length > RECENT_COMMANDS) commands2.length = RECENT_COMMANDS;
74593
74817
  },
74594
- snapshot: Effect_exports.gen(function* () {
74818
+ snapshot: (points2 = "all") => Effect_exports.gen(function* () {
74595
74819
  const now2 = yield* Clock_exports.currentTimeMillis;
74596
74820
  const connected = (yield* Metric_exports.value(Metric_exports.withAttributes(mqttConnected, attributes))).value === 1;
74597
74821
  const rows = (yield* Metric_exports.value(Metric_exports.withAttributes(bufferRows, attributes))).value;
74598
- let dropped = 0;
74599
- for (const reason of bufferDropReasons) {
74600
- dropped += (yield* Metric_exports.value(Metric_exports.withAttributes(bufferDropped, { ...attributes, reason }))).count;
74601
- }
74822
+ const disabled2 = (yield* Metric_exports.value(Metric_exports.withAttributes(bufferDisabled, attributes))).value === 1;
74823
+ const total = totals(yield* Metric_exports.snapshot, attributes);
74824
+ const droppedBy = Object.fromEntries(
74825
+ bufferDropReasons.map((reason) => [reason, total(bufferDropped.id, { reason })])
74826
+ );
74827
+ const dropped = Object.values(droppedBy).reduce((sum3, count2) => sum3 + count2, 0);
74602
74828
  const devices = config.devices.map((device) => {
74603
74829
  const state = health.devices.get(device.id) ?? { status: "starting" };
74604
74830
  return {
@@ -74608,10 +74834,9 @@ var makeStatusState = (config, health, since, host) => {
74608
74834
  pollIntervalMs: device.pollIntervalMs,
74609
74835
  ...state.reason === void 0 ? {} : { reason: state.reason },
74610
74836
  ...state.lastSuccess === void 0 ? {} : { lastSuccess: state.lastSuccess },
74611
- points: device.points.map((point) => {
74612
- const key5 = `${device.id}/${point.id}`;
74613
- const payload = payloads.get(key5);
74614
- const last2 = reads.get(key5) ?? Option_exports.getOrUndefined(payload === void 0 ? Option_exports.none() : decodeValue2(payload));
74837
+ pointCount: device.points.length,
74838
+ points: points2 === "none" ? [] : device.points.map((point) => {
74839
+ const last2 = lastRead(`${device.id}/${point.id}`);
74615
74840
  return {
74616
74841
  id: point.id,
74617
74842
  name: point.name,
@@ -74629,13 +74854,54 @@ var makeStatusState = (config, health, since, host) => {
74629
74854
  id: config.id,
74630
74855
  since,
74631
74856
  now: now2,
74632
- broker: { url: config.mqtt.url, connected },
74633
- ...config.buffer === void 0 ? {} : { buffer: { path: config.buffer.path, rows: Math.max(0, rows), maxRows: config.buffer.maxRows, dropped } },
74857
+ broker: {
74858
+ url: config.mqtt.url,
74859
+ connected,
74860
+ ...broker === void 0 ? {} : { connectedAt: broker.at, connection: broker.connection },
74861
+ connects: total(mqttConnects.id, { outcome: "ok" }),
74862
+ failedConnects: total(mqttConnects.id, { outcome: "failed" }) + total(mqttConnects.id, { outcome: "rejected" }),
74863
+ published: total(valuesPublished.id),
74864
+ publishFailures: total(publishFailures.id)
74865
+ },
74866
+ ...config.buffer === void 0 ? {} : {
74867
+ buffer: {
74868
+ path: config.buffer.path,
74869
+ rows: Math.max(0, rows),
74870
+ maxRows: config.buffer.maxRows,
74871
+ dropped,
74872
+ written: total(bufferWritten.id),
74873
+ delivered: total(bufferDrained.id),
74874
+ droppedBy,
74875
+ failures: total(bufferFailures.id),
74876
+ disabled: disabled2
74877
+ }
74878
+ },
74634
74879
  ...host === void 0 || sample === void 0 ? {} : { host: { version: host.version, node: process.versions.node, ...sample } },
74635
74880
  devices,
74636
74881
  commands: [...commands2]
74637
74882
  };
74638
74883
  }),
74884
+ values: (keys4) => Effect_exports.gen(function* () {
74885
+ const asked = keys4.split(",").filter((key5) => key5 !== "");
74886
+ if (asked.length > MAX_VALUES_PER_REQUEST) {
74887
+ return yield* new ValuesQueryInvalid({
74888
+ message: `${asked.length} points asked for, at most ${MAX_VALUES_PER_REQUEST} per request`
74889
+ });
74890
+ }
74891
+ const readings = asked.flatMap((key5) => {
74892
+ if (!configured.has(key5)) return [];
74893
+ const slash = key5.indexOf("/");
74894
+ const last2 = lastRead(key5);
74895
+ return [
74896
+ {
74897
+ device: key5.slice(0, slash),
74898
+ point: key5.slice(slash + 1),
74899
+ ...last2 === void 0 ? {} : { value: last2.value, ts: last2.ts }
74900
+ }
74901
+ ];
74902
+ });
74903
+ return { readings };
74904
+ }),
74639
74905
  messages: Effect_exports.sync(() => ({
74640
74906
  messages: [...latest.entries()].toSorted(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([topic, message]) => ({
74641
74907
  topic,
@@ -74646,9 +74912,21 @@ var makeStatusState = (config, health, since, host) => {
74646
74912
  count: message.count
74647
74913
  })),
74648
74914
  droppedTopics: droppedTopics.size
74649
- }))
74915
+ })),
74916
+ points: Effect_exports.succeed(catalog),
74917
+ config: Effect_exports.succeed(settings)
74650
74918
  };
74651
74919
  };
74920
+ var totals = (snapshots, scope3) => (id2, match9 = {}) => {
74921
+ const wanted = Object.entries({ ...scope3, ...match9 });
74922
+ let sum3 = 0;
74923
+ for (const snapshot3 of snapshots) {
74924
+ if (snapshot3.id !== id2 || snapshot3.type !== "Counter") continue;
74925
+ const attributes = snapshot3.attributes ?? {};
74926
+ if (wanted.every(([key5, value4]) => attributes[key5] === value4)) sum3 += Number(snapshot3.state.count);
74927
+ }
74928
+ return sum3;
74929
+ };
74652
74930
  var DEFAULT_HISTORY_MS = 36e5;
74653
74931
  var historyHandler = (config, history) => (request3) => Effect_exports.gen(function* () {
74654
74932
  if (history === void 0) {
@@ -74679,7 +74957,7 @@ var serveStatus = (settings, state, history = () => Effect_exports.fail(new Hist
74679
74957
  HttpApiBuilder_exports.group(
74680
74958
  OtGatewayApi,
74681
74959
  "status",
74682
- (handlers) => handlers.handle("status", () => state.snapshot).handle("messages", () => state.messages).handle("history", ({ query: query3 }) => history(query3))
74960
+ (handlers) => handlers.handle("status", ({ query: query3 }) => state.snapshot(query3.points)).handle("values", ({ query: query3 }) => state.values(query3.points)).handle("messages", () => state.messages).handle("points", () => state.points).handle("config", () => state.config).handle("history", ({ query: query3 }) => history(query3))
74683
74961
  )
74684
74962
  )
74685
74963
  );
@@ -76422,6 +76700,9 @@ var northbound = (config, health, options3, routing, status3, staleMeta) => {
76422
76700
  health: { topic: health.topic, online: health.online },
76423
76701
  // With a buffer, a value that cannot go out now is stored, so waiting for the broker would only stall reads.
76424
76702
  waitForConnection: config.buffer === void 0,
76703
+ ...status3 === void 0 ? {} : {
76704
+ onConnected: (connection) => Effect_exports.map(Clock_exports.currentTimeMillis, (at) => status3.recordBrokerConnection(at, connection))
76705
+ },
76425
76706
  ...options3.network === void 0 ? {} : { network: options3.network },
76426
76707
  subscriptions: [...commandSubscriptions, ...staleMeta.subscriptions],
76427
76708
  // A `$meta` topic is never a command topic (`.../$set`), so each message has one taker.
@@ -76654,7 +76935,7 @@ var init2 = Command_exports.make(
76654
76935
  Argument_exports.optional,
76655
76936
  Argument_exports.map(Option_exports.getOrUndefined)
76656
76937
  ),
76657
- site: optionalFlag("site", "The site, the first topic segment (a slug: vienna-hq)"),
76938
+ site: optionalFlag("site", "The site, the first topic segment (a slug: site-1)"),
76658
76939
  building: optionalFlag("building", "The building, the second topic segment"),
76659
76940
  broker: optionalFlag("broker", "The MQTT broker URL, mqtts:// for TLS"),
76660
76941
  username: optionalFlag("username", "The broker username"),
@@ -76724,15 +77005,15 @@ var init2 = Command_exports.make(
76724
77005
  ),
76725
77006
  Command_exports.withExamples([
76726
77007
  {
76727
- command: "ot-gateway init vienna-hq",
76728
- description: "Make the folder vienna-hq and write the gateway's files in it"
77008
+ command: "ot-gateway init site-1",
77009
+ description: "Make the folder site-1 and write the gateway's files in it"
76729
77010
  },
76730
77011
  { command: "ot-gateway init .", description: "Write them in this folder" },
76731
77012
  {
76732
- command: "ot-gateway init vienna-hq --yes --site vienna-hq --broker mqtts://broker.example:8883 --points points.csv",
77013
+ command: "ot-gateway init site-1 --yes --site site-1 --broker mqtts://broker.example:8883 --points points.csv",
76733
77014
  description: "The same without questions, for scripts and agents"
76734
77015
  },
76735
- { command: "ot-gateway init vienna-hq --json --dry-run --site vienna-hq", description: "Only show it, as JSON" }
77016
+ { command: "ot-gateway init site-1 --json --dry-run --site site-1", description: "Only show it, as JSON" }
76736
77017
  ])
76737
77018
  );
76738
77019
  var importCommand = Command_exports.make(
@@ -76873,7 +77154,7 @@ var watchCommand = Command_exports.make(
76873
77154
  Command_exports.withDescription("Print what arrives at the config's broker under its site and building, as it arrives"),
76874
77155
  Command_exports.withExamples([
76875
77156
  { command: "ot-gateway watch", description: "Watch the broker in ot-gateway.json" },
76876
- { command: "ot-gateway watch --topic 'my-site/main/ahu-1/#'", description: "Only one device" },
77157
+ { command: "ot-gateway watch --topic 'site-1/building-a/heat-pump/#'", description: "Only one device" },
76877
77158
  { command: "ot-gateway watch --seconds 10", description: "Ten seconds of it, then stop" },
76878
77159
  { command: "ot-gateway watch --seconds 10 --json", description: "The same as JSON lines, for scripts and agents" }
76879
77160
  ])