기기가 커미셔닝된 후 사용할 수 있는 특성은 다음과 같습니다.
OtaSoftwareUpdateRequestorTrait
이 특성은 카메라 기기에서 OTA 소프트웨어 업데이트를 모니터링하는 인터페이스를 제공합니다. 커미셔닝이 완료되면 카메라가 업데이트를 시작하고 앱에 상태를 보고합니다. 앱이 소프트웨어 업데이트가 완료되었다는 상태를 수신하면 카메라가 라이브 스트리밍을 시작할 수 있습니다.
다음 샘플 코드와 설명은 특성을 사용하는 방법을 보여줍니다.
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)
기기 특성 구독: 기기의 특성을 구독하여 특히
OtaSoftwareUpdateRequestorTrait를 찾아 OTA 업데이트 정보를 수신합니다.제한 시간 설정: 30초 제한 시간을 설정합니다. 이 시간 내에 특성에서 업데이트가 수신되지 않으면 구독이 종료됩니다.
OTA 상태 업데이트 처리 (
receiveValue):OtaSoftwareUpdateRequestorTrait에서 새 상태를 제공하면 이 블록이 실행됩니다. 현재 상태와 OTA 업데이트 진행 상황을 로깅합니다. 그런 다음 이 새 정보를 반영하도록 애플리케이션의 내부 상태 (step)를 업데이트합니다.완료 처리 (
sink): 이 블록은 구독이 종료될 때 실행되며 완료를 로깅합니다. 프로세스가 다운로드 상태인 경우 애플리케이션 상태가 다음 단계 (.settings)로 진행됩니다.정기 결제 수명 주기 관리:
.store(in: &cancellables)줄은 정기 결제를 소유한 객체의 할당이 해제될 때 정기 결제가 적절하게 관리되고 취소되도록 합니다.
자세한 내용은 OtaSoftwareUpdateRequestorTrait 특성 참조를 확인하세요.
ConfigurationDoneTrait
이 특성은 카메라 활성화에 필요하지 않지만 앱이 AppConfigurationComplete 속성을 true로 설정하여 기기가 완전히 설정되고 사용 가능한 시점을 추적할 수 있습니다.
이 특성은 OtaSoftwareUpdateRequestorTrait 후에 사용해야 합니다.
let configDoneTrait = try await device.types.get(OtaRequestorDeviceType.self)?.traits[Google.ConfigurationDoneTrait.self]
_ = try await configDoneTrait?.update {
$0.setAppConfigurationComplete(true)
}