Post-commissioning traits for camera onboarding

Traits that can be used after the device has been commissioned are:

OtaSoftwareUpdateRequestor trait

This trait provides an interface to monitor an OTA software update on the camera device. Once commissioned, the camera initiates the update and reports its state to the app. Once the app receives the status that the software update is complete, the camera can begin to livestream.

The following sample code and explanation demonstrate how the trait can be used.

withTimeout(OTA_TIMEOUT_MS) {
  device.type(OtaRequestorDevice)
    .mapNotNull { it?.trait(OtaSoftwareUpdateRequestor) }
    .distinctUntilChanged()
    .transformWhile { trait ->
      emit(trait)
      !isTerminalState(trait.updateState)
    }
    .collect { trait ->
      updateState = trait.updateState
      updateStateProgress = trait.updateStateProgress
    }
}
  • Timeout: withTimeout enforces a maximum duration (OTA_TIMEOUT_MS) for the monitoring process. If the update doesn't complete within this time, it times out.

  • Observing trait changes: The .distinctUntilChanged() operator ensures that the subsequent code in the chain only reacts when the state of the trait actually changes, which makes this more efficient than constant polling.

  • Processing until completion: The .transformWhile operator continues processing updates as long as the OTA updateState is not a terminal state (such as success or failure).

  • Collecting status: For each state change, the .collect block is executed to update the updateState and updateStateProgress variables with the latest values from the trait.

For more information, refer to the OtaSoftwareUpdateRequestor trait reference.

ConfigurationDone trait

This trait is not required for camera activation, but it allows the app to track when the device is fully set up and usable by setting the AppConfigurationComplete attribute to true. This trait should be used after the OtaSoftwareUpdateRequestor trait.

device.trait(ConfigurationDone).first().update { setAppConfigurationComplete(true) }