Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Sleep API not working

ANSWERED

I am trying to add the new Fitbit sleep API to my app and I followed the exact instructions on the Fitbit API site (https://dev.fitbit.com/build/reference/device-api/sleep/). 

I put this in my app: 

import sleep from "sleep"

if (sleep) {
sleep.onchange = () => {
console.log(`User sleep state is: ${sleep!.state}`)
}
} else {
console.log("Sleep API not supported on this device, or no permission")
}

 

This does not work. The backtick in console.log is poorly placed and does not even build and when I remove the exclamation mark it keeps posting asleep when I am awake and wearing the watch. What is the problem?

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

You're right, that rogue exclamation mark is a TypeScript'ism, sorry.

 

The detection is a basic sleep classifier, but if you're moving it shouldn't think you're asleep. Are you sitting completely still when it reports you're asleep?

View best answer in original post

Best Answer
0 Votes
2 REPLIES 2

You're right, that rogue exclamation mark is a TypeScript'ism, sorry.

 

The detection is a basic sleep classifier, but if you're moving it shouldn't think you're asleep. Are you sitting completely still when it reports you're asleep?

Best Answer
0 Votes

It is just not super accurate. It is useful though as a point of reference among other variables. Thanks for your response Jon.

Best Answer
0 Votes