Skip to content

fix(predheat): say in the log when Predheat is disabled (#4670) - #4700

Merged
springfall2008 merged 2 commits into
mainfrom
fix/predheat-silent-when-disabled
Aug 24, 2026
Merged

fix(predheat): say in the log when Predheat is disabled (#4670)#4700
springfall2008 merged 2 commits into
mainfrom
fix/predheat-silent-when-disabled

Conversation

@springfall2008

Copy link
Copy Markdown
Owner

Fixes #4670

Problem

Predheat initialises, logs Predheat: Startup and Predheat: Next run time will be ... and then every 300 seconds, and is then completely silent forever — no Predheat: update at ..., no predheat.* entities.

Both timer callbacks open with a silent early return:

if not self.get_arg("predheat_enable"):
    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:

Link Result
initialize() registers both timers in run_list ✅ both, run_every 300s
Hass.timer_tick() dispatches them
HA switch event → config value → gate ✅ Predheat ran 3s after the toggle
predheat_enable restored from predbat_config.json across a restart

That leaves the gate as the only thing that can produce total silence, i.e. Predbat's stored predheat_enable is False while Home Assistant's entity displays on — 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.py has had no functional change since April, the only commit since being an ERROR:Error: string tidy.

Change

is_enabled() logs each change of state once (not per tick), naming the switch:

Predheat: Disabled - turn on switch.predbat_predheat_enable to run it
Predheat: Enabled via switch.predbat_predheat_enable, will update every 5 minutes

Re-enabling also sets update_pending, so turning the switch on runs Predheat immediately instead of appearing dead for up to run_every minutes.

Tests

First Predheat tests in the repo (./run_all --test predheat) — timer registration, the silent-gate regression, enabling via the real switch_event path, 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

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>
Copilot AI lite review requested due to automatic review settings August 24, 2026 10:58

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 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 predheat unit 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 thread apps/predbat/predheat.py
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():
Comment thread apps/predbat/tests/test_predheat.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@springfall2008
springfall2008 merged commit bcef615 into main Aug 24, 2026
2 checks passed
@springfall2008
springfall2008 deleted the fix/predheat-silent-when-disabled branch August 24, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PredHeat initializes and schedules but update callback never runs in v8.52.0

2 participants