-
Notifications
You must be signed in to change notification settings - Fork 3
AferoJavaSDK Overview
These are the base functions that need to be implemented in order for the core SDK to make the necessary Afero REST API calls.
Observable<ActionResponse> postAttributeWrite(DeviceModel deviceModel, PostActionBody body, int maxRetryCount, int statusCode);
Observable<RequestResponse[]> postBatchAttributeWrite(DeviceModel deviceModel, DeviceRequest[] body, int maxRetryCount, int statusCode);
Observable<DeviceProfile> getDeviceProfile(String profileId);
Observable<DeviceProfile[]> getAccountDeviceProfiles();
Observable<ConclaveAccessDetails> postConclaveAccess(String mobileClientId);
Observable<Location> getDeviceLocation(DeviceModel deviceModel);
Observable<DeviceAssociateResponse> deviceAssociateGetProfile(String associationId, boolean isOwnershipVerified);
Observable<DeviceAssociateResponse> deviceAssociate(String associationId);
Observable<DeviceModel> deviceDisassociate(DeviceModel deviceModel);
Observable<Void> putDeviceTimezone(DeviceModel deviceModel, TimeZone tz);
String getActiveAccountId();
int getStatusCode(Throwable t);
boolean isTransferVerificationError(Throwable t);
AferoClientRetrofit2 is a concrete implementation of the AferoClient interface using Retrofit2 and okhttp3.
In addition to the base AferoClient calls, AferoClientRetrofit2 provides calls to fetch an access token, account tracking, password reset, sign out, etc.
public Observable<AccessToken> getAccessToken(String user, String password)
public void setOwnerAndActiveAccountId(String accountId)
public Observable<Void> resetPassword(String email)
public void signOut(String userId, String mobileClientId)
AferoClientRetrofit2.Config aferoClientConfig = new AferoClientRetrofit2.ConfigBuilder()
.oauthClientId(myOAuthClientId)
.oauthClientSecret(myOAuthClientSecret)
.logLevel(BuildConfig.HTTP_LOG_LEVEL)
.defaultTimeout(DEFAULT_SERVICE_TIMEOUT)
.build();
mAferoClient = new AferoClientRetrofit2(aferoClientConfig);
mAferoClient.setOwnerAndActiveAccountId(accountId);
mAferoClient.setToken(new AccessToken(accessToken, refreshToken));
The DeviceCollection manages the devices associated with the account, and provides updates when the collection or individual device state changes.
mDeviceCollection = new DeviceCollection(mAferoClient, ClientID.get(this));
mDeviceCollection.start()
.subscribe(new Observer<DeviceCollection>() {
@Override
public void onNext(DeviceCollection deviceCollection) {
// DeviceCollection is fully populated and listening for updates
}
@Override
public void onCompleted() {
// DeviceCollection is fully populated and listening for updates
}
@Override
public void onError(Throwable e) {
// may get IllegalStateException if already started
}
});
public Observable addDevice(String associationId, boolean isOwnershipVerified)
deviceCollection.addDevice(associationId, false)
.subscribe(new Action1<DeviceModel>() {
@Override
public void call(DeviceModel deviceModel) {
AfLog.i("New Device Added: " + deviceModel.getName());
}
});
public Observable removeDevice(DeviceModel deviceModel)
deviceCollection.removeDevice(deviceModel)
.subscribe(new Action1<DeviceModel>() {
@Override
public void call(DeviceModel deviceModel) {
AfLog.i("New Device Added: " + deviceModel.getName());
}
});
deviceCollection.observeCreates()
.subscribe(new Action1<DeviceModel>() {
@Override
public void call(DeviceModel deviceModel) {
AfLog.i("Device Added: " + deviceModel.getName());
}
});
deviceCollection.observeDeletes()
.subscribe(new Action1<DeviceModel>() {
@Override
public void call(DeviceModel deviceModel) {
AfLog.i("Device Removed: " + deviceModel.getName());
}
});
The AferoSofthub is a singleton that manages the soft hub functionality.
mAferoSofthub = AferoSofthub.acquireInstance(this, mAferoClient, "my-unique-client-identifier");
if (!(mAferoSofthub.isRunning() || mAferoSofthub.isStarting()) {
mAferoSofthub.start()
.subscribe(new Observer<AferoSofthub>() {
@Override
public void onNext(AferoSofthub aferoSofthub) {
// AferoSofthub is now running
}
@Override
public void onCompleted() {
// AferoSofthub is now running
}
@Override
public void onError(Throwable e) {
// may get IllegalStateException if already starting or running
}
});
}
This class provides support for the Afero wifi setup process to help bring wifi based devices online.
DeviceWifiSetup wifiSetup = new DeviceWifiSetup(DeviceModel deviceModel, AferoClient aferoClient);
wifiSetup.start();
// fetch the wifi network list visible from the Afero device
wifiSetup.getWifiSSIDList()
.subscribe(new Action1<WifiSSIDEntry>() {
@Override
public void call(WifiSSIDEntry wifiSSIDEntry) {
AfLog.i((wifiSSIDEntry.isSecure() ? "+" : "-") + " " + wifiSSIDEntry.getSSID());
}
});