Fix sleep data parsing to match actual API response#11
Fix sleep data parsing to match actual API response#11talison wants to merge 1 commit intosteipete:mainfrom
Conversation
This PR addresses two issues with the sleep commands: 1. **Range command flag parsing** (`sleep_range.go`): The `--from` and `--to` flags were being read via `viper.GetString()` which wasn't receiving the flag values properly. Changed to read directly from cobra's `cmd.Flags().GetString()`. 2. **SleepDay struct field mapping** (`eightsleep.go`): The struct fields didn't match the actual API response structure. The API returns: - `sleepDuration` (not `sleepDurationSeconds`) - `deepDuration`, `remDuration`, `lightDuration` for sleep stages - `sleepStart`, `sleepEnd` timestamps - Nested `sleepQualityScore` with `hrv.current`, `heartRate.current`, etc. Updated the struct and commands to properly parse and display: - Sleep duration in hours - Deep/REM/Light sleep durations - Sleep start/end times - RHR (resting heart rate) - HRV - Respiratory rate Tested against live Eight Sleep API.
Corrects field mappings for sleep data parsing: - sleepDuration (not sleepDurationSeconds) - Adds deepDuration, remDuration, lightDuration, sleepStart/End - Properly nests sleepQualityScore with hrv, heartRate, respiratoryRate - Fixes sleep range --from/--to flag parsing (read from cobra, not viper) - Displays durations in hours for readability Inspired by talison's analysis in steipete#11.
|
Hey @talison — thanks for digging into the actual API response structure and testing against the live API. The before/after comparison really shows the problem clearly. A few things I'd like to see before we merge:
The struct changes themselves look correct based on your live API testing. Happy to help if you have questions about rebasing. Thanks! |
|
Update: PR #31 just merged and addresses the The remaining value in this PR is the
Happy to help if you want to pick this back up. Thanks! |
Summary
This PR addresses two issues with the sleep commands:
Range command flag parsing (
sleep_range.go): The--fromand--toflags were being read viaviper.GetString()which wasn't receiving the flag values properly. Changed to read directly from cobra'scmd.Flags().GetString().SleepDay struct field mapping (
eightsleep.go): The struct fields didn't match the actual API response structure. The API returns:sleepDuration(notsleepDurationSeconds)deepDuration,remDuration,lightDurationfor sleep stagessleepStart,sleepEndtimestampssleepQualityScorewithhrv.current,heartRate.current, etc.Changes
Updated the struct and commands to properly parse and display:
Before/After
Before:
After:
Test plan
eightctl sleep dayagainst live APIeightctl sleep range --from X --to Yagainst live API🤖 Generated with Claude Code