smart-home-engine 0.30.0 → 0.32.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.
@@ -1,4 +1,4 @@
1
- import{m as O}from"./monaco-langs-BW2J83t5.js";import{t as I}from"./index-3AzTXNmr.js";/*!-----------------------------------------------------------------------------
1
+ import{m as O}from"./monaco-langs-BW2J83t5.js";import{t as I}from"./index-BfPts03-.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-3AzTXNmr.js"></script>
158
+ <script type="module" crossorigin src="/assets/index-BfPts03-.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-DqYTpwg5.css">
161
+ <link rel="stylesheet" crossorigin href="/assets/index-BvaykAGz.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.30.0",
3
+ "version": "0.32.0",
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
@@ -319,6 +319,7 @@ require('./web/server').setStatsProvider(() => {
319
319
  }
320
320
  return {
321
321
  scripts: Object.keys(scripts).length,
322
+ runningScripts: Object.keys(scripts).map(f => makeLabel(f).slice(0, -1)),
322
323
  topics,
323
324
  mqttMsgPerSec,
324
325
  matterEnabled: !!config.matterStorage,
@@ -896,32 +897,6 @@ function runScript(script, name, _origin) {
896
897
  return store.getObject('mqtt::' + topic);
897
898
  },
898
899
 
899
- /**
900
- * Universal read by namespaced key.
901
- * @method get
902
- * @param {string} key Namespaced key, e.g. 'mqtt::home/sensor/temp' or 'var::myVar'
903
- * @returns {*} current value, or undefined
904
- */
905
- get: function Sandbox_she_get(key) {
906
- if (key.startsWith('var::')) {
907
- return store.get('var::' + key.slice(5));
908
- }
909
- return store.get(key);
910
- },
911
-
912
- /**
913
- * Universal read (full state object) by namespaced key.
914
- * @method getObject
915
- * @param {string} key
916
- * @returns {{ val:*, ts:number, lc:number } | undefined}
917
- */
918
- getObject: function Sandbox_she_getObject(key) {
919
- if (key.startsWith('var::')) {
920
- return store.getObject('var::' + key.slice(5));
921
- }
922
- return store.getObject(key);
923
- },
924
-
925
900
  /**
926
901
  * Universal subscribe by namespaced key.
927
902
  * Callback receives (val, obj, prevObj).
@@ -958,34 +933,6 @@ function runScript(script, name, _origin) {
958
933
  throw new TypeError('she.on: unknown namespace in key: ' + key);
959
934
  }
960
935
  },
961
-
962
- /**
963
- * Universal write by namespaced key.
964
- * @method set
965
- * @param {string} key Namespaced key: 'mqtt::topic', 'var::name'
966
- * @param {*} val
967
- */
968
- set: function Sandbox_she_set(key, val) {
969
- if (typeof key !== 'string') throw new TypeError('she.set: key must be a string');
970
-
971
- if (key.startsWith('mqtt::')) {
972
- she.mqttpub(key.slice(6), val);
973
- } else if (key.startsWith('var::')) {
974
- setVariable(key.slice(5), val);
975
- } else if (key.startsWith('matter::')) {
976
- throw new Error('she.set: matter:: write not yet implemented');
977
- } else {
978
- throw new TypeError('she.set: unknown namespace in key: ' + key);
979
- }
980
- },
981
-
982
- /** @internal Register a callback for MQTT connection lifecycle events. */
983
- _registerMqttEvent: function Sandbox_she_registerMqttEvent(event, callback) {
984
- if (event !== 'connect' && event !== 'disconnect') {
985
- throw new TypeError('she.mqtt.on: unknown event "' + event + '" — use "connect" or "disconnect"');
986
- }
987
- mqttEventCallbacks.push({ event, callback: scriptDomain.bind(callback), _script: name });
988
- },
989
936
  };
990
937
 
991
938
  // she.log is an alias for she.info
@@ -1146,6 +1093,7 @@ function loadScript(file, origin) {
1146
1093
  if (scripts[file]) {
1147
1094
  scriptOrigins.set(file, origin);
1148
1095
  runScript(scripts[file], file, origin);
1096
+ broadcast({ type: 'script:running', path: makeLabel(file).slice(0, -1), running: true });
1149
1097
  }
1150
1098
  }
1151
1099
  });
@@ -1234,6 +1182,7 @@ function unloadScript(file) {
1234
1182
 
1235
1183
  // Remove from scripts map so it can be re-loaded
1236
1184
  delete scripts[file];
1185
+ broadcast({ type: 'script:running', path: makeLabel(file).slice(0, -1), running: false });
1237
1186
  }
1238
1187
 
1239
1188
  function loadBuiltinsDir(callback) {
@@ -32,8 +32,6 @@ module.exports = function (she, ctx = {}) {
32
32
  pub: (...args) => she.mqttpub(...args),
33
33
  /** Get the last-known value for a topic. */
34
34
  get: (topic) => she.getValue(topic),
35
- /** Set a value on one or more topics. */
36
- set: (topic, val) => she.setValue(topic, val),
37
35
  /** Get a specific property from a topic's state object. */
38
36
  getProp: (...args) => she.getProp(...args),
39
37
  /** Forward value changes from source topic(s) to target topic(s). */
@@ -51,8 +49,6 @@ module.exports = function (she, ctx = {}) {
51
49
  age: function Sandbox_mqtt_age(topic) {
52
50
  return Math.round((new Date().getTime() - she.getProp(topic, 'lc')) / 1000);
53
51
  },
54
- /** Register a callback for MQTT connection lifecycle events ('connect' or 'disconnect'). */
55
- on: (event, cb) => she._registerMqttEvent(event, cb),
56
52
  /**
57
53
  * Publish 1 to target when any source is truthy, 0 otherwise.
58
54
  * target may be a topic string or a callback(topic, val).
@@ -13,10 +13,8 @@ she.mqtt.sub(topic, [opts], cb) Subscribe; wildcards: + (1 level) # (mult
13
13
  opts.change: true = only fire when value changes
14
14
  she.mqtt.pub(topic, payload, [opts]) Publish; opts: { qos, retain }
15
15
  she.mqtt.get(topic) Current retained value (sync)
16
- she.mqtt.set(topic, val) Publish as retained
17
16
  she.mqtt.link(src, target, [fn]) Forward src changes to target; optional transform
18
17
  she.mqtt.age(topic) Seconds since topic last received a message
19
- she.mqtt.on('connect'|'disconnect', cb) MQTT lifecycle events
20
18
  ```
21
19
 
22
20
  ### Scheduling
@@ -29,14 +27,6 @@ she.schedule(pattern, [opts], cb)
29
27
  opts.random: max random delay in seconds added to the trigger time
30
28
  ```
31
29
 
32
- ### Universal key-value API
33
- ```
34
- she.on(key, cb) Subscribe. Key prefixes: mqtt:: var:: matter::
35
- she.set(key, val) Set value (mqtt:: or var:: namespaces)
36
- she.get(key) Current value
37
- she.getObject(key) Current { val, ts, lc } state object
38
- ```
39
-
40
30
  ### Variable system (var:: namespace)
41
31
  Topics prefixed with "var" (default) are persisted as retained MQTT messages
42
32
  and available across scripts via she.get('var::name') / she.set('var::name', v).
@@ -1,3 +0,0 @@
1
- 'use strict';
2
-
3
- she.info('ready');