diff --git a/README.md b/README.md new file mode 100644 index 0000000..871d51c --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# Little Warmth for homebridge + +Get temperature from a command, and present it as a temperature for the cosy +bedroom + +## example config + +```json +"accessories": [ + { + "accessory": "LittleWarmth", + "name": "Little Warmth", + "command": "/bin/get_temperature" + } +], +``` diff --git a/index.js b/index.js new file mode 100644 index 0000000..b1301c1 --- /dev/null +++ b/index.js @@ -0,0 +1,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] + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..44f3988 --- /dev/null +++ b/package.json @@ -0,0 +1,21 @@ +{ + "name": "homebridge-little-warmth", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://git.snoot.club/chee/homebridge-little-warmth.git" + }, + "engines": { + "homebridge": "*" + }, + "author": "chee ", + "license": "GPL-3.0", + "keywords": [ + "homebridge-plugin" + ] +}