diff --git a/README.md b/README.md index 7eaf95c..bedd7f2 100755 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# homebridge-http-temperature-humidity +# homebridge-http-simple-switch Supports https devices on HomeBridge Platform # Installation 1. Install homebridge using: npm install -g homebridge -2. Install this plugin using: npm install -g homebridge-httptemperaturehumidity +2. Install this plugin using: npm install -g homebridge-http-simple-switch 3. Update your configuration file. See sample-config.json in this repository for a sample. # Configuration @@ -18,9 +18,10 @@ Configuration sample: "accessories": [ "accessories": [ { - "accessory": "HttpTempHum", - "name": "Living Room Weather", - "url": "http://192.168.1.210/weather", + "accessory": "SimpleHttpSwitch", + "name": "Living Room Button", + "url": "http://192.168.1.210/button", + "default_state_off": true, "sendimmediately": "", "http_method": "GET" } diff --git a/index.js b/index.js index d3ffc69..52eef96 100755 --- a/index.js +++ b/index.js @@ -1,30 +1,27 @@ var Service, Characteristic; var request = require('sync-request'); -var temperatureService; -var humidityService; var url -var humidity = 0; -var temperature = 0; module.exports = function (homebridge) { Service = homebridge.hap.Service; Characteristic = homebridge.hap.Characteristic; - homebridge.registerAccessory("homebridge-httptemperaturehumidity", "HttpTemphum", HttpTemphum); + homebridge.registerAccessory("homebridge-http-simple-switch", "SimpleHttpSwitch", SimpleHttpSwitch); } -function HttpTemphum(log, config) { +function SimpleHttpSwitch(log, config) { this.log = log; // url info this.url = config["url"]; this.http_method = config["http_method"]; this.sendimmediately = config["sendimmediately"]; + this.default_state_off = config["default_state_off"]; this.name = config["name"]; } -HttpTemphum.prototype = { +SimpleHttpSwitch.prototype = { httpRequest: function (url, body, method, username, password, sendimmediately, callback) { request({ @@ -38,11 +35,11 @@ HttpTemphum.prototype = { }) }, - getStateHumidity: function(callback){ - callback(null, this.humidity); + getPowerState: function (callback) { + callback(null, !this.default_state_off); }, - getState: function (callback) { + setPowerState: function(powerOn, callback) { var body; var res = request(this.http_method, this.url, {}); @@ -52,14 +49,9 @@ HttpTemphum.prototype = { }else{ this.log('HTTP power function succeeded!'); var info = JSON.parse(res.body); - - temperatureService.setCharacteristic(Characteristic.CurrentTemperature, info.temperature); - humidityService.setCharacteristic(Characteristic.CurrentRelativeHumidity, info.humidity); - this.log(res.body); this.log(info); - this.temperature = info.temperature; - callback(null, this.temperature); + callback(); } }, @@ -77,16 +69,13 @@ HttpTemphum.prototype = { .setCharacteristic(Characteristic.Model, "Luca Model") .setCharacteristic(Characteristic.SerialNumber, "Luca Serial Number"); - temperatureService = new Service.TemperatureSensor(this.name); - temperatureService - .getCharacteristic(Characteristic.CurrentTemperature) - .on('get', this.getState.bind(this)); - - humidityService = new Service.HumiditySensor(this.name); - humidityService - .getCharacteristic(Characteristic.CurrentRelativeHumidity) - .on('get', this.getStateHumidity.bind(this)); + switchService = new Service.Switch(this.name); + switchService + .getCharacteristic(Characteristic.On) + .on('get', this.getPowerState.bind(this)) + .on('set', this.setPowerState.bind(this)); - return [temperatureService, humidityService]; + + return [switchService]; } }; \ No newline at end of file diff --git a/package.json b/package.json index 6c7fe34..52bf77d 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "homebridge-httptemperaturehumidity", - "version": "0.0.10", - "description": "https plugin for homebridge", + "name": "homebridge-http-simple-switch", + "version": "0.0.1", + "description": "http plugin for homebridge", "license": "ISC", "keywords": [ "homebridge-plugin" @@ -15,7 +15,7 @@ }, "repository": { "type": "git", - "url": "git://github.com/lucacri/homebridge-http-temperature-humidity.git" + "url": "git://github.com/lucacri/homebridge-http-simple-switch.git" }, "dependencies": { "sync-request": "^2.1.0" diff --git a/sample-config.json b/sample-config.json index 20f8a5c..3658cc3 100755 --- a/sample-config.json +++ b/sample-config.json @@ -12,9 +12,10 @@ "accessories": [ { - "accessory": "HttpTemphum", - "name": "Living Room Weather", - "url": "http://192.168.1.210/weather", + "accessory": "SimpleHttpSwitch", + "name": "Living Room Button", + "url": "http://192.168.1.210/button", + "default_state_off": true, "sendimmediately": "", "http_method": "GET" }