Add HealthKit sensors to iOS app - #4923
Conversation
There was a problem hiding this comment.
Pull request overview
Adds optional Apple Health (HealthKit) backed sensors to the iOS app so selected health metrics can be exposed via the existing Home Assistant sensor webhook flow.
Changes:
- Introduces a new
HealthKitSensorprovider with caching and per-metric enablement. - Adds a persisted master toggle + cache storage in
SettingsStore, and wires a new “Apple Health” section into the Sensors settings UI. - Adds HealthKit entitlement + usage description strings, plus unit tests for sensor collection/encoding and settings wiring.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/Shared/Sensors/HealthKitSensor.test.swift | Adds unit tests for HealthKit sensor behavior (availability, caching, enable/disable). |
| Tests/App/Settings/SensorListViewModelHealthKitTests.swift | Adds unit tests for HealthKit toggle behavior in the sensors settings view model. |
| Sources/Shared/Settings/SettingsStore.swift | Persists HealthKit sensors master enable state, “ever enabled” flag, and cached values. |
| Sources/Shared/Resources/Swiftgen/Strings.swift | Adds SwiftGen accessors for new HealthKit-related localized strings. |
| Sources/Shared/Environment/Environment.swift | Adds HealthKit dependency wrapper + registers the new HealthKit sensor provider. |
| Sources/Shared/API/Webhook/Sensors/HealthKitSensor.swift | Implements the HealthKit-backed sensor provider and cache model types. |
| Sources/App/Settings/Sensors/List/SensorListViewModel.swift | Adds HealthKit status state, toggle handling, and hides HealthKit sensors when master toggle is off. |
| Sources/App/Settings/Sensors/List/SensorListView.swift | Adds an Apple Health section with master toggle + status display to the Sensors settings UI. |
| Sources/App/Resources/Info.plist | Adds NSHealthShareUsageDescription. |
| Sources/App/Resources/en.lproj/Localizable.strings | Adds localized strings for the Sensors settings Apple Health section. |
| Sources/App/Resources/en.lproj/InfoPlist.strings | Adds localized NSHealthShareUsageDescription. |
| HomeAssistant.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved | Adds a new SPM lockfile under the .xcodeproj workspace. |
| HomeAssistant.xcodeproj/project.pbxproj | Adds new source/test files to the project and enables the HealthKit capability. |
| Configuration/Entitlements/App-ios.entitlements | Enables the HealthKit entitlement for the iOS app target. |
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
|
Please do not use AI to answer PR comments, if you/AI implemented it in a specific way, the implementation could be correct, I'm just making questions to evaluate the reasoning. |
|
Please provide screenshots of how the sensors in app, sensors in HA, and permission request look like. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4923 +/- ##
=======================================
Coverage ? 50.14%
=======================================
Files ? 284
Lines ? 18147
Branches ? 0
=======================================
Hits ? 9099
Misses ? 9048
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
270dbca to
c33e9f4
Compare
|
I tried this, but HealthKit doesn’t expose whether read access was granted or denied. A denied read looks the same as there being no data, so showing Enabled/Disabled would be misleading. I’ve kept the separate section with the request button and availability status instead. Is that okay? |
|
@aero-oli Apparently tests are hanging and exceeding the CI limit, please check on your local environment |
## AI Policy - [x] I have read the [Open Home Foundation AI Policy](https://developers.home-assistant.io/docs/ai_policy). Select exactly one option that describes AI usage in this contribution: - [ ] I have not used AI for this contribution. - [x] 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 Fixes the CI build failures introduced by the HealthKit sensors change (#4923): - The Mac (Catalyst) build failed to compile because `SensorListViewModel` used `Current.healthKitService`, which is only defined for iOS (`#if os(iOS) && !targetEnvironment(macCatalyst)`). The service usage is now guarded behind the same check, and the HealthKit section is hidden on Catalyst. - The iOS App Store archive failed to sign because the provisioning profile did not include the HealthKit capability. The `iOS App Store - App` profile has been updated to include the `com.apple.developer.healthkit` entitlement. ## Screenshots No visual change on iOS. On Mac Catalyst the (non-functional) HealthKit section is no longer shown. ## Link to pull request in Documentation repository Documentation: home-assistant/companion.home-assistant# ## Any other notes Follow-up to #4923.
## AI Policy - [x] I have read the [Open Home Foundation AI Policy](https://developers.home-assistant.io/docs/ai_policy). Select exactly one option that describes AI usage in this contribution: - [ ] I have not used AI for this contribution. - [x] 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 App Store upload of the iOS build fails with error 90683 because the app now ships the HealthKit entitlement but is missing the `NSHealthUpdateUsageDescription` key in its Info.plist: > Missing purpose string in Info.plist. ... The Info.plist file for the "Home Assistant.app" bundle should contain a NSHealthUpdateUsageDescription key with a user-facing purpose string... Apple requires this key whenever the HealthKit entitlement is present, even for read-only usage. The app only reads Health data (`requestAuthorization` uses an empty `toShare` set), so the purpose string states that no data is written. ## Screenshots No visual change. The string is only shown if write access is ever requested, which the app never does. ## Link to pull request in Documentation repository Documentation: home-assistant/companion.home-assistant# ## Any other notes Follow-up to #4923 and #5264.

Summary
Adds optional HealthKit-backed iOS sensors so selected health metrics can be exposed through the existing Home Assistant sensor webhook flow.
This includes:
Screenshots
Link to pull request in Documentation repository
Documentation: home-assistant/companion.home-assistant#1368
Any other notes
Validation: CI passed on the fork PR, including lint, unused-string checks, SwiftLint disable checks, and the test job: https://github.com/aero-oli/iOS/actions/runs/28614134149