Add Health Connect nutrition sensor support#6891
Conversation
There was a problem hiding this comment.
Hi @SteveHosko
It seems you haven't yet signed a CLA. Please do so here.
Once you do that we will be able to review and accept this pull request.
Thanks!
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
|
You need to update the companion app documentation with the new sensor https://companion.home-assistant.io/docs/core/sensors#health-connect-sensors |
| record.energyFromFat?.inKilocalories?.let { attributes["energyFromFat"] = it } | ||
| record.totalCarbohydrate?.inGrams?.let { attributes["totalCarbohydrate"] = it } | ||
| record.protein?.inGrams?.let { attributes["protein"] = it } | ||
| record.totalFat?.inGrams?.let { attributes["totalFat"] = it } | ||
| record.sugar?.inGrams?.let { attributes["sugar"] = it } | ||
| record.dietaryFiber?.inGrams?.let { attributes["dietaryFiber"] = it } | ||
| record.sodium?.inGrams?.let { attributes["sodium"] = it } | ||
| record.saturatedFat?.inGrams?.let { attributes["saturatedFat"] = it } | ||
| record.transFat?.inGrams?.let { attributes["transFat"] = it } | ||
| record.unsaturatedFat?.inGrams?.let { attributes["unsaturatedFat"] = it } |
There was a problem hiding this comment.
Why only taking those? The API does have more attributes like vitaminA?
|
|
||
| val permissions = sensorManager.requiredPermissions(context, HealthConnectSensorManager.nutrition.id) | ||
|
|
||
| assertEquals( |
|
|
||
| assertEquals( | ||
| true, | ||
| permissions.contains(HealthPermission.getReadPermission(NutritionRecord::class)), |
There was a problem hiding this comment.
I think you can make an exhaustive test by testing that it contains PERMISSION_READ_HEALTH_DATA_IN_BACKGROUND too when backgroundReadAvailable is true.
TimoPtr
left a comment
There was a problem hiding this comment.
Adding this would require us to update the App Content policy regarding Health. Could you provide a detail use case of this sensor?
TimoPtr
left a comment
There was a problem hiding this comment.
It lakes the permission in the manifest <uses-permission android:name="android.permission.health.READ_NUTRITION" />
Summary
Add a new Health Connect nutrition sensor to the Android companion app.
This change introduces support for syncing the latest Health Connect
NutritionRecordinto Home Assistant as a sensor entity (health_connect_nutrition) with additional nutrient-related attributes.Motivation:
Impact:
Checklist
Screenshots
N/A - no new custom UI layout was introduced. This PR adds an additional supported Health Connect sensor type within existing system/app flows.
Link to pull request in documentation repositories
User Documentation: home-assistant/companion.home-assistant#N/A
Developer Documentation: home-assistant/developers.home-assistant#N/A
Any other notes
Validation performed locally:
./gradlew :app:testFullDebugUnitTest --tests io.homeassistant.companion.android.sensors.HealthConnectSensorManagerTest✅./gradlew ktlintCheck :build-logic:convention:ktlintCheck --continue✅./gradlew testwas attempted but is currently blocked by pre-existing unrelated local minimal/wear test-classpath issues (for example unresolved Wear/GMS references in existingapp/src/test/.../settings/wear/*tests)