IotDevice

IotDevice

You can get the IotDevice from the IotDeviceController.getIotDevices().

Since SDK 1.3.1 all functions in the IotDeviceController returning LiveData are deprecated . Use either the suspending functions with Coroutines or one of the *WithCallback() alternative functions.

The IotDevice offers you a function newRequest(). It gives you a StateChangeRequest.Builder.

val stateChangeRequest: StateChangeRequest = iotDevice.newRequest().apply {
  addState(property, value)
}

The StateChangeRequest can then be used as a parameter given to the execute() function of the IotDeviceController interface: iotDeviceController.execute(stateChangeRequest)

Kotlin
val cancelable: Cancelable = iotDeviceController.executeWithCallback(stateChangeRequest) { wasSuccessful: Boolean ->
  // check if call was successful
}

// you must call cancel when you leave your ViewModel/Fragment/Activity to not leak memory!
cancelable.cancel();
Kotlin + Coroutines
coroutineScope.launch {
  val wasSuccessful: Boolean = iotDeviceController.execute(stateChangeRequest)
  // check if call was successful
}
Java

Do not forget calling cancel() on the CoroutineScope or the Cancelable or you will leak memory!