Skip to content

Commit

Permalink
Merge commit '78e74981584d0f3732c3a3b601363396e23ccb73'
Browse files Browse the repository at this point in the history
* commit '78e74981584d0f3732c3a3b601363396e23ccb73':
  added configuration options to the information service
  • Loading branch information
Luca Critelli committed Apr 11, 2016
2 parents 15cd7e1 + 78e7498 commit 8ce14ba
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ function HttpTemphum(log, config) {

// url info
this.url = config["url"];
this.http_method = config["http_method"];
this.sendimmediately = config["sendimmediately"];
this.http_method = config["http_method"] || "GET";
this.sendimmediately = config["sendimmediately"] || "";
this.name = config["name"];
this.manufacturer = config["manufacturer"] || "Luca Manufacturer";
this.model = config["model"] || "Luca Model";
this.serial = config["serial"] || "Luca Serial";
}

HttpTemphum.prototype = {
Expand All @@ -39,30 +42,31 @@ HttpTemphum.prototype = {
},

getStateHumidity: function(callback){
callback(null, this.humidity);
callback(null, this.humidity);
},

getState: function (callback) {
var body;

var res = request(this.http_method, this.url, {});
if(res.statusCode > 400){
// this.log('HTTP power function failed');
callback(error);
}else{
// this.log('HTTP power function succeeded!');
var info = JSON.parse(res.body);
var res = request(this.http_method, this.url, {});
if(res.statusCode > 400){
this.log('HTTP power function failed');
callback(error);
} 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);
temperatureService.setCharacteristic(Characteristic.CurrentTemperature, info.temperature);
humidityService.setCharacteristic(Characteristic.CurrentRelativeHumidity, info.humidity);

// this.log(res.body);
// this.log(info);
this.temperature = Number( info.temperature );
this.humidity = Number( info.humidity );
callback(null, this.temperature);
}
this.log(res.body);
this.log(info);

this.temperature = info.temperature;
this.humidity = info.humidity;

callback(null, this.temperature);
}
},

identify: function (callback) {
Expand All @@ -72,26 +76,21 @@ HttpTemphum.prototype = {

getServices: function () {
var informationService = new Service.AccessoryInformation();

informationService
.setCharacteristic(Characteristic.Manufacturer, "Luca Manufacturer")
.setCharacteristic(Characteristic.Model, "Luca Model")
.setCharacteristic(Characteristic.SerialNumber, "Luca Serial Number");
.setCharacteristic(Characteristic.Manufacturer, this.manufacturer)
.setCharacteristic(Characteristic.Model, this.model)
.setCharacteristic(Characteristic.SerialNumber, this.serial);

temperatureService = new Service.TemperatureSensor(this.name);
temperatureService
.getCharacteristic(Characteristic.CurrentTemperature)
.setProps({
minValue: -100,
value: 10
})
.on('get', this.getState.bind(this));

humidityService = new Service.HumiditySensor(this.name);
humidityService
.getCharacteristic(Characteristic.CurrentRelativeHumidity)
.on('get', this.getStateHumidity.bind(this));

return [temperatureService, humidityService];
return [informationService, temperatureService, humidityService];
}
};

0 comments on commit 8ce14ba

Please sign in to comment.