Skip to content

Avoid all-sensor refresh for sleep-confidence updates - #7753

Open
chipsfromhell wants to merge 3 commits into
home-assistant:mainfrom
chipsfromhell:fix/sleep-confidence-targeted-refresh
Open

chipsfromhell wants to merge 3 commits into
home-assistant:mainfrom
chipsfromhell:fix/sleep-confidence-targeted-refresh

Conversation

@chipsfromhell

Copy link
Copy Markdown

Summary

A sleep-confidence event currently calls updateAllSensors after saving its value. That refreshes unrelated sensor managers, including Health Connect, for each confidence callback.

This changes the callback to request the existing ACTION_UPDATE_SENSOR path for sleep_confidence instead. The confidence value and attributes are still saved before requesting delivery. Normal all-sensor refresh and registration are unchanged.

The targeted path sends changed state or icon values for enabled, registered sensors. It does not force registration or send attribute-only changes. Those retain the existing normal-refresh behaviour. Sleep-segment processing is unchanged, but a combined callback no longer incidentally requests an immediate all-sensor send.

Checklist

  • New or updated tests have been added to cover the changes following the testing guidelines.
  • The code follows the project's code style and best_practices.
  • The changes have been thoroughly tested, and edge cases have been considered.
  • Changes are backward compatible whenever feasible. Any breaking changes are documented in the changelog for users and/or in the code for developers depending on the relevance.
  • I have read the Open Home Foundation 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.

Any other notes

Automated checks:

  • A regression test invokes the production sleep callback and verifies that state and attributes are saved before the targeted broadcast. It fails against the unchanged production callback, then passes with this change.
  • 28 distinct focused unit-test cases pass across the activity, Health Connect, targeted-delivery and normal-refresh tests. These include permission, disabled-sensor, empty-event, unchanged-value and registration controls.
  • ktlint checks pass.
  • Detekt exits successfully but reports unresolved compiler/type-resolution diagnostics that reduce analysis accuracy. This is not a clean type-resolved analysis result.

The code and tests were generated with AI tools and received a separate AI code review. No on-device testing has been performed. This change removes the all-manager refresh request from sleep-confidence callbacks. It does not eliminate all Health Connect permission checks or establish a quota or battery-life improvement.

Copilot AI balanced review requested due to automatic review settings November 1, 2026 12:39

@home-assistant home-assistant Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hello @chipsfromhell,

When attempting to inspect the commits of your pull request for CLA signature status among all authors we encountered commit(s) which were not linked to a GitHub account, thus not allowing us to determine their status(es).

The commits that are missing a linked GitHub account are the following:

Unfortunately, we are unable to accept this pull request until this situation is corrected.

Here are your options:

  1. If you had an email address set for the commit that simply wasn't linked to your GitHub account you can link that email now and it will retroactively apply to your commits. The simplest way to do this is to click the link to one of the above commits and look for a blue question mark in a blue circle in the top left. Hovering over that bubble will show you what email address you used. Clicking on that button will take you to your email address settings on GitHub. Just add the email address on that page and you're all set. GitHub has more information about this option in their help center.

  2. If you didn't use an email address at all, it was an invalid email, or it's one you can't link to your GitHub, you will need to change the authorship information of the commit and your global Git settings so this doesn't happen again going forward. GitHub provides some great instructions on how to change your authorship information in their help center.

    • If you only made a single commit you should be able to run
      git commit --amend --author="Author Name <email@address.com>"
      
      (substituting "Author Name" and "email@address.com" for your actual information) to set the authorship information.
    • If you made more than one commit and the commit with the missing authorship information is not the most recent one you have two options:
      1. You can re-create all commits missing authorship information. This is going to be the easiest solution for developers that aren't extremely confident in their Git and command line skills.
      2. You can use this script that GitHub provides to rewrite history. Please note: this should be used only if you are very confident in your abilities and understand its impacts.
    • Whichever method you choose, I will come by to re-check the pull request once you push the fixes to this branch.

We apologize for this inconvenience, especially since it usually bites new contributors to Home Assistant. We hope you understand the need for us to protect ourselves and the great community we all have built legally. The best thing to come out of this is that you only need to fix this once and it benefits the entire Home Assistant and GitHub community.

Thanks, I look forward to checking this PR again soon! ❤️

@home-assistant
home-assistant Bot marked this pull request as draft November 1, 2026 12:39
@home-assistant

home-assistant Bot commented Nov 1, 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.

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.

🟡 Changes recommended

The targeted update path treats rejected sleep-confidence updates as sent, suppressing retries; it needs failure-state cleanup and regression coverage.

1 open issue
What changed in this PR

This PR routes sleep-confidence callbacks through the existing single-sensor update path, avoiding refreshes of unrelated sensor managers.

Changes:

  • Replaces the all-sensor refresh request with a targeted broadcast after saving confidence data.
  • Adds callback tests for persistence, permissions, disabled sensors, and sleep-segment handling.
  • Adds targeted-delivery tests for enabled, registered, and changed-value filtering.
File Description
common/​src/​test/​kotlin/​io/​homeassistant/​companion/​android/​common/​sensors/​SensorUpdaterTargetedTest.kt Tests targeted delivery filtering and payloads.
app/​src/​testFull/​kotlin/​io/​homeassistant/​companion/​android/​sensors/​ActivitySensorManagerTest.kt Tests sleep callbacks, persistence order, and broadcast behavior.
app/​src/​full/​kotlin/​io/​homeassistant/​companion/​android/​sensors/​ActivitySensorManager.kt Requests targeted sleep-confidence delivery instead of refreshing all sensors.

Review effort: Balanced

// Send sleep confidence immediately without refreshing unrelated sensor managers.
applicationContext.sendBroadcast(
Intent(applicationContext, SensorReceiver::class.java).apply {
action = ACTION_UPDATE_SENSOR
@chipsfromhell
chipsfromhell force-pushed the fix/sleep-confidence-targeted-refresh branch from 06312c1 to f3b79c7 Compare November 1, 2026 12:45

@home-assistant home-assistant Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hi @chipsfromhell

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!

AI-Generated-By: Gwen (Hermes Agent)
Use registration metadata to avoid persisting a missing sensor row's default after a rejected targeted update. Exercise the real repository fallback with mocked DAOs, retaining existing-row reset and per-server success coverage.

AI-Generated-By: Gwen (Hermes Agent)
@chipsfromhell
chipsfromhell marked this pull request as ready for review November 1, 2026 14:16
@home-assistant
home-assistant Bot dismissed stale reviews from themself November 1, 2026 14:16

Stale

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants