-
Notifications
You must be signed in to change notification settings - Fork 0
/
temps.js
34 lines (32 loc) · 838 Bytes
/
temps.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
let huejay = require("huejay")
const { logger } = require("./logging")
function pollSensors(client, callback) {
client.sensors
.getAll()
.then(sensors => {
for (let sensor of sensors) {
if (sensor.type == "ZLLTemperature" || sensor.type == "ZLLLightLevel") {
callback(sensor)
}
}
})
.catch(error => {
logger.error(error.stack)
})
}
exports.startPollingSensors = function(username, callback) {
huejay
.discover()
.then(bridges => {
let bridge = bridges[0]
logger.info("Using Hue bridge " + bridge.ip)
client = new huejay.Client({
host: bridge.ip,
username
})
setInterval(() => pollSensors(client, callback), 10 * 1000)
})
.catch(error => {
logger.error(`An error occurred: ${error.message}`)
})
}