Skip to content

Skip autotune samples when the heating curve is zero - #194

Open
dajiaohuang wants to merge 1 commit into
Alexwijn:developfrom
dajiaohuang:fix/skip-zero-curve-autotune-20261020
Open

dajiaohuang wants to merge 1 commit into
Alexwijn:developfrom
dajiaohuang:fix/skip-zero-curve-autotune-20261020

Conversation

@dajiaohuang

@dajiaohuang dajiaohuang commented Oct 20, 2026 •

Copy link
Copy Markdown

At a target and outside temperature of 20°C the heating-curve term is zero. Autotune divides by that term and raises ZeroDivisionError instead of ignoring a sample from which no coefficient can be inferred.

Return None for that undefined coefficient and skip the autotune sample before changing the derivative or history. Nonzero calculations remain unchanged.

Validation: Python 3.13.16 / Home Assistant 2026.2.3 with the unchanged requirements_test.txt. Six new zero-curve cases fail on the original source; the two nonzero controls pass. All eight pass after the repair, and the independent branch's complete pytest suite passes 15 tests. Cases cover both heating systems, fresh/restored history, and the next valid sample. Tests run in an isolated network namespace with sockets disabled except Unix sockets. No actual device or heating installation was exercised.

Fixes #183.

Summary by CodeRabbit

  • Bug Fixes

    • Prevented heating curve tuning from attempting calculations when the curve value is zero, avoiding division errors.
    • Preserved tuning history and state when no valid coefficient can be calculated.
    • Ensured tuning resumes consistently once valid heating curve values are available.
  • Tests

    • Added coverage for underfloor and radiator heating systems, including zero-value and existing nonzero curve scenarios.

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 68fc4f05-1300-4edb-bcb6-2b3a0f2e57ad
📥 Commits

Reviewing files that changed from the base of the PR and between 7d43560 and fac42d8.

📒 Files selected for processing: 2
  • custom_components/sat/heating_curve.py
  • tests/test_heating_curve.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

Walkthrough

The heating-curve coefficient calculation now returns None when the calculated curve value is zero. Autotune exits without updating its state in that case. Tests cover zero and nonzero curves, including fresh and restored autotune history.

Changes

Heating-curve autotune

Layer / File(s) Summary
Handle zero-valued curves
custom_components/sat/heating_curve.py, tests/test_heating_curve.py
calculate_coefficient returns None for a zero curve, and autotune skips derivative calculation and state updates. Tests cover history preservation and expected nonzero coefficients.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: alexwijn

Merge Risk: ⚪ Minimal · up to fac42

The zero-curve sample can be skipped without interrupting autotuning. No actionable merge-blocking risk remains after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: skipping autotune samples when the heating curve is zero.
Linked Issues check Passed Issue #183 requires safe handling when the heating curve is zero at target and outside temperature 20°C. calculate_coefficient now returns None before division when calculate() returns zero. `au…
Out of Scope Changes check Passed The pull request changes only custom_components/sat/heating_curve.py and adds focused tests in tests/test_heating_curve.py. The implementation and tests directly support issue #183. No unrelated c…
Full details: Linked Issues check

Explanation

Issue #183 requires safe handling when the heating curve is zero at target and outside temperature 20°C. calculate_coefficient now returns None before division when calculate() returns zero. autotune returns before changing the derivative or coefficient history. The added tests cover both heating systems, fresh and restored state, the next valid sample, and unchanged nonzero coefficients.

Full details: Out of Scope Changes check

Explanation

The pull request changes only custom_components/sat/heating_curve.py and adds focused tests in tests/test_heating_curve.py. The implementation and tests directly support issue #183. No unrelated change is shown.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

[BUG] Heating curve autotune divides by zero at a 20°C target and outside temperature

1 participant