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

Commit 9170487

Browse files
committed
Merge pull request #18 from SeraphimSerapis/welcome
Adds support for Netatmo Welcome camera
2 parents d2de174 + 3eabb8c commit 9170487

File tree

3 files changed

+374
-1
lines changed

3 files changed

+374
-1
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,25 @@ var options = {
125125
api.setThermpoint(options, function(err, status) {
126126
console.log(status);
127127
});
128+
129+
130+
// Get Home Data
131+
// See docs: https://dev.netatmo.com/doc/methods/gethomedata
132+
api.getHomeData(function(err, data) {
133+
console.log(data);
134+
});
135+
136+
137+
// Get Next Events
138+
// See docs: https://dev.netatmo.com/doc/methods/getnextevents
139+
var options = {
140+
home_id: '',
141+
event_id: ''
142+
};
143+
144+
api.getNextEvents(options, function(err,events) {
145+
console.log(events);
146+
});
128147
```
129148

130149
Example #2
@@ -160,6 +179,10 @@ var getThermstate = function(err, result) {
160179
console.log(result);
161180
};
162181

182+
var getCameraPicture = function(err, picture) {
183+
console.log(picture); // image/jpeg
184+
}
185+
163186
var setSyncSchedule = function(err, status) {
164187
console.log(status);
165188
};
@@ -173,6 +196,7 @@ api.on('get-user', getUser);
173196
api.on('get-devicelist', getDevicelist);
174197
api.on('get-measure', getMeasure);
175198
api.on('get-thermstate', getThermstate);
199+
api.on('get-camerapicture', getCameraPicture);
176200
api.on('set-syncschedule', setSyncSchedule);
177201
api.on('set-thermpoint', setThermpoint);
178202

netatmo.js

Lines changed: 314 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';
96+
scope = args.scope || 'read_station read_thermostat write_thermostat read_camera';
9797

9898
var form = {
9999
client_id: client_id,
@@ -716,4 +716,317 @@ netatmo.prototype.setThermpoint = function (options, callback) {
716716
return this;
717717
};
718718

719+
/**
720+
* https://dev.netatmo.com/doc/methods/gethomedata
721+
* @param options
722+
* @param callback
723+
* @returns {*}
724+
*/
725+
netatmo.prototype.getHomeData = function (options, callback) {
726+
// Wait until authenticated.
727+
if (!access_token) {
728+
return this.on('authenticated', function () {
729+
this.getHomeData(options, callback);
730+
});
731+
}
732+
733+
var url = util.format('%s/api/gethomedata', BASE_URL);
734+
735+
var form = {
736+
access_token: access_token
737+
};
738+
739+
if (options != null && callback == null) {
740+
callback = options;
741+
options = null;
742+
}
743+
744+
if (options) {
745+
746+
if (options.home_id) {
747+
form.home_id = options.home_id;
748+
}
749+
750+
if (options.size) {
751+
form.size = options.size;
752+
}
753+
754+
}
755+
756+
request({
757+
url: url,
758+
method: "POST",
759+
form: form,
760+
}, function (err, response, body) {
761+
if (err || response.statusCode != 200) {
762+
return this.handleRequestError(err, response, body, "getHomeData error");
763+
}
764+
765+
body = JSON.parse(body);
766+
767+
this.emit('get-homedata', err, body.body);
768+
769+
if (callback) {
770+
return callback(err, body.body);
771+
}
772+
773+
return this;
774+
775+
}.bind(this));
776+
777+
return this;
778+
};
779+
780+
/**
781+
* https://dev.netatmo.com/doc/methods/getnextevents
782+
* @param options
783+
* @param callback
784+
* @returns {*}
785+
*/
786+
netatmo.prototype.getNextEvents = function (options, callback) {
787+
// Wait until authenticated.
788+
if (!access_token) {
789+
return this.on('authenticated', function () {
790+
this.getNextEvents(options, callback);
791+
});
792+
}
793+
794+
if (!options) {
795+
this.emit("error", new Error("getNextEvents 'options' not set."));
796+
return this;
797+
}
798+
799+
if (!options.home_id) {
800+
this.emit("error", new Error("getNextEvents 'home_id' not set."));
801+
return this;
802+
}
803+
804+
if (!options.event_id) {
805+
this.emit("error", new Error("getNextEvents 'event_id' not set."));
806+
return this;
807+
}
808+
809+
var url = util.format('%s/api/getnextevents', BASE_URL);
810+
811+
var form = {
812+
access_token: access_token,
813+
home_id: options.home_id,
814+
event_id: options.event_id,
815+
};
816+
817+
if (options.size) {
818+
form.size = options.size;
819+
}
820+
821+
request({
822+
url: url,
823+
method: "POST",
824+
form: form,
825+
}, function (err, response, body) {
826+
if (err || response.statusCode != 200) {
827+
return this.handleRequestError(err, response, body, "getNextEvents error");
828+
}
829+
830+
body = JSON.parse(body);
831+
832+
this.emit('get-nextevents', err, body.body);
833+
834+
if (callback) {
835+
return callback(err, body.body);
836+
}
837+
838+
return this;
839+
840+
}.bind(this));
841+
842+
return this;
843+
};
844+
845+
/**
846+
* https://dev.netatmo.com/doc/methods/getlasteventof
847+
* @param options
848+
* @param callback
849+
* @returns {*}
850+
*/
851+
netatmo.prototype.getLastEventOf = function (options, callback) {
852+
// Wait until authenticated.
853+
if (!access_token) {
854+
return this.on('authenticated', function () {
855+
this.getLastEventOf(options, callback);
856+
});
857+
}
858+
859+
if (!options) {
860+
this.emit("error", new Error("getLastEventOf 'options' not set."));
861+
return this;
862+
}
863+
864+
if (!options.home_id) {
865+
this.emit("error", new Error("getLastEventOf 'home_id' not set."));
866+
return this;
867+
}
868+
869+
if (!options.person_id) {
870+
this.emit("error", new Error("getLastEventOf 'person_id' not set."));
871+
return this;
872+
}
873+
874+
var url = util.format('%s/api/getlasteventof', BASE_URL);
875+
876+
var form = {
877+
access_token: access_token,
878+
home_id: options.home_id,
879+
person_id: options.person_id,
880+
};
881+
882+
if (options.offset) {
883+
form.offset = options.offset;
884+
}
885+
886+
request({
887+
url: url,
888+
method: "POST",
889+
form: form,
890+
}, function (err, response, body) {
891+
if (err || response.statusCode != 200) {
892+
return this.handleRequestError(err, response, body, "getLastEventOf error");
893+
}
894+
895+
body = JSON.parse(body);
896+
897+
this.emit('get-lasteventof', err, body.body);
898+
899+
if (callback) {
900+
return callback(err, body.body);
901+
}
902+
903+
return this;
904+
905+
}.bind(this));
906+
907+
return this;
908+
};
909+
910+
/**
911+
* https://dev.netatmo.com/doc/methods/geteventsuntil
912+
* @param options
913+
* @param callback
914+
* @returns {*}
915+
*/
916+
netatmo.prototype.getEventsUntil = function (options, callback) {
917+
// Wait until authenticated.
918+
if (!access_token) {
919+
return this.on('authenticated', function () {
920+
this.getEventsUntil(options, callback);
921+
});
922+
}
923+
924+
if (!options) {
925+
this.emit("error", new Error("getEventsUntil 'options' not set."));
926+
return this;
927+
}
928+
929+
if (!options.home_id) {
930+
this.emit("error", new Error("getEventsUntil 'home_id' not set."));
931+
return this;
932+
}
933+
934+
if (!options.event_id) {
935+
this.emit("error", new Error("getEventsUntil 'event_id' not set."));
936+
return this;
937+
}
938+
939+
var url = util.format('%s/api/geteventsuntil', BASE_URL);
940+
941+
var form = {
942+
access_token: access_token,
943+
home_id: options.home_id,
944+
event_id: options.event_id,
945+
};
946+
947+
request({
948+
url: url,
949+
method: "POST",
950+
form: form,
951+
}, function (err, response, body) {
952+
if (err || response.statusCode != 200) {
953+
return this.handleRequestError(err, response, body, "getEventsUntil error");
954+
}
955+
956+
body = JSON.parse(body);
957+
958+
this.emit('get-eventsuntil', err, body.body);
959+
960+
if (callback) {
961+
return callback(err, body.body);
962+
}
963+
964+
return this;
965+
966+
}.bind(this));
967+
968+
return this;
969+
};
970+
971+
/**
972+
* https://dev.netatmo.com/doc/methods/getcamerapicture
973+
* @param options
974+
* @param callback
975+
* @returns {*}
976+
*/
977+
netatmo.prototype.getCameraPicture = function (options, callback) {
978+
// Wait until authenticated.
979+
if (!access_token) {
980+
return this.on('authenticated', function () {
981+
this.getCameraPicture(options, callback);
982+
});
983+
}
984+
985+
if (!options) {
986+
this.emit("error", new Error("getCameraPicture 'options' not set."));
987+
return this;
988+
}
989+
990+
if (!options.image_id) {
991+
this.emit("error", new Error("getCameraPicture 'image_id' not set."));
992+
return this;
993+
}
994+
995+
if (!options.key) {
996+
this.emit("error", new Error("getCameraPicture 'key' not set."));
997+
return this;
998+
}
999+
1000+
var url = util.format('%s/api/getcamerapicture', BASE_URL);
1001+
1002+
var qs = {
1003+
access_token: access_token,
1004+
image_id: options.image_id,
1005+
key: options.key,
1006+
};
1007+
1008+
request({
1009+
url: url,
1010+
method: "GET",
1011+
qs: qs,
1012+
encoding: null,
1013+
contentType: 'image/jpg'
1014+
}, function (err, response, body) {
1015+
if (err || response.statusCode != 200) {
1016+
return this.handleRequestError(err, response, body, "getCameraPicture error");
1017+
}
1018+
1019+
this.emit('get-camerapicture', err, body);
1020+
1021+
if (callback) {
1022+
return callback(err, body);
1023+
}
1024+
1025+
return this;
1026+
1027+
}.bind(this));
1028+
1029+
return this;
1030+
};
1031+
7191032
module.exports = netatmo;

0 commit comments

Comments
 (0)