-
Notifications
You must be signed in to change notification settings - Fork 14
/
imageHelper.js
41 lines (39 loc) · 1.68 KB
/
imageHelper.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
38
39
40
41
//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:'imageHelper', type:LOG_TYPE.INFO, content:'', deviceId: null };
let myMessage = {...initMessage, ...message}
return metaMessage (myMessage);
}
class imageHelper {
constructor(deviceId, name, variableListened, controller) {
this.name = name;
this.deviceId = deviceId;
this.variableListened = variableListened;
this.value = '';
this.controller = controller;
var self = this;
this.get = function (deviceId) {
return new Promise(function (resolve, reject) {
resolve(self.value);
})
};
this.update = function (deviceId, theValue) {
return new Promise(function (resolve, reject) {
if (self.value != theValue) {
self.value = theValue;
self.controller.sendComponentUpdate({ uniqueDeviceId: deviceId, component: self.name, value: self.value})
.catch((err) => { metaLog({type:LOG_TYPE.ERROR, content:err, deviceId:deviceId})});
}
resolve();
});
};
this.initialise = function (deviceId) {
metaLog({type:LOG_TYPE.VERBOSE, content:"Initialise imageHelper", deviceId:deviceId})
self.controller.vault.addObserver(self.variableListened, self.update, deviceId, self.name);
}
}
}
exports.imageHelper = imageHelper;