Skip to content

Commit

Permalink
0.0.1 version
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Critelli committed Jan 24, 2016
1 parent c426ee4 commit 8167d86
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 38 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
}
Expand Down
41 changes: 15 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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, {});
Expand All @@ -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();
}

},
Expand All @@ -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];
}
};
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions sample-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down

0 comments on commit 8167d86

Please sign in to comment.