Authorize and connect to the Netatmo API.
All you need are your login credentials from https://auth.netatmo.com/access/checklogin and ClientId/Client-Secret from https://dev.netatmo.com/myaccount/createanapp
No OAuth2 handling is needed, the lib will login and refresh the credentials automatically
Initialize the lib with your credentials
List<Scope> scopeList = new ArrayList<Scope>();
list.add(Scope.ACCESS_PRESENCE);
NetatmoApi api = new NetatmoApi("$USERNAME", "$USERPASSWORD", "CLIENTID", "CLIENTSECRET", scopeList)
If you already have access token and refresh token, which is accessible from the NetatmoApi-Object after the first successfull call, you may add them after the cope list. It will prevent the lib to relogin.
For debug information simply add the debug flag as boolean parameter to the constructor.
For retreiving data, you have to specify the Netatmo Api Connector (weather, energy, aircare, etc.) and method.
Executable<HomesDataBody> getHomesDataExec = api.getEnergyApi().getHomesData(null, null)
In return you get an executable with is capable of synchronous and/or asynchronous execution.
HomesDataBody result = getHomesDataExec.executeSync()
The result is either the model or null or the actual object. Error values are only printed when debug is activated
Executable.Callback<HomesDataBody> callback = new Executable.Callback<HomesDataBody>() {
@Override
public void onResult(HomesDataBody homesDataBody) {
}
@Override
public void onError(BackendError s) {
}
};
api.getEnergyApi().getHomesData(null, null).executeAsync(callback);
The call will either return the object in the onResult
function or an error in OnError
function
Also lambdas are possible
{
[…]
api.getEnergyApi().getHomesData(null, null)
.onError(this::onError)
.executeAsync(this::onSuccess);
[…]
}
public Unit onError(BackendError error){
return null;
}
public Unit onSuccess(HomesDataBody obj) {
return null;
}
Be aware of the return types (caused by Kotlin <-> Java interface )
For the most convinient usage, Kotlin is advised
- Kotlin 1.3
- Kotlin Coroutines 1.0.1
- Kotlin Logging 1.6.22
- Kotlin Coroutine Adapter 0.9.2
- Retrofit 2.5.0
- Jackson Converter 2.5.0
- Jackson Core 2.9.7
- Jackson Annotations 2.9.7
- Jackson Kotlin Module 2.9.7
- OkHttp 3.12.0
- OkHttp Loggin Interceptor 3.12.0
- Michael Rudolph - Initial work
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details