remoterigs-raspberrypi 0.1.9 → 0.1.10

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "remoterigs-raspberrypi",
3
3
  "type": "module",
4
- "version": "0.1.9",
4
+ "version": "0.1.10",
5
5
  "main": "./index.js",
6
6
  "files": [
7
7
  "index.js",
@@ -61,6 +61,7 @@ export default class Component {
61
61
  }
62
62
  this.Log("status: '" + this.component.status[i].name.toLowerCase() + "'");
63
63
  }
64
+ this.LoadStoredStatuses();
64
65
  for (var i = 0; i < this.component.codeBlocks.length; i++) {
65
66
  if (this.component.codeBlocks[i].type == CodeBlockType.Function) {
66
67
  try {
@@ -232,6 +233,29 @@ export default class Component {
232
233
  }
233
234
  }
234
235
  }
236
+ LoadStoredStatuses() {
237
+ var componentStatuses = this.rig.rig.componentStatuses;
238
+ if (componentStatuses == undefined) {
239
+ return;
240
+ }
241
+ for (const key in this.status) {
242
+ var status = this.status[key];
243
+ if (!status.IsStored()) {
244
+ continue;
245
+ }
246
+ for (var i = 0; i < componentStatuses.length; i++) {
247
+ var stored = componentStatuses[i].value;
248
+ if (stored != undefined &&
249
+ stored.componentId == this.component.id &&
250
+ stored.statusId == status.GetStatusId() &&
251
+ stored.value != undefined && stored.value != null) {
252
+ status.LoadStoredValue(stored.value);
253
+ this.Log("stored status loaded: '" + key + "' = " + stored.value + (stored.valueStr ? " (" + stored.valueStr + ")" : ""));
254
+ break;
255
+ }
256
+ }
257
+ }
258
+ }
235
259
  SetCallback(callback) {
236
260
  this.callback = callback;
237
261
  }
@@ -262,7 +286,7 @@ export default class Component {
262
286
  }
263
287
  GetStatusState(status) {
264
288
  if (this.status.hasOwnProperty(status.toLowerCase())) {
265
- this.status[status.toLowerCase()].GetValueStr();
289
+ return this.status[status.toLowerCase()].GetValueStr();
266
290
  }
267
291
  return "";
268
292
  }
@@ -13,6 +13,19 @@ export default class Status {
13
13
  this.SendUpdateStatus(value);
14
14
  }
15
15
  }
16
+ /**
17
+ * Restore the last value stored on the server (only for statuses with 'store' enabled).
18
+ * Does not send an update; SendCurrent() will report it to the server.
19
+ */
20
+ LoadStoredValue(value) {
21
+ this.last_value = value;
22
+ }
23
+ IsStored() {
24
+ return this.status.store == true;
25
+ }
26
+ GetStatusId() {
27
+ return this.status.id;
28
+ }
16
29
  SendCurrent() {
17
30
  if (this.last_value != null) {
18
31
  this.SendUpdateStatus(this.last_value);
@@ -29,6 +29,7 @@ export class ComponentStatusViewModel {
29
29
  this.componentId = _data["componentId"];
30
30
  this.name = _data["name"];
31
31
  this.type = _data["type"];
32
+ this.store = _data["store"];
32
33
  if (Array.isArray(_data["states"])) {
33
34
  this.states = [];
34
35
  for (let item of _data["states"])
@@ -48,6 +49,7 @@ export class ComponentStatusViewModel {
48
49
  data["componentId"] = this.componentId;
49
50
  data["name"] = this.name;
50
51
  data["type"] = this.type;
52
+ data["store"] = this.store;
51
53
  if (Array.isArray(this.states)) {
52
54
  data["states"] = [];
53
55
  for (let item of this.states)
@@ -308,6 +310,7 @@ export class RigClientViewModel {
308
310
  if (!data) {
309
311
  this.rigModelViewModel = new RigModelViewModel();
310
312
  this.logSettings = [];
313
+ this.componentStatuses = [];
311
314
  }
312
315
  }
313
316
  init(_data) {
@@ -323,6 +326,11 @@ export class RigClientViewModel {
323
326
  for (let item of _data["logSettings"])
324
327
  this.logSettings.push(LogSettingViewModel.fromJS(item));
325
328
  }
329
+ if (Array.isArray(_data["componentStatuses"])) {
330
+ this.componentStatuses = [];
331
+ for (let item of _data["componentStatuses"])
332
+ this.componentStatuses.push(StatusModel.fromJS(item));
333
+ }
326
334
  }
327
335
  }
328
336
  static fromJS(data) {
@@ -344,6 +352,11 @@ export class RigClientViewModel {
344
352
  for (let item of this.logSettings)
345
353
  data["logSettings"].push(item ? item.toJSON() : undefined);
346
354
  }
355
+ if (Array.isArray(this.componentStatuses)) {
356
+ data["componentStatuses"] = [];
357
+ for (let item of this.componentStatuses)
358
+ data["componentStatuses"].push(item ? item.toJSON() : undefined);
359
+ }
347
360
  return data;
348
361
  }
349
362
  }