From 703681f1f0910822251308e3df96c7304a6b7a38 Mon Sep 17 00:00:00 2001 From: chee Date: Sat, 5 Oct 2019 21:54:56 +0100 Subject: [PATCH] Initial commit --- README.md | 16 ++++++++++++++++ index.js | 36 ++++++++++++++++++++++++++++++++++++ package.json | 21 +++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 README.md create mode 100644 index.js create mode 100644 package.json 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" + ] +}