openLiveData

abstract fun openLiveData(openable: Openable, cancellationSignal: CancellationSignal?): LiveData<Response<IotUnit, OpeningProgress>?>

Open the specified Openable. Some IotUnit must be booked before they can be opened. See BookingManager.

Returns a LiveData with the status of the operation. This method can only be called when the UnitController.Status is Status.Ready (see getStatusLiveData). In case the status is not ready, the returned Response will be failed with an IllegalStateException.

After logout LiveData.getValue is set to null. You need to re-observe this LiveData once the user is logged out!

The Response of this data contains two parameters:

The cancellation signal is used to cancel of the operation. Cancel is a "best effort" executeStateChangeRequest and some steps of opening cannot be cancelled. (e.g. API calls to backend) The Exception passed to the CancellationSignal.cancel method is forwarded to the Response.exception

Below is some example usage of the CancellationSignal:

val cancelOpen = CancellationSignal()

fun onOpenButtonClicked() {
open(iotUnit, cancelOpen)
.... observe the progress, update UI
if(response.exception is UserCancelException) {
// the SDK successfully cancelled the operation as requested by the user
}
}

fun onCancelButtonClicked() {
cancelOpen.cancel(UserCancelException("Canceling open of $iotUnit. User executeStateChangeRequest"))
}

override fun onStop() {
// onStop cancel opening to avoid the UnitController to search (and be busy) forever
cancelOpen.cancel(Exception("Canceling open of $iotUnit. Activity stop"))
}

class UserCancelException(message:String): Exception(message:String)