Fix settings update issue by making SensorSetting immutable - #7117
Conversation
5b110af to
8c3a9c2
Compare
302033e to
442927a
Compare
8c3a9c2 to
c870331
Compare
442927a to
7eaa35d
Compare
c870331 to
1ae01d7
Compare
7eaa35d to
c26cb81
Compare
c26cb81 to
1944254
Compare
jpelgrom
left a comment
There was a problem hiding this comment.
Tested and this correctly fixes the issue. Thanks for the fix!
| private const val SENSOR_SETTING_TRANS_KEY_PREFIX = "sensor_setting_" | ||
|
|
||
| // Keep the database-backed flows hot briefly across config changes before stopping collection. | ||
| private const val STOP_TIMEOUT_MILLIS = 5_000L |
There was a problem hiding this comment.
You can use a duration here instead of millis which should be preferred. 5 seconds also feels very long for configuration changes.
(This also needs updated imports so simply accepting suggestion won't work)
| private const val STOP_TIMEOUT_MILLIS = 5_000L | |
| private val STOP_TIMEOUT = 1.seconds |
There was a problem hiding this comment.
I'm ashamed ... I used claude for this and I didn't even see that it was not following the convention I wrote... 🥹
There was a problem hiding this comment.
I also made it 500ms like we had in other places.
1944254 to
ce2b954
Compare
There was a problem hiding this comment.
Pull request overview
This PR addresses a regression where sensor setting changes were not reflected in the Compose UI after recent immutability changes, by making SensorSetting immutable and switching the sensor detail screen to consume database-backed StateFlows.
Changes:
- Make
SensorSetting.valueimmutable (var→val) - Refactor
SensorDetailViewModelto exposeStateFlowfor sensors and sensor settings (viastateIn) - Update
SensorDetailViewto collect these flows usingcollectAsStateWithLifecycleand update dialog submission to usecopy(...)
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| common/src/main/kotlin/io/homeassistant/companion/android/database/sensor/SensorSetting.kt | Makes sensor setting values immutable to ensure state updates propagate via new instances |
| app/src/main/kotlin/io/homeassistant/companion/android/settings/sensor/views/SensorDetailView.kt | Collects StateFlow values in Compose and updates setting submission to use immutable copies |
| app/src/main/kotlin/io/homeassistant/companion/android/settings/sensor/SensorDetailViewModel.kt | Exposes sensors/settings as StateFlow backed by database flows using stateIn |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Summary
The sensor settings update where not showing as per @jpelgrom found out #7041 (comment) with the recent changes we've made.
I've fixed it by making SensorSetting immutable and exposing StateFlow for it. The issue was that now that the sensor is immutable the way we've updated the Settings it was not triggering a change on the compose side because the object itself was still the same reference.
Checklist
Any other notes
Based on #7041