PolarSleepApi

public protocol PolarSleepApi

Protocol defining methods to get Polar Sleep Data

  • Get sleep recording state

    Requires

    Requires SDK feature(s): PolarBleSdkFeature.feature_polar_sleep_data

    Throws

    timeout(description:) if timeout is exceeded before state is received.

    Declaration

    Swift

    @available(*, deprecated, message: "Use getSleepRecordingStatus(identifier:timeoutMs:﹚, which reports unknown state instead of off")
    func getSleepRecordingState(identifier: String, timeoutMs: UInt64) async throws -> Bool

    Parameters

    identifier

    The Polar device ID or BT address

    timeoutMs

    Timeout in milliseconds while waiting for the first sleep recording state event

    Return Value

    AnyPublisher emitting a single Bool value indicating if sleep recording is ongoing

  • Declaration

    Swift

    @available(*, deprecated, message: "Use observeSleepRecordingStatus(identifier:﹚, which reports unknown state instead of off")
    func observeSleepRecordingState(identifier: String) -> AsyncThrowingStream<[Bool], Error>

    Return Value

    Publisher stream of Bool values indicating if sleep recording is ongoing

  • Get sleep recording status.

    Requires

    Requires SDK feature(s): PolarBleSdkFeature.feature_polar_sleep_data

    Throws

    timeout(description:) if timeout is exceeded before a status is received.

    Declaration

    Swift

    func getSleepRecordingStatus(identifier: String, timeoutMs: UInt64) async throws -> PolarSleepRecordingStatus

    Parameters

    identifier

    The Polar device ID or BT address

    timeoutMs

    Timeout in milliseconds while waiting for the first sleep recording status event

    Return Value

    The sleep recording status. .unknown means the device did not report the state.

  • Observe sleep recording status.

    Declaration

    Swift

    func observeSleepRecordingStatus(identifier: String) -> AsyncThrowingStream<[PolarSleepRecordingStatus], Error>

    Return Value

    Stream of sleep recording status batches. .unknown means the device did not report the state.

  • Declaration

    Swift

    func stopSleepRecording(identifier: String) async throws

    Return Value

    Publisher stream

  • Declaration

    Swift

    func getSleep(identifier: String, fromDate: Date, toDate: Date) async throws -> [PolarSleepData.PolarSleepAnalysisResult]

    Return Value

    Publisher emitting an array of PolarSleepData for the specified period.

  • getSleepData(identifier:fromDate:toDate:) Default implementation, asynchronous

    Default Implementation

    Declaration

    Swift

    @available(*, deprecated, renamed: "getSleep(identifier:fromDate:toDate:﹚")
    func getSleepData(identifier: String, fromDate: Date, toDate: Date) async throws -> [PolarSleepData.PolarSleepAnalysisResult]
  • getSleepRecordingState(identifier:) Extension method, asynchronous

    Get sleep recording state with default timeout of 30 seconds.

    Declaration

    Swift

    @available(*, deprecated, message: "Use getSleepRecordingStatus(identifier:﹚, which reports unknown state instead of off")
    func getSleepRecordingState(identifier: String) async throws -> Bool
  • getSleepRecordingStatus(identifier:) Extension method, asynchronous

    Get sleep recording status with default timeout of 30 seconds.

    Declaration

    Swift

    func getSleepRecordingStatus(identifier: String) async throws -> PolarSleepRecordingStatus