-
Notifications
You must be signed in to change notification settings - Fork 53
Fix hrv #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix hrv #152
Conversation
WalkthroughUnpacks and stricter-validates body battery reading tuples and explicitly returns readings sorted by timestamp; makes several HRV model fields optional with defaults; adds/adjusts tests for body battery list/get and bumps package version to 0.5.20. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #152 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 45 45
Lines 1896 1905 +9
=========================================
+ Hits 1896 1905 +9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/garth/data/body_battery/readings.py(1 hunks)src/garth/data/hrv.py(2 hunks)src/garth/version.py(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: test 3.12
🔇 Additional comments (4)
src/garth/version.py (1)
1-1: LGTM! Version bump aligns with the PR changes.The version increment from 0.5.19 to 0.5.20 is appropriate for this patch-level change that makes data fields optional.
src/garth/data/body_battery/readings.py (1)
37-40: LGTM! Using unpacked variables improves readability.Replacing direct indexing with named variables makes the code clearer and more maintainable.
src/garth/data/hrv.py (2)
47-50: Verify downstream code handles optional sleep timestamp fields.Making sleep timestamp fields optional with default
Noneappropriately handles cases where sleep data is unavailable (e.g., user not wearing the watch). Ensure that any code accessingsleep_start_timestamp_gmt,sleep_end_timestamp_gmt,sleep_start_timestamp_local, orsleep_end_timestamp_localfields includes properNonechecks before performing date/time operations.
27-28: Good change to handle missing HRV data gracefully.Making
last_night_avgandlast_night_5_min_highoptional with defaultNoneinHRVSummaryaligns with the PR objective to prevent failures when HRV measurements are unavailable. The optional type hints (int | None) ensure type checkers will enforce proper None handling in any downstream code that accesses these fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
tests/data/cassettes/test_daily_body_battery_stress_get_incomplete_data.yamlis excluded by!tests/**/cassettes/**
📒 Files selected for processing (2)
src/garth/data/body_battery/readings.py(1 hunks)tests/data/test_body_battery_data.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
tests/**
⚙️ CodeRabbit configuration file
tests/**: - test functions shouldn't have a return type hint
- it's ok to use
assertinstead ofpytest.assume()
Files:
tests/data/test_body_battery_data.py
🧬 Code graph analysis (1)
tests/data/test_body_battery_data.py (1)
src/garth/data/body_battery/daily_stress.py (3)
DailyBodyBatteryStress(20-90)get(73-90)body_battery_readings(37-39)
🪛 GitHub Actions: CI
tests/data/test_body_battery_data.py
[error] 121-122: Item 'None' of 'DailyBodyBatteryStress | None' has no attribute 'body_battery_readings'.
🔇 Additional comments (4)
src/garth/data/body_battery/readings.py (3)
32-34: LGTM! Past review feedback addressed correctly.The unpacking with
*_now handles arrays with more than 4 elements, and the explicitNonechecks prevent incorrectly skipping readings withlevel=0or empty-string status.
37-40: LGTM! Cleaner usage of unpacked variables.Using the unpacked variables instead of array indices improves readability and maintainability.
44-44: LGTM! Explicit sorting ensures chronological order.The explicit return statement makes the sorting behavior clear and ensures readings are always in chronological order.
tests/data/test_body_battery_data.py (1)
130-131: LGTM! Sequential execution for VCR compatibility.Setting
max_workers=1appropriately prevents VCR issues with concurrent requests during testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/data/test_body_battery_data.py (1)
118-124: Consider using more explicit None check for clarity.The test correctly addresses the previous review comment by checking that
daily_datais not None before accessing its attributes. However,assert daily_datacould be made more explicit asassert daily_data is not Noneto improve readability and make the intent clearer to both developers and type checkers.🔎 Suggested refinement
@pytest.mark.vcr def test_daily_body_battery_stress_get_incomplete_data(authed_client: Client): daily_data = DailyBodyBatteryStress.get("2025-12-18", client=authed_client) - assert daily_data + assert daily_data is not None, "Expected data for 2025-12-18" assert all(r.level is not None for r in daily_data.body_battery_readings) assert all(r.status is not None for r in daily_data.body_battery_readings)
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
tests/data/test_body_battery_data.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
tests/**
⚙️ CodeRabbit configuration file
tests/**: - test functions shouldn't have a return type hint
- it's ok to use
assertinstead ofpytest.assume()
Files:
tests/data/test_body_battery_data.py
🧬 Code graph analysis (1)
tests/data/test_body_battery_data.py (1)
src/garth/data/body_battery/daily_stress.py (2)
get(73-90)body_battery_readings(37-39)
matin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good. feel free to merge and release
Summary by CodeRabbit
Bug Fixes
Improvements
Tests
Chores
✏️ Tip: You can customize this high-level summary in your review settings.