Skip to content

Commit

Permalink
Added an option to disable reporting of humidity
Browse files Browse the repository at this point in the history
  • Loading branch information
DanTheMan827 committed Jun 15, 2016
1 parent 8ce14ba commit bf4d51e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
30 changes: 20 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function HttpTemphum(log, config) {
this.manufacturer = config["manufacturer"] || "Luca Manufacturer";
this.model = config["model"] || "Luca Model";
this.serial = config["serial"] || "Luca Serial";
this.humidity = config["humidity"];
}

HttpTemphum.prototype = {
Expand Down Expand Up @@ -57,13 +58,15 @@ HttpTemphum.prototype = {
var info = JSON.parse(res.body);

temperatureService.setCharacteristic(Characteristic.CurrentTemperature, info.temperature);
humidityService.setCharacteristic(Characteristic.CurrentRelativeHumidity, info.humidity);
if(this.humidity !== false)
humidityService.setCharacteristic(Characteristic.CurrentRelativeHumidity, info.humidity);

this.log(res.body);
this.log(info);

this.temperature = info.temperature;
this.humidity = info.humidity;
if(this.humidity !== false)
this.humidity = info.humidity;

callback(null, this.temperature);
}
Expand All @@ -75,22 +78,29 @@ HttpTemphum.prototype = {
},

getServices: function () {
var informationService = new Service.AccessoryInformation();
var services = [],
informationService = new Service.AccessoryInformation();

informationService
.setCharacteristic(Characteristic.Manufacturer, this.manufacturer)
.setCharacteristic(Characteristic.Model, this.model)
.setCharacteristic(Characteristic.SerialNumber, this.serial);
services.push(informationService);

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));

return [informationService, temperatureService, humidityService];
services.push(temperatureService);

if(this.humidity !== false){
humidityService = new Service.HumiditySensor(this.name);
humidityService
.getCharacteristic(Characteristic.CurrentRelativeHumidity)
.on('get', this.getStateHumidity.bind(this));
services.push(humidityService);
}

return services;
}
};
3 changes: 2 additions & 1 deletion sample-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"accessory": "HttpTemphum",
"name": "Living Room Weather",
"url": "http://192.168.1.210/weather",
"http_method": "GET"
"http_method": "GET",
"humidity": true
}
]
}

0 comments on commit bf4d51e

Please sign in to comment.