-
Notifications
You must be signed in to change notification settings - Fork 0
/
bmp183-scout.js
50 lines (38 loc) · 1.09 KB
/
bmp183-scout.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
42
43
44
45
46
47
48
49
50
const config = require('./config');
const Scout = require(process.lynxari.scout);
const Bmp183 = require('./bmp183');
module.exports = class Bmp183Scout extends Scout {
constructor(opts) {
super();
if (typeof opts !== 'undefined') {
// copy all config options defined in the server
for (const key in opts) {
if (typeof opts[key] !== 'undefined') {
config[key] = opts[key];
}
}
}
if (config.name === undefined) { config.name = "BMP183" }
this.name = config.name;
this.bmp183 = new Bmp183(config);
}
init(next) {
const query = this.server.where({name: this.name});
const self = this;
this.server.find(query, function(err, results) {
if (!err) {
if (results[0]) {
self.provision(results[0], self.bmp183);
self.server.info('Provisioned known device ' + self.name);
} else {
self.discover(self.bmp183);
self.server.info('Discovered new device ' + self.name);
}
}
else {
self.server.error(err);
}
});
next();
}
}