forked from llun/homebridge-sensibo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (38 loc) · 1.29 KB
/
index.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
const Api = require('./lib/sensiboapi')
const pods = require('./accessories/pods')
module.exports = homebridge => {
const { Service, Characteristic, Accessory, uuid } = homebridge.hap
const SensiboPodAccessory = pods(Accessory, Service, Characteristic, uuid)
class SensiboPlatform {
constructor (log, config) {
this.api = new Api(config.apiKey)
this.log = log
this.debug = log.debug
this.devices = []
this.config = config
}
reloadData (callback) {
this.debug('Refreshing Sensibo Data')
this.devices.forEach(device => device.loadData())
}
refresh () {
setInterval(() => this.reloadData(), 40000)
}
accessories (callback) {
this.log('Fetching Sensibo devices...')
this.devices = []
this.api.getPods().then(pods => {
pods.forEach(pod => {
const accessory = new SensiboPodAccessory(this, pod)
if (accessory) {
this.log(`Device Added (Name: ${accessory.name}, ID: ${accessory.device.id}, Group: ${accessory.deviceGroup})`)
this.devices.push(accessory)
}
})
this.refresh()
callback(this.devices)
}).catch(error => { console.error(error) })
}
}
homebridge.registerPlatform('homebridge-sensibo', 'Sensibo', SensiboPlatform)
}