Sensorberg Smart Spaces SDK for Android / com.sensorberg.smartworkspace.sdk / UnitController / open

open

abstract fun open(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.

The Response of this data contains two parameters:

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

Below is some example usage of the CancellationSignal:

val cancelOpen = CancellationSignal()
fun onOpenButtonClicked() {
   sdk.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 request"))
}

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)