signalk-automation-plugin 0.0.6 → 0.0.8

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.
package/lib/engine.js CHANGED
@@ -579,7 +579,7 @@ async function runAction (action, ctx) {
579
579
  }
580
580
  if (action.delay != null) {
581
581
  const ms = parseDuration(action.delay)
582
- if (ctx.skipDelay) return { ok: true, type: 'delay', ms, skipped: true, stop: true }
582
+ if (ctx.skipDelay) return { ok: true, type: 'delay', ms, skipped: true }
583
583
  try {
584
584
  await ctx.sleep(ms)
585
585
  } catch (err) {
package/lib/runtime.js CHANGED
@@ -21,6 +21,7 @@ class Runtime {
21
21
  this.sleep = opts.sleep || ((ms) => new Promise((r) => setTimeout(r, ms)))
22
22
  this.putFn = opts.put
23
23
  this.notifyFn = opts.notify
24
+ this.onHelper = opts.onHelper || null
24
25
  this.log = opts.log || { debug () {}, error () {} }
25
26
 
26
27
  this.doc = yaml.emptyDoc()
@@ -90,11 +91,20 @@ class Runtime {
90
91
  to: coerced,
91
92
  changed: true
92
93
  })
94
+ this.emitHelperValue(id, coerced)
93
95
  if (!opts || opts.kick !== false) {
94
96
  await this.kickPath(helpers.helperPath(id), coerced)
95
97
  }
96
98
  }
97
- return coerced
99
+ const current = Object.prototype.hasOwnProperty.call(this.helperValues, id)
100
+ ? this.helperValues[id]
101
+ : coerced
102
+ if (!engine.sameValue(current, coerced)) this.emitHelperValue(id, current)
103
+ return current
104
+ }
105
+
106
+ emitHelperValue (id, value) {
107
+ if (typeof this.onHelper === 'function') this.onHelper(id, value)
98
108
  }
99
109
 
100
110
  async resetHelper (id) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "signalk-automation-plugin",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "Home Assistant-like YAML automations for Signal K",
5
5
  "main": "plugin/index.js",
6
6
  "keywords": [
package/plugin/index.js CHANGED
@@ -426,6 +426,7 @@ module.exports = function (app) {
426
426
  scriptTimeoutSeconds: options.scriptTimeoutSeconds,
427
427
  put: putPath,
428
428
  notify,
429
+ onHelper: (id, value) => emitHelper(id, value),
429
430
  log: {
430
431
  debug: app.debug ? app.debug.bind(app) : () => {},
431
432
  error: app.error ? app.error.bind(app) : console.error,
@@ -461,7 +462,10 @@ module.exports = function (app) {
461
462
  app.registerPutHandler('vessels.self', helpers.helperPath(id), (context, p, v, cb) => {
462
463
  Promise.resolve(runtime.setHelper(id, v))
463
464
  .then((next) => {
464
- emitHelper(id, next)
465
+ const live = Object.prototype.hasOwnProperty.call(runtime.helperValues, id)
466
+ ? runtime.helperValues[id]
467
+ : next
468
+ emitHelper(id, live)
465
469
  if (cb) cb({ state: 'COMPLETED' })
466
470
  })
467
471
  .catch((err) => {