/
index.js
36 lines (29 loc) · 860 Bytes
/
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
let readline = require("readline")
let {exec} = require("child_process")
let Service, Characteristic, HomebridgeAPI
module.exports = homebridge => {
Service = homebridge.hap.Service
Characteristic = homebridge.hap.Characteristic
homebridge.registerAccessory("homebridge-little-warmth", "LittleWarmth", LittleWarmth)
}
class LittleWarmth {
constructor (log, config) {
this.log = log
this.name = config.name || "Little Warmth"
this.command = config.command || "get_temperature"
this.service = new Service.TemperatureSensor(this.name)
this.service
.getCharacteristic(Characteristic.CurrentTemperature)
.on("get", this.getState.bind(this))
}
getState (callback) {
exec(this.command, (error, temp) => {
this.log(temp)
this.temp = Number(temp)
callback(error, this.temp)
})
}
getServices () {
return [this.service]
}
}