Traits that can be used after the device has been commissioned are:
OtaSoftwareUpdateRequestorTrait
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.
device.types.subscribe(OtaRequestorDeviceType.self)
.receive(on: DispatchQueue.main)
.compactMap { $0.traits[Matter.OtaSoftwareUpdateRequestorTrait.self] }
.removeDuplicates()
.timeout(.seconds(30), scheduler: DispatchQueue.main)
.sink { [weak self] completion in
guard let self else { return }
Logger.debug("OTA trait subscription completed unexpectedly: \(completion).")
if case .otaDownload = self.step {
Logger.debug("Advancing to settings step due to OTA trait subscription completion")
self.step = .settings
}
} receiveValue: { [weak self] otaTrait in
Logger.debug(
"OTA update is in progress, state: \(otaTrait.attributes.updateState), progress: \(otaTrait.attributes.updateStateProgress ?? 0)"
)
self.step = .otaDownload(
state: otaTrait.attributes.updateState ?? .querying,
progress: Double(otaTrait.attributes.updateStateProgress ?? 0) / 100.0)
}
}
.store(in: &cancellables)
Subscribing to device traits: It subscribes to the device's traits, specifically looking for the
OtaSoftwareUpdateRequestorTraitto listen for OTA update information.Setting a timeout: It sets a 30-second timeout. If no update is received from the trait within that time, the subscription ends.
Handling OTA status updates (
receiveValue): When theOtaSoftwareUpdateRequestorTraitprovides a new status, this block is executed. It logs the current state and the progress of the OTA update. It then updates the application's internal state (step) to reflect this new information.Handling completion (
sink): This block is executed when the subscription ends, and logs the completion. If the process was in a downloading state, the application state advances to the next step (.settings).Managing the subscription lifecycle: The
.store(in: &cancellables)line ensures that the subscription is properly managed and cancelled when the object that owns it is deallocated.
For more information, refer to the
OtaSoftwareUpdateRequestorTrait trait reference.
ConfigurationDoneTrait
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 OtaSoftwareUpdateRequestorTrait.
let configDoneTrait = try await device.types.get(OtaRequestorDeviceType.self)?.traits[Google.ConfigurationDoneTrait.self]
_ = try await configDoneTrait?.update {
$0.setAppConfigurationComplete(true)
}