Fix sleep data parsing to match actual API response#11
Open
talison wants to merge 1 commit intosteipete:mainfrom
Open
Fix sleep data parsing to match actual API response#11talison wants to merge 1 commit intosteipete:mainfrom
talison 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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