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
| Property | Type | Description | API_LEVEL |
|---|---|---|---|
| score | number | Sleep score | 2.0 |
| deepTime | number | Deep sleep time (minutes) | 2.0 |
| startTime | number | Sleep onset time, based on the number of minutes at 0:00 of the day | 2.0 |
| endTime | number | Sleep end time, based on the number of minutes at 0:00 of the day | 2.0 |
| totalTime | number | Get total sleep time (minutes) | 2.0 |
getStageConstantObj
Get the constant value of the sleep stage, used to determine the sleep stage in the getStage return value
getStageConstantObj(): StageConstants
StageConstants
| Property | Type | Description | API_LEVEL |
|---|---|---|---|
| WAKE_STAGE | number | Awake stage | 2.0 |
| REM_STAGE | number | Deep sleep time (minutes) | 2.0 |
| LIGHT_STAGE | number | Light Sleep stage | 2.0 |
| DEEP_STAGE | number | Deep Sleep stage | 2.0 |
getStage
Get Sleep Staging Data
getStage(): Array<StageInfo>
StageInfo
| Property | Type | Description | API_LEVEL |
|---|---|---|---|
| model | number | Sleep stage type, refer to the constants returned by getStageConstantObj for the meaning of the value | 2.0 |
| start | number | Sleep stage onset time, based on the number of minutes at 0:00 of the day | 2.0 |
| stop | number | Sleep stage end time, based on the number of minutes at 0:00 of the day | 2.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
| Property | Type | Description | API_LEVEL |
|---|---|---|---|
| length | number | Nap duration (minutes) | 3.0 |
| start | number | Nap start time, based on the number of minutes at 0:00 of the day | 3.0 |
| stop | number | Nap end time, based on the number of minutes at 0:00 of the day | 3.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')
}
})