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

Commit

Permalink
Added setPersonAway API call (resolve #52) (#67)
Browse files Browse the repository at this point in the history
Co-authored-by: Boris MANCHETTE <borismanchette@sfr.fr>
  • Loading branch information
sadmin91 and Boris MANCHETTE authored Nov 17, 2020
1 parent d028e66 commit 7d6d06c
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion netatmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ netatmo.prototype.authenticate = function (args, callback) {
password = args.password;
client_id = args.client_id;
client_secret = args.client_secret;
scope = args.scope || 'read_station read_thermostat write_thermostat read_camera read_homecoach';
scope = args.scope || 'read_station read_thermostat write_thermostat read_camera write_camera read_homecoach';

var form = {
client_id: client_id,
Expand Down Expand Up @@ -1364,4 +1364,63 @@ netatmo.prototype.setRoomThermPoint = function (options, callback) {
return this;
};

/**
* https://dev.netatmo.com/apidocumentation/security#setpersonsaway
* @param options
* @param callback
* @returns {*}
*/
netatmo.prototype.setPersonAway = function (options, callback) {
// Wait until authenticated.
if (!access_token) {
return this.on('authenticated', function () {
this.setPersonAway(options, callback);
});
}

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

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

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

var form = {
access_token: access_token,
home_id: options.home_id,
};

if (options.person_id) {
form.person_id = options.person_id;
}

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

body = JSON.parse(body);

this.emit('set-personsaway', err, body);

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

return this;

}.bind(this));

return this;
};

module.exports = netatmo;

0 comments on commit 7d6d06c

Please sign in to comment.