iobroker.netatmo
Advanced tools
Comparing version 1.2.2 to 1.3.0
{ | ||
"common": { | ||
"name": "netatmo", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"title": "Netatmo Adapter", | ||
@@ -31,2 +31,3 @@ "desc": { | ||
"netatmoWelcome": false, | ||
"netatmoCoach": false, | ||
"username": "", | ||
@@ -33,0 +34,0 @@ "password": "", |
24
main.js
@@ -11,2 +11,5 @@ /* jshint -W097 */// jshint strict:false | ||
var NetatmoCoach = require("./netatmoCoach"); | ||
var coach = null; | ||
var NetatmoStation = require("./netatmoStation"); | ||
@@ -76,4 +79,4 @@ var station = null; | ||
// If nothing is set, activate at least the Weatherstation | ||
if (!(adapter.config.netatmoWeather || adapter.config.netatmoWelcome)) { | ||
adapter.log.info("No product was choosen, using WeatherStation as default!"); | ||
if (!(adapter.config.netatmoCoach || adapter.config.netatmoWeather || adapter.config.netatmoWelcome)) { | ||
adapter.log.info("No product was choosen, using Weatherstation as default!"); | ||
adapter.config.netatmoWeather = true; | ||
@@ -97,2 +100,7 @@ } | ||
} | ||
if (adapter.config.netatmoCoach) { | ||
scope += " read_homecoach"; | ||
} | ||
// -------------------------------------------------------- | ||
@@ -124,2 +132,14 @@ // Backward compatibility end ... | ||
api.setAdapter(adapter); | ||
if (adapter.config.netatmoCoach) { | ||
coach = new NetatmoCoach(api, adapter); | ||
coach.requestUpdateCoachStation(); | ||
_deviceUpdateTimer = setInterval(function () { | ||
coach.requestUpdateCoachStation(); | ||
}, adapter.config.check_interval * 60 * 1000); | ||
} | ||
if (adapter.config.netatmoWeather) { | ||
@@ -126,0 +146,0 @@ station = new NetatmoStation(api, adapter); |
@@ -5,3 +5,5 @@ var util = require('util'); | ||
var moment = require('moment'); | ||
var glob_lib_adapter = null; | ||
var BASE_URL = 'https://api.netatmo.com'; | ||
@@ -23,2 +25,10 @@ | ||
/** | ||
* setAdapter | ||
* @param myadapter | ||
*/ | ||
netatmo.prototype.setAdapter = function (myadapter) { | ||
glob_lib_adapter = myadapter; | ||
}; | ||
/** | ||
* handleRequestError | ||
@@ -48,2 +58,3 @@ * @param err | ||
} | ||
var error = new Error(message + ": " + errorMessage); | ||
@@ -78,3 +89,4 @@ if (critical) { | ||
this.refresh_token = args.refresh_token; | ||
this.scope = args.scope || 'read_station read_thermostat write_thermostat read_camera'; | ||
this.scope = args.scope || 'read_homecoach read_station read_thermostat write_thermostat read_camera'; | ||
this.emit('access_token', this.access_token); | ||
@@ -141,3 +153,3 @@ this.emit('refresh_token', this.refresh_token); | ||
this.client_secret = args.client_secret; | ||
this.scope = args.scope || 'read_station read_thermostat write_thermostat read_camera'; | ||
this.scope = args.scope || 'read_homecoach read_station read_camera'; | ||
@@ -252,3 +264,6 @@ Object.assign( | ||
var url; | ||
if (this.scope.indexOf('read_station') !== -1) { | ||
if (this.scope.indexOf('read_homecoach') !== -1) { | ||
url = util.format('%s/api/gethomecoachsdata', BASE_URL); | ||
} else if (this.scope.indexOf('read_station') !== -1) { | ||
url = util.format('%s/api/getstationsdata', BASE_URL); | ||
@@ -405,2 +420,57 @@ } else if (this.scope.indexOf('read_thermostat') !== -1) { | ||
/** | ||
* https://dev.netatmo.com/doc/methods/gethomecoachsdata | ||
* @param options | ||
* @param callback | ||
* @returns {*} | ||
*/ | ||
netatmo.prototype.getCoachData = function (options, callback) { | ||
// Wait until authenticated. | ||
if (!this.access_token) { | ||
return this.on('authenticated', function () { | ||
this.getCoachData(options, callback); | ||
}); | ||
} | ||
if (options != null && callback == null) { | ||
callback = options; | ||
options = null; | ||
} | ||
var url = util.format('%s/api/gethomecoachsdata', BASE_URL); | ||
var form = { | ||
access_token: this.access_token, | ||
}; | ||
if (options && options.app_type) { | ||
form.app_type = options.app_type; | ||
} | ||
request({ | ||
url: url, | ||
method: "POST", | ||
form: form, | ||
}, function (err, response, body) { | ||
if (err || response.statusCode != 200) { | ||
return this.handleRequestError(err, response, body, "gethomecoachsdata error", false, callback, this.getCoachData.bind(this, options, callback)); | ||
} | ||
body = JSON.parse(body); | ||
var devices = body.body.devices; | ||
this.emit('get-coachdata', err, devices); | ||
if (callback) { | ||
return callback(err, devices); | ||
} | ||
return this; | ||
}.bind(this)); | ||
return this; | ||
}; | ||
/** | ||
* https://dev.netatmo.com/doc/methods/getthermostatsdata | ||
@@ -407,0 +477,0 @@ * @param options |
{ | ||
"name": "iobroker.netatmo", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"description": "ioBroker netatmo Adapter", | ||
@@ -5,0 +5,0 @@ "authors": { |
@@ -34,2 +34,5 @@ ![Logo](admin/netatmo.png) | ||
### 1.3.0 | ||
* (HMeyer) Added Netatmo Coach | ||
### 1.2.2 | ||
@@ -36,0 +39,0 @@ * (PArns) Updated meta info |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
178281
17
3684
135