-
Notifications
You must be signed in to change notification settings - Fork 14
/
sensorHelper.js
37 lines (35 loc) · 1.48 KB
/
sensorHelper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//LOGGING SETUP AND WRAPPING
//Disable the NEEO library console warning.
const { metaMessage, LOG_TYPE } = require("./metaMessage");
console.error = console.info = console.debug = console.warn = console.trace = console.dir = console.dirxml = console.group = console.groupEnd = console.time = console.timeEnd = console.assert = console.profile = function() {};
function metaLog(message) {
let initMessage = { component:'sensorHelper', type:LOG_TYPE.INFO, content:'', deviceId: null };
let myMessage = {...initMessage, ...message}
return metaMessage (myMessage);
}
class sensorHelper {
constructor(deviceId, name, variableListened, controller) {
this.name = name;
this.deviceId = deviceId;
this.variableListened = variableListened;
this.value = '';
var self = this;
this.get = function (deviceId) {
return self.value;
}
this.update = function (deviceId, theValue) {
return new Promise(function (resolve, reject) {
if (self.value != theValue) {
self.value = theValue;
controller.sendComponentUpdate({ uniqueDeviceId: deviceId, component: self.name, value: theValue })
.catch((err) => {metaLog({type:LOG_TYPE.ERROR, content:err, deviceId:deviceId})});
}
resolve();
});
};
this.initialise = function (deviceId) {
controller.vault.addObserver(self.variableListened, self.update, deviceId, self.name);
}
}
}
exports.sensorHelper = sensorHelper;