smart-home-engine 0.27.3 → 0.27.5

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.
@@ -1,4 +1,4 @@
1
- import{m as O}from"./monaco-langs-BW2J83t5.js";import{t as I}from"./index-Ck2pAcwb.js";/*!-----------------------------------------------------------------------------
1
+ import{m as O}from"./monaco-langs-BW2J83t5.js";import{t as I}from"./index-DlX_4aUV.js";/*!-----------------------------------------------------------------------------
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
3
  * Version: 0.52.2(404545bded1df6ffa41ea0af4e8ddb219018c6c1)
4
4
  * Released under the MIT license
@@ -155,10 +155,10 @@
155
155
  }
156
156
  })();
157
157
  </script>
158
- <script type="module" crossorigin src="/assets/index-Ck2pAcwb.js"></script>
158
+ <script type="module" crossorigin src="/assets/index-DlX_4aUV.js"></script>
159
159
  <link rel="modulepreload" crossorigin href="/assets/monaco-langs-BW2J83t5.js">
160
160
  <link rel="stylesheet" crossorigin href="/assets/monaco-langs-DyX1CsEw.css">
161
- <link rel="stylesheet" crossorigin href="/assets/index-6dbanXAb.css">
161
+ <link rel="stylesheet" crossorigin href="/assets/index-CYeO3Jr9.css">
162
162
  </head>
163
163
  <body>
164
164
  <div id="app"></div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smart-home-engine",
3
- "version": "0.27.3",
3
+ "version": "0.27.5",
4
4
  "description": "Node.js based script runner for use in MQTT based Smart Home environments",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -47,7 +47,7 @@ const _pino = require('pino')(
47
47
  }),
48
48
  );
49
49
  // Lazy import — log-ws exports a no-op broadcastLog when the HTTP server is not started.
50
- const { broadcastLog, broadcast } = require('./web/log-ws');
50
+ const { broadcastLog, broadcast, setWelcomeProvider } = require('./web/log-ws');
51
51
  const shedb = require('./web/shedb');
52
52
  const log = {
53
53
  debug: (...args) => {
@@ -247,7 +247,7 @@ let _startupTimeout = null; // fires if broker never connects
247
247
  let _sentinelTimeout = null; // fires if sentinel never arrives after connecting
248
248
  let _sentinelValue = null; // unique value for this boot's sentinel
249
249
  const _STARTUP_TIMEOUT_MS = 10000; // ms to wait for broker before starting anyway
250
- const _SENTINEL_TIMEOUT_MS = 10000; // ms to wait for sentinel after connecting
250
+ const _SENTINEL_TIMEOUT_MS = 15000; // ms to wait for sentinel after connecting
251
251
 
252
252
  function startOnce(reason) {
253
253
  if (_started) return;
@@ -261,6 +261,7 @@ function startOnce(reason) {
261
261
  _sentinelTimeout = null;
262
262
  }
263
263
  if (reason) log.info(reason);
264
+ broadcast({ type: 'mqtt:status', ready: true });
264
265
  start();
265
266
  }
266
267
 
@@ -326,6 +327,10 @@ require('./web/server').setStatsProvider(() => {
326
327
  };
327
328
  });
328
329
 
330
+ // Inform newly-connected WebSocket clients of the current mqtt:status so the
331
+ // UI shows the correct indicator even if the browser opened after the event fired.
332
+ setWelcomeProvider(() => ({ type: 'mqtt:status', ready: _started }));
333
+
329
334
  if (!config.url) {
330
335
  log.warn('no MQTT broker URL configured — set "url" in ' + path.join(require('os').homedir(), '.she', 'config.json'));
331
336
  }
@@ -363,6 +368,7 @@ if (config.url) {
363
368
  _sentinelValue = String(Date.now());
364
369
  mqtt.publish(config.name + '/she-sentinel', _sentinelValue, { retain: false });
365
370
  log.debug('mqtt: waiting for retained-state sentinel');
371
+ broadcast({ type: 'mqtt:status', ready: false });
366
372
 
367
373
  // Fallback: if sentinel never arrives (e.g. abnormal broker behaviour)
368
374
  _sentinelTimeout = setTimeout(() => {
@@ -144,7 +144,7 @@ parentPort.on('message', (msg) => {
144
144
 
145
145
  case 'delQuery':
146
146
  delete queries[msg.id];
147
- queue = queue.filter((id) => id !== msg.id);
147
+ queue.delete(msg.id);
148
148
  parentPort.postMessage({ type: 'view', id: msg.id, deleted: true });
149
149
  break;
150
150
  }
package/src/web/log-ws.js CHANGED
@@ -4,6 +4,17 @@ const { WebSocketServer } = require('ws');
4
4
 
5
5
  let _wss = null;
6
6
  const _clients = new Set();
7
+ let _welcomeProvider = null;
8
+
9
+ /**
10
+ * Register a function that returns a welcome message to send to each new
11
+ * WebSocket client immediately after it connects. Useful for pushing
12
+ * current state (e.g. mqtt:status) without waiting for the next broadcast.
13
+ * @param {() => object} fn
14
+ */
15
+ function setWelcomeProvider(fn) {
16
+ _welcomeProvider = fn;
17
+ }
7
18
 
8
19
  // Ring buffer of recent log entries for the AI tool get_script_logs
9
20
  const _logBuffer = [];
@@ -31,6 +42,11 @@ function attachWss(httpServer, authCheck = () => true) {
31
42
  _clients.add(ws);
32
43
  ws.on('close', () => _clients.delete(ws));
33
44
  ws.on('error', () => _clients.delete(ws));
45
+ // Send current state to this new client immediately
46
+ if (_welcomeProvider) {
47
+ const welcome = _welcomeProvider();
48
+ if (welcome) ws.send(JSON.stringify(welcome));
49
+ }
34
50
  });
35
51
 
36
52
  // Keepalive ping every 30 s
@@ -90,4 +106,4 @@ function closeWss() {
90
106
  });
91
107
  }
92
108
 
93
- module.exports = { attachWss, broadcast, broadcastLog, closeWss, getLogBuffer };
109
+ module.exports = { attachWss, broadcast, broadcastLog, closeWss, getLogBuffer, setWelcomeProvider };