Skip to main content
Version: v3

Sleep

Start from API_LEVEL 2.0 . Please refer to API_LEVEL.

Sleep Sensor.

info

permission code: data:user.hd.sleep

Methods

updateInfo

By default, the system updates the sleep data every 30 minutes, the updateInfo method is used to actively trigger the update of the sleep data

updateInfo(): void

getInfo

Get sleep information

getInfo(): SleepInfo

SleepInfo

PropertyTypeDescriptionAPI_LEVEL
scorenumberSleep score2.0
deepTimenumberDeep sleep time (minutes)2.0
startTimenumberSleep onset time, based on the number of minutes at 0:00 of the day2.0
endTimenumberSleep end time, based on the number of minutes at 0:00 of the day2.0
totalTimenumberGet total sleep time (minutes)2.0

getStageConstantObj

Get the constant value of the sleep stage, used to determine the sleep stage in the getSleepStageData return value

getStageConstantObj(): StageConstants

StageConstants

PropertyTypeDescriptionAPI_LEVEL
WAKE_STAGEnumberAwake stage2.0
REM_STAGEnumberDeep sleep time (minutes)2.0
LIGHT_STAGEnumberLight Sleep stage2.0
DEEP_STAGEnumberDeep Sleep stage2.0

getStage

Get Sleep Staging Data

getStage(): Array<StageInfo>

StageInfo

PropertyTypeDescriptionAPI_LEVEL
modelnumberSleep stage type, refer to the constants returned by getStageConstantObj for the meaning of the value2.0
startnumberSleep stage onset time, based on the number of minutes at 0:00 of the day2.0
stopnumberSleep stage end time, based on the number of minutes at 0:00 of the day2.0

getSleepingStatus

Start from API_LEVEL 3.0

Get the current sleep state, 0 'awake, 1' sleeping

getSleepingStatus(): number

getNap

Start from API_LEVEL 3.0

Get nap data

getNap(): Array<NapInfo>

NapInfo

PropertyTypeDescriptionAPI_LEVEL
lengthnumberNap duration (minutes)3.0
startnumberNap start time, based on the number of minutes at 0:00 of the day3.0
stopnumberNap end time, based on the number of minutes at 0:00 of the day3.0

Example

import { Sleep } from '@zos/sensor'

const sleep = new Sleep()
const { score } = sleep.getInfo()
const sleepStageConstants = sleep.getStageConstantObj()
const stage = sleep.getStage()

stage.forEach((i) => {
const { model } = i

if (model === sleepStageConstants.WAKE_STAGE) {
console.log('This stage is awake stage')
}
})