Skip to content

navybk/netatmo-java-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Netatmo Kotlin/Java Api

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

Using the lib

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.

Examples

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.

Synchronous

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

Asynchronous

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

Used libraries

Authors

  • Michael Rudolph - Initial work

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details