fix(predheat): say in the log when Predheat is disabled (#4670) - #4700
Merged
Conversation
Both Predheat timer callbacks returned silently when predheat_enable was off. A disabled Predheat therefore logged its startup banner, its "Next run time will be ..." line, and then nothing at all - indistinguishable in the log from a scheduler that never fires, which is exactly how #4670 was reported. Route both gates through a new is_enabled() that logs each change of state once, naming the switch to turn on. Re-enabling also sets update_pending so Predheat runs straight away rather than looking dead until the next run_every boundary. Adds the first Predheat tests: timer registration, the silent-gate regression, enabling through the real switch_event path, and the prompt re-enable. Also documents the symptom in docs/predheat.md. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new Predheat test helper uses datetime.now() for next_time even though timer_tick() requires now > next_time, which can make the test timing-dependent and should be made deterministic.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR improves Predheat operability by making “Predheat disabled” explicitly visible in logs (so it’s distinguishable from a broken scheduler) and adds initial regression tests to cover the enable/disable gate and scheduler behavior.
Changes:
- Add
PredHeat.is_enabled()to log enable/disable transitions once and request a prompt update when re-enabled. - Add a new
predheatunit test covering timer registration, the silent-gate regression, and switch-event enable/disable behavior. - Update Predheat documentation to explain the enable switch behavior and how to diagnose switch desync.
File summaries
| File | Description |
|---|---|
| docs/predheat.md | Documents the “configured but disabled” log behavior and troubleshooting steps. |
| apps/predbat/predheat.py | Adds state-transition logging for predheat_enable and triggers prompt updates on re-enable. |
| apps/predbat/unit_test.py | Registers the new predheat test in the test runner. |
| apps/predbat/tests/test_predheat.py | Introduces tests for scheduler registration and the predheat_enable gate behavior. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
660
to
+664
| def update_time_loop(self, cb_args): | ||
| """ | ||
| Called every 15 seconds | ||
| """ | ||
| if not self.get_arg("predheat_enable"): | ||
| if not self.is_enabled(): |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4670
Problem
Predheat initialises, logs
Predheat: StartupandPredheat: Next run time will be ... and then every 300 seconds, and is then completely silent forever — noPredheat: update at ..., nopredheat.*entities.Both timer callbacks open with a silent early return:
So "Predheat is switched off" and "Predheat's scheduler is broken" produce byte-for-byte identical logs. There is no way to tell them apart from a log, which is why #4670 could not be resolved from the reporter's evidence.
Root cause of #4670 itself
Every other link in the chain checks out, verified against the real code and on a live add-on instance:
initialize()registers both timers inrun_listrun_every300sHass.timer_tick()dispatches thempredheat_enablerestored frompredbat_config.jsonacross a restartThat leaves the gate as the only thing that can produce total silence, i.e. Predbat's stored
predheat_enableisFalsewhile Home Assistant's entity displayson— the HA toggle never reached Predbat. When it does arrive, the log already records it (switch_event: switch.predbat_predheat_enable = True) and Predheat runs seconds later. The reporter's "restarting returns the switch to OFF" note is the same desync seen from the other side.Not a v8.52.0 regression:
predheat.pyhas had no functional change since April, the only commit since being anERROR:→Error:string tidy.Change
is_enabled()logs each change of state once (not per tick), naming the switch:Re-enabling also sets
update_pending, so turning the switch on runs Predheat immediately instead of appearing dead for up torun_everyminutes.Tests
First Predheat tests in the repo (
./run_all --test predheat) — timer registration, the silent-gate regression, enabling via the realswitch_eventpath, and the prompt re-enable. Confirmed RED before the fix../run_all --quick— 816 passed, 0 failed./run_pre_commit— all hooks passed🤖 Generated with Claude Code