Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit cd2ee2d

Browse files
Pierre Mkarbassi
authored andcommitted
Added gethomecoachsdata API call (#28)
1 parent 063b961 commit cd2ee2d

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

netatmo.js

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ netatmo.prototype.authenticate = function (args, callback) {
9393
password = args.password;
9494
client_id = args.client_id;
9595
client_secret = args.client_secret;
96-
scope = args.scope || 'read_station read_thermostat write_thermostat read_camera';
96+
scope = args.scope || 'read_station read_thermostat write_thermostat read_camera read_homecoach';
9797

9898
var form = {
9999
client_id: client_id,
@@ -866,4 +866,53 @@ netatmo.prototype.getCameraPicture = function (options, callback) {
866866
return this;
867867
};
868868

869+
/**
870+
* https://dev.netatmo.com/dev/resources/technical/reference/healthyhomecoach/gethomecoachsdata
871+
* @param options
872+
* @param callback
873+
* @returns {*}
874+
*/
875+
netatmo.prototype.getHealthyHomeCoachData = function (options, callback) {
876+
// Wait until authenticated.
877+
if (!access_token) {
878+
return this.on('authenticated', function () {
879+
this.getHealthyHomeCoachData(options, callback);
880+
});
881+
}
882+
883+
if (options != null && callback == null) {
884+
callback = options;
885+
options = null;
886+
}
887+
888+
var url = util.format('%s/api/gethomecoachsdata?access_token=%s', BASE_URL, access_token);
889+
if (options != null) {
890+
url = util.format(url + '&device_id=%s', options.device_id);
891+
}
892+
893+
request({
894+
url: url,
895+
method: "GET",
896+
}, function (err, response, body) {
897+
if (err || response.statusCode != 200) {
898+
return this.handleRequestError(err, response, body, "getHealthyHomeCoachData error");
899+
}
900+
901+
body = JSON.parse(body);
902+
903+
var devices = body.body.devices;
904+
905+
this.emit('get-healthhomecoaches-data', err, devices);
906+
907+
if (callback) {
908+
return callback(err, devices);
909+
}
910+
911+
return this;
912+
913+
}.bind(this));
914+
915+
return this;
916+
};
917+
869918
module.exports = netatmo;

test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,12 @@ var options = {
247247
};
248248

249249
api.getCameraPicture(options);
250+
251+
// Get Healthy Home Coach Data
252+
// See docs: https://dev.netatmo.com/dev/resources/technical/reference/healthyhomecoach/gethomecoachsdata
253+
var options = {
254+
device_id: '',
255+
};
256+
257+
api.getHealthyHomeCoachData(options);
258+

0 commit comments

Comments
 (0)