Skip to content

Extract SensorReceiverBase update logic into SensorUpdater - #7107

Merged
TimoPtr merged 5 commits into
mainfrom
feature/rework_sensor_worker_receiver
Jul 2, 2026
Merged

Extract SensorReceiverBase update logic into SensorUpdater#7107
TimoPtr merged 5 commits into
mainfrom
feature/rework_sensor_worker_receiver

Conversation

@TimoPtr

@TimoPtr TimoPtr commented Jun 30, 2026

Copy link
Copy Markdown
Member

Summary

This PR is a wider refactor required to merge at the same time as #7106 and #7040, it fixes issues where we were using SensorReceiver instance, we shouldn't because it's android components instantiated by the system. To achieve that I had to modify the bluetooth manager and remove the companion function that are now within the manager directly, so that we can use a new SensorUpdater. The SensorUpdater is a class that we can inject and use to require an update of sensors.
I had also to move the stop of the beacon into its own receiver it was mixed within the SensorReceiver.

Overall it simplifies a bit the code by removing some parameters and split responsibilities, I did add some very basic tests but it doesn't cover everything in the SensorUpdater.

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.

Any other notes

We could merge this one onto the base one if we want only one commit.

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

This PR refactors sensor update/sync responsibilities by extracting the SensorReceiverBase update logic into a new injectable SensorUpdater, removing reliance on system-instantiated receiver instances, and separating beacon stop handling into a dedicated receiver.

Changes:

  • Introduce SensorUpdater and route broadcast/worker-driven updates through it.
  • Consolidate periodic sensor WorkManager logic into common and remove app/wear wrapper workers.
  • Move beacon “Disable” notification action handling into StopBeaconScanningReceiver, and rework Bluetooth update triggers to avoid broadcasting to removed receivers.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
wear/src/main/kotlin/io/homeassistant/companion/android/sensors/WearSensorModule.kt Provides wear-specific SensorSettingsIntentProvider for permission-missing notifications
wear/src/main/kotlin/io/homeassistant/companion/android/sensors/SensorWorker.kt Removed wear wrapper worker in favor of common worker
wear/src/main/kotlin/io/homeassistant/companion/android/sensors/SensorReceiver.kt Simplifies wear receiver; delegates update logic to base/updater
wear/src/main/kotlin/io/homeassistant/companion/android/notifications/MessagingManager.kt Updates device command wiring to new Bluetooth command APIs
wear/src/main/kotlin/io/homeassistant/companion/android/home/HomeActivity.kt Switches to using common SensorWorker
common/src/test/kotlin/io/homeassistant/companion/android/common/sensors/SensorUpdaterTest.kt Adds basic unit tests for SensorUpdater update entrypoints
common/src/test/kotlin/io/homeassistant/companion/android/common/CommonTestModule.kt Adds test binding for SensorSettingsIntentProvider
common/src/main/kotlin/io/homeassistant/companion/android/common/sensors/StopBeaconScanningReceiver.kt New receiver dedicated to stopping beacon scanning from notification action
common/src/main/kotlin/io/homeassistant/companion/android/common/sensors/SensorWorker.kt Replaces SensorWorkerBase with concrete worker + start() scheduling
common/src/main/kotlin/io/homeassistant/companion/android/common/sensors/SensorUpdateReceiver.kt Removed common-module update receiver
common/src/main/kotlin/io/homeassistant/companion/android/common/sensors/SensorUpdater.kt New central implementation of update + per-server sync/registration logic
common/src/main/kotlin/io/homeassistant/companion/android/common/sensors/SensorReceiverBase.kt Delegates update paths to SensorUpdater and removes embedded sync logic
common/src/main/kotlin/io/homeassistant/companion/android/common/sensors/BluetoothSensorManager.kt Moves enable/disable helpers into manager and triggers Bluetooth-only sync via updater
common/src/main/kotlin/io/homeassistant/companion/android/common/notifications/DeviceCommands.kt Updates BLE/beacon device commands to call Bluetooth manager directly
common/src/main/kotlin/io/homeassistant/companion/android/common/bluetooth/ble/MonitoringManager.kt Updates “Disable” action to target the new stop-scanning receiver
common/src/main/kotlin/io/homeassistant/companion/android/common/bluetooth/ble/IBeaconMonitor.kt Removes need for Context in beacon updates; triggers Bluetooth-only sync via manager
common/src/main/AndroidManifest.xml Removes SensorUpdateReceiver registration; registers StopBeaconScanningReceiver
app/src/test/kotlin/io/homeassistant/companion/android/launch/LaunchActivityTest.kt Switches to using common SensorWorker import
app/src/main/kotlin/io/homeassistant/companion/android/webview/WebViewActivity.kt Switches to using common SensorWorker import
app/src/main/kotlin/io/homeassistant/companion/android/sensors/SensorWorker.kt Removed app wrapper worker in favor of common worker
app/src/main/kotlin/io/homeassistant/companion/android/sensors/SensorReceiver.kt Simplifies app receiver; delegates update logic to base/updater
app/src/main/kotlin/io/homeassistant/companion/android/sensors/AppSensorModule.kt Provides app-specific SensorSettingsIntentProvider for permission-missing notifications
app/src/main/kotlin/io/homeassistant/companion/android/notifications/MessagingManager.kt Updates device command wiring to new Bluetooth command APIs
app/src/main/kotlin/io/homeassistant/companion/android/launch/LaunchActivity.kt Switches to using common SensorWorker

@TimoPtr TimoPtr mentioned this pull request Jun 30, 2026
4 tasks
@TimoPtr
TimoPtr force-pushed the feature/remove_database_entrypoint branch from f389973 to 96d87fb Compare June 30, 2026 14:13
@TimoPtr
TimoPtr force-pushed the feature/rework_sensor_worker_receiver branch from eafad21 to 46d86fb Compare June 30, 2026 14:13
@TimoPtr
TimoPtr force-pushed the feature/remove_database_entrypoint branch from 96d87fb to d87a5fa Compare July 1, 2026 10:11
@TimoPtr
TimoPtr force-pushed the feature/rework_sensor_worker_receiver branch from 46d86fb to 845bdd3 Compare July 1, 2026 10:11

@jpelgrom jpelgrom 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.

Already tested functionality with previous PRs, as the other sensor PRs need this to build. Only one minor comment about the use of "update" which now can mean two things.

Copilot/Lint can be ignored for now as you've copied it, I would like to avoid any functional changes we don't need.

@TimoPtr TimoPtr mentioned this pull request Jul 1, 2026
@TimoPtr
TimoPtr requested a review from jpelgrom July 1, 2026 14:29
@TimoPtr
TimoPtr force-pushed the feature/remove_database_entrypoint branch from d87a5fa to 581bdf2 Compare July 2, 2026 09:05
@TimoPtr
TimoPtr force-pushed the feature/rework_sensor_worker_receiver branch 2 times, most recently from 835ac9d to 7a727d4 Compare July 2, 2026 09:43
Base automatically changed from feature/remove_database_entrypoint to main July 2, 2026 10:08
@TimoPtr
TimoPtr force-pushed the feature/rework_sensor_worker_receiver branch from 7a727d4 to e2f5a72 Compare July 2, 2026 10:10
@TimoPtr
TimoPtr enabled auto-merge (squash) July 2, 2026 10:11
@TimoPtr
TimoPtr disabled auto-merge July 2, 2026 11:17
@TimoPtr
TimoPtr merged commit 2c3406f into main Jul 2, 2026
20 of 22 checks passed
@TimoPtr
TimoPtr deleted the feature/rework_sensor_worker_receiver branch July 2, 2026 11:17
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.

4 participants