Skip to content

Add HealthKit sensors to iOS app - #4923

Merged
bgoncal merged 10 commits into
home-assistant:mainfrom
aero-oli:feature/apple-health-sensors
Jul 28, 2026
Merged

Add HealthKit sensors to iOS app#4923
bgoncal merged 10 commits into
home-assistant:mainfrom
aero-oli:feature/apple-health-sensors

Conversation

@aero-oli

@aero-oli aero-oli commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds optional HealthKit-backed iOS sensors so selected health metrics can be exposed through the existing Home Assistant sensor webhook flow.

This includes:

  • HealthKit authorization and sensor value collection for supported health metrics.
  • A persisted app setting for enabling/disabling HealthKit sensors.
  • Sensors settings UI wiring so the HealthKit group appears alongside existing sensor controls.
  • The required HealthKit entitlement and usage description.
  • Unit coverage for HealthKit sensor encoding/collection behavior and the sensor list view model wiring.

Screenshots

serve-sim-screenshot-2026-07-24T17-13-15-427 serve-sim-screenshot-2026-07-24T17-14-53-623 serve-sim-screenshot-2026-07-24T17-15-12-007

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

@aero-oli
aero-oli marked this pull request as ready for review July 2, 2026 19:38
Copilot AI review requested due to automatic review settings July 2, 2026 19:38

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.

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 HealthKitSensor provider 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.

Comment thread Sources/Shared/Environment/Environment.swift Outdated
Comment thread Sources/Shared/API/Webhook/Sensors/HealthKitSensor.swift Outdated
Comment thread Tests/Shared/Sensors/HealthKitSensor.test.swift Outdated
Comment thread Tests/Shared/Sensors/HealthKitSensor.test.swift Outdated
Comment thread Tests/Shared/Sensors/HealthKitSensor.test.swift Outdated
Comment thread Tests/Shared/Sensors/HealthKitSensor.test.swift Outdated
Comment thread Sources/Shared/Settings/SettingsStore.swift Outdated
Comment thread Sources/Shared/Settings/SettingsStore.swift Outdated
Comment thread Sources/Shared/Settings/SettingsStore.swift Outdated
Comment thread Sources/Shared/Settings/SettingsStore.swift Outdated
Comment thread Sources/App/Settings/Sensors/List/SensorListViewModel.swift Outdated
Comment thread Sources/App/Settings/Sensors/List/SensorListViewModel.swift Outdated
@home-assistant
home-assistant Bot marked this pull request as draft July 2, 2026 19:57
@home-assistant

home-assistant Bot commented Jul 2, 2026

Copy link
Copy Markdown

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@aero-oli
aero-oli marked this pull request as ready for review July 2, 2026 20:23
@home-assistant
home-assistant Bot requested a review from bgoncal July 2, 2026 20:23
@aero-oli
aero-oli requested a review from Copilot July 2, 2026 20:39

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.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.

Comment thread Sources/App/Settings/Sensors/List/SensorListViewModel.swift Outdated
Comment thread Sources/Shared/Environment/Environment.swift Outdated
Comment thread Sources/Shared/Environment/Environment.swift Outdated
Comment thread Sources/Shared/Environment/Environment.swift Outdated
Comment thread Sources/Shared/API/Webhook/Sensors/HealthKitSensor.swift
@bgoncal

bgoncal commented Jul 2, 2026

Copy link
Copy Markdown
Member

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.

@bgoncal

bgoncal commented Jul 2, 2026

Copy link
Copy Markdown
Member

Please provide screenshots of how the sensors in app, sensors in HA, and permission request look like.

Comment thread Sources/Shared/Environment/Environment.swift Outdated
Comment thread Sources/Shared/Environment/Environment.swift Outdated
Comment thread Sources/Shared/Environment/Environment.swift Outdated
Comment thread Sources/Shared/Environment/Environment.swift Outdated
@home-assistant
home-assistant Bot marked this pull request as draft July 2, 2026 20:58
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.77778% with 32 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@23628b9). Learn more about missing BASE report.

Files with missing lines Patch % Lines
Sources/Shared/Environment/Environment.swift 65.15% 23 Missing ⚠️
...s/Shared/API/Webhook/Sensors/HealthKitSensor.swift 88.46% 9 Missing ⚠️
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.
📢 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.

@aero-oli
aero-oli force-pushed the feature/apple-health-sensors branch from 270dbca to c33e9f4 Compare July 24, 2026 15:32
@aero-oli
aero-oli marked this pull request as ready for review July 24, 2026 17:42
@home-assistant
home-assistant Bot requested a review from bgoncal July 24, 2026 17:42

@bgoncal bgoncal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please include health data permission in the same style as the existent permissions sections like the motion access

Image

@home-assistant
home-assistant Bot marked this pull request as draft July 24, 2026 17:55
@aero-oli

Copy link
Copy Markdown
Contributor Author

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
aero-oli marked this pull request as ready for review July 24, 2026 18:51
@home-assistant
home-assistant Bot requested a review from bgoncal July 24, 2026 18:51
@aero-oli
aero-oli requested a review from bgoncal July 24, 2026 21:29
@bgoncal

bgoncal commented Jul 27, 2026

Copy link
Copy Markdown
Member

@aero-oli Apparently tests are hanging and exceeding the CI limit, please check on your local environment

@bgoncal
bgoncal merged commit 4b0e30c into home-assistant:main Jul 28, 2026
5 checks passed
bgoncal added a commit that referenced this pull request Jul 28, 2026
## 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.
bgoncal added a commit that referenced this pull request Jul 28, 2026
## 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.
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.

3 participants