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

Commit

Permalink
Adds getHomesData and getHomeStatus. (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
luixal authored and karbassi committed Apr 23, 2019
1 parent 9dad577 commit f6633b7
Showing 1 changed file with 113 additions and 0 deletions.
113 changes: 113 additions & 0 deletions netatmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,119 @@ netatmo.prototype.getHomeData = function (options, callback) {
return this;
};

/**
* https://dev.netatmo.com/resources/technical/reference/energy/homesdata
* @param options
* @param callback
* @returns {*}
*/
netatmo.prototype.getHomesData = function (options, callback) {
// Wait until authenticated.
if (!access_token) {
return this.on('authenticated', function () {
this.getHomesData(options, callback);
});
}

var url = util.format('%s/api/homesdata', BASE_URL);

var form = {
access_token: access_token
};

if (options != null && callback == null) {
callback = options;
options = null;
}

if (options) {
if (options.home_id) form.home_id = options.home_id;
if (options.gateway_types) form.gateway_types = options.gateway_types;
}

request({
url: url,
method: "POST",
form: form,
}, function (err, response, body) {
if (err || response.statusCode != 200) {
return this.handleRequestError(err, response, body, "getHomesData error");
}

body = JSON.parse(body);

this.emit('get-homesdata', err, body.body);

if (callback) {
return callback(err, body.body);
}

return this;

}.bind(this));

return this;
};

/**
* https://dev.netatmo.com/resources/technical/reference/energy/homestatus
* @param options
* @param callback
* @returns {*}
*/
netatmo.prototype.getHomeStatus = function (options, callback) {
// Wait until authenticated.
if (!access_token) {
return this.on('authenticated', function () {
this.getHomeStatus(options, callback);
});
}

if (!options.home_id) {
this.emit("error", new Error("getHomeStatus 'home_id' not set."));
return this;
}

var url = util.format('%s/api/homestatus', BASE_URL);

var form = {
access_token: access_token
};

if (options != null && callback == null) {
callback = options;
options = null;
}

if (options) {
if (options.home_id) form.home_id = options.home_id;
if (options.device_types) form.device_types = options.device_types;
}

request({
url: url,
method: "POST",
form: form,
}, function (err, response, body) {
if (err || response.statusCode != 200) {
return this.handleRequestError(err, response, body, "getHomeStatus error");
}

body = JSON.parse(body);

this.emit('get-homestatus', err, body.body);

if (callback) {
return callback(err, body.body);
}

return this;

}.bind(this));

return this;
};

/**
* https://dev.netatmo.com/dev/resources/technical/reference/welcome/getnextevents
* @param options
Expand Down

0 comments on commit f6633b7

Please sign in to comment.