Repository navigation
Use the configured heating system for PID gains and options #193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dajiaohuang
wants to merge
1
commit into
Alexwijn:develop
Choose a base branch
from
dajiaohuang:fix/use-configured-heating-system-20261020
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+61
−6
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| """Configured heating systems must reach controllers and the options form.""" | ||
| import pytest | ||
| from homeassistant.const import UnitOfTemperature | ||
| from pytest_homeassistant_custom_component.common import MockConfigEntry | ||
|
|
||
| from custom_components.sat.climate import SatClimate | ||
| from custom_components.sat.config_flow import SatOptionsFlowHandler | ||
| from custom_components.sat.const import ( | ||
| DOMAIN, CONF_HEATING_SYSTEM, CONF_AUTOMATIC_GAINS, | ||
| CONF_HEATING_CURVE_COEFFICIENT, CONF_ROOMS, CONF_CYCLES_PER_HOUR, | ||
| HEATING_SYSTEM_UNDERFLOOR, HEATING_SYSTEM_RADIATORS, HEATING_SYSTEM_HEAT_PUMP, | ||
| ) | ||
| from custom_components.sat.errors import Error | ||
| from custom_components.sat.fake import SatFakeCoordinator | ||
| from tests.const import DEFAULT_USER_DATA | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("heating_system, expected_kp", [ | ||
| (HEATING_SYSTEM_UNDERFLOOR, 15.0), | ||
| (HEATING_SYSTEM_RADIATORS, 20.0), | ||
| (HEATING_SYSTEM_HEAT_PUMP, 20.0), | ||
| ]) | ||
| @pytest.mark.parametrize("legacy_option", [None, HEATING_SYSTEM_RADIATORS]) | ||
| async def test_climate_and_area_pid_use_setup_system(hass, heating_system, expected_kp, legacy_option): | ||
| data = {**DEFAULT_USER_DATA, CONF_HEATING_SYSTEM: heating_system, CONF_ROOMS: ["climate.room"]} | ||
| options = {CONF_AUTOMATIC_GAINS: True, CONF_HEATING_CURVE_COEFFICIENT: 2.0} | ||
| if legacy_option is not None: | ||
| options[CONF_HEATING_SYSTEM] = legacy_option | ||
| entry = MockConfigEntry(domain=DOMAIN, data=data, options=options) | ||
| coordinator = SatFakeCoordinator(hass, entry.data, entry.options) | ||
| climate = SatClimate(coordinator, entry, UnitOfTemperature.CELSIUS) | ||
|
|
||
| for pid in [climate.pid, climate.areas.pids.areas[0].pid]: | ||
| pid.update_reset(Error("climate.room", 0), 30) | ||
| assert pid.kp == expected_kp | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("heating_system, expected_cycles", [ | ||
| (HEATING_SYSTEM_UNDERFLOOR, None), | ||
| (HEATING_SYSTEM_RADIATORS, ["3", "4"]), | ||
| (HEATING_SYSTEM_HEAT_PUMP, ["2", "3"]), | ||
| ]) | ||
| @pytest.mark.parametrize("legacy_option", [None, HEATING_SYSTEM_RADIATORS]) | ||
| async def test_options_cycles_follow_setup_system(hass, heating_system, expected_cycles, legacy_option): | ||
| options = {} if legacy_option is None else {CONF_HEATING_SYSTEM: legacy_option} | ||
| entry = MockConfigEntry(domain=DOMAIN, data={**DEFAULT_USER_DATA, CONF_HEATING_SYSTEM: heating_system}, options=options) | ||
| flow = SatOptionsFlowHandler(entry) | ||
| flow.hass = hass | ||
| result = await flow.async_step_system_configuration() | ||
| cycle_selector = next((value for key, value in result["data_schema"].schema.items() if key.schema == CONF_CYCLES_PER_HOUR), None) | ||
|
|
||
| if expected_cycles is None: | ||
| assert cycle_selector is None | ||
| else: | ||
| assert [item["value"] for item in cycle_selector.config["options"]] == expected_cycles |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n 670,730p custom_components/sat/config_flow.py rg -n 'CONF_CYCLES_PER_HOUR|OPTIONS_DEFAULTS' custom_components/sat/config_flow.py custom_components/sat/const.pyRepository: Alexwijn/SAT
Length of output: 5756
🏁 Script executed:
Repository: Alexwijn/SAT
Length of output: 9950
Set a valid default for the heat-pump cycle selector.
When a heat-pump entry has no saved
CONF_CYCLES_PER_HOUR,get_options()supplies4. The selector accepts only"2"and"3", so the default"4"can fail validation when the form is submitted. Use an allowed heat-pump default when the saved value is absent or invalid.This became reachable for heat-pump entries whose heating system is stored only in config entry data. The merge base checked
options, so it did not select this branch from config entry data alone.🐛 Suggested fix
🤖 Prompt for AI Agents