Commit bd74589
[switch] Persist the state when a restore mode is switched on at run time (#69)
A switch whose Start mode is changed to "Last" from the dashboard or the
front-panel menu came back at the mode's default after a reboot instead of
where it was left.
publish_state() is the only writer of rtc_ and it drops duplicates, so the
update() that follows set_restore_mode() stored nothing when the state had
not changed. And under JETHOME_DYNAMIC_ENTITY_SETTINGS rtc_ was created
inside get_initial_state(), which get_initial_state_with_restore_mode() only
calls for a persistent mode - so a switch that booted as ALWAYS_OFF had no
preference to write to in the first place.
set_restore_mode() now stores the current state when persistence goes on and
syncs it, since a mode change is a rare, deliberate act that a user is likely
to power-cycle right after. The preference is created whatever the mode is.
Before setup() rtc_ has no backend, save() fails and nothing is written, so
the boot-time apply of stored settings cannot overwrite the state it is about
to restore.
Verified under QEMU on jxd-r6-e1eth-lcd, over both paths (dashboard and the
front-panel menu) and against a control build without the fix.
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent d8e7dda commit bd74589
2 files changed
Lines changed: 19 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
34 | 44 | | |
35 | 45 | | |
36 | 46 | | |
| |||
48 | 58 | | |
49 | 59 | | |
50 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
51 | 65 | | |
52 | 66 | | |
53 | 67 | | |
54 | 68 | | |
55 | 69 | | |
56 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
57 | 73 | | |
58 | 74 | | |
59 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
| 128 | + | |
| 129 | + | |
129 | 130 | | |
130 | 131 | | |
131 | 132 | | |
| |||
0 commit comments