Skip to content

Explain why the In Bed health sensor can be unavailable - #5655

Merged
bgoncal merged 1 commit into
mainfrom
health-in-bed-sensor-footer
Sep 5, 2026
Merged

Explain why the In Bed health sensor can be unavailable#5655
bgoncal merged 1 commit into
mainfrom
health-in-bed-sensor-footer

Conversation

@bgoncal

@bgoncal bgoncal commented Sep 5, 2026

Copy link
Copy Markdown
Member

AI Policy

Select exactly one option that describes AI usage in this contribution:

  • I have not used AI for this contribution.
  • AI assistance was used for this contribution.
  • AI fully generated the code for this contribution, but I've reviewed and understood it before submitting and will respond without AI during review.

Summary

The In Bed sleep sensor reports unavailable whenever nothing writes inBed samples to Apple Health. Apple Watch records the sleep stages but not time in bed, so on a Watch-only setup this one sensor looks broken while the other sleep sensors report a duration.

A metric can now carry an optional footer, shown under its row in the Apple Health sensor list. In Bed uses it to say where its samples have to come from: turn on "Track Time in Bed with iPhone" in Health > Sleep > Options, or use a sleep tracking app that records it.

Screenshots

Link to pull request in Documentation repository

Documentation: home-assistant/companion.home-assistant#

Any other notes

The footer is an enum case rather than a stored string, so the metric catalog stays plain data and the wording resolves in the user's current language.

Nothing writes `HKCategoryValueSleepAnalysis.inBed` samples on its own:
Apple Watch records the sleep stages but not time in bed, and the iPhone
only writes it once "Track Time in Bed with iPhone" is on. Without such a
sample the night isn't tracked for that stage, so `health_sleep_in_bed`
reports `unavailable` while the other sleep sensors report a duration,
which reads like a bug from the sensor list.

Give a metric an optional footer, shown under its row in the Apple Health
sensor list, and use it on In Bed to say where its samples have to come
from. The footer is a case rather than a string so the metric catalog
stays plain data and the wording resolves in the user's language.
Copilot AI lite review requested due to automatic review settings September 5, 2026 23:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is small and well-scoped, adds localized user guidance for the one affected metric, and includes a targeted unit test for the new catalog behavior.

Pull request overview

This PR clarifies why the Apple Health “In Bed” sleep sensor may remain unavailable by introducing an optional, localized per-metric footer that can be rendered under that sensor row in the Health sensor list.

Changes:

  • Added HealthKitMetric.footer (optional) plus a HealthKitMetricFooter enum that resolves localized explanatory text at read time.
  • Updated the sleep metric catalog so only health_sleep_in_bed carries a .timeInBedSource footer, with a unit test asserting no other metric has a footer.
  • Updated the Health sensor settings row UI to render the footer text under the toggle when present, and added the English localization key + SwiftGen accessor.
File summaries
File Description
Tests/Shared/Sensors/HealthKitMetricCatalog.test.swift Adds a test ensuring only the “In Bed” metric has a footer.
Sources/Shared/Resources/Swiftgen/Strings.swift SwiftGen accessor update for the new localized footer string.
Sources/Shared/API/Webhook/Sensors/Health/HealthKitMetricFooter.swift Introduces the footer enum and localization resolution (footer.text).
Sources/Shared/API/Webhook/Sensors/Health/HealthKitMetric+Sleep.swift Adds footer support to the sleep metric factory and assigns it to “In Bed”.
Sources/Shared/API/Webhook/Sensors/Health/HealthKitMetric.swift Adds the footer property to the shared metric model with a defaulted initializer parameter.
Sources/App/Settings/Sensors/Health/HealthSensorRow.swift Renders the optional footer under the metric’s toggle row in the settings list.
Sources/App/Resources/en.lproj/Localizable.strings Adds the English copy for the “In Bed” footer.
Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@bgoncal
bgoncal enabled auto-merge (squash) September 5, 2026 23:37
@codecov

codecov Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 8.33333% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 35.28%. Comparing base (c3d1737) to head (4d6126a).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
.../App/Settings/Sensors/Health/HealthSensorRow.swift 0.00% 19 Missing ⚠️
...Webhook/Sensors/Health/HealthKitMetricFooter.swift 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5655      +/-   ##
==========================================
- Coverage   35.29%   35.28%   -0.02%     
==========================================
  Files        1013     1014       +1     
  Lines       73124    73136      +12     
==========================================
- Hits        25812    25808       -4     
- Misses      47312    47328      +16     
Files with missing lines Coverage Δ
...Webhook/Sensors/Health/HealthKitMetric+Sleep.swift 100.00% <100.00%> (ø)
...d/API/Webhook/Sensors/Health/HealthKitMetric.swift 100.00% <100.00%> (ø)
...Webhook/Sensors/Health/HealthKitMetricFooter.swift 0.00% <0.00%> (ø)
.../App/Settings/Sensors/Health/HealthSensorRow.swift 0.00% <0.00%> (ø)

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bgoncal
bgoncal merged commit 244253a into main Sep 5, 2026
15 checks passed
@bgoncal
bgoncal deleted the health-in-bed-sensor-footer branch September 5, 2026 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants