Enhance generic_thermostat with min/max run time and cooldown time#136298
Enhance generic_thermostat with min/max run time and cooldown time#136298emontnemery merged 13 commits intohome-assistant:devfrom
Conversation
|
Thank you for the great work, would really like to see this merged! |
|
Its really weird because the generic_hygrostat's minimum cycle duration works differently. with the exact same name and description |
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
|
Will work on rebasing and also see about creating some tests (now that I know a bit about how to do that). |
|
Some tests are failing & new tests should possibly be created. Knowing now how to somewhat design and alter tests, I will work on resolving the failing tests and review the need for additional tests to test new features. |
If you need some help with the test, feel free to message me on Discord, I'm @emontnemery there too. |
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
|
Working on it mr bot. I didn't rebase, but I did merge all upstream changes and resolved conflicts. Might not be pretty, but that's git's fault. |
Please feel free to message me on Discord if you need any help with the tests
We squash before merge, so it doesn't matter if there are a lot of merge commits etc. |
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
There was a problem hiding this comment.
Pull request overview
This PR enhances the generic_thermostat integration to support duty-cycle style control by introducing a cooldown period and a maximum run time, and by repurposing the existing minimum cycle duration into a minimum run time with updated migration and UI strings.
Changes:
- Add
max_cycle_duration(maximum run time) andcycle_cooldown(minimum off-time) to the generic thermostat logic and configuration. - Update config entry migration to copy the legacy
min_cycle_durationintocycle_cooldownfor backward-compatible behavior. - Extend and adjust test coverage for migration and new timing behaviors.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
homeassistant/components/generic_thermostat/climate.py |
Implements min run time, max run time shutoff scheduling, and cooldown gating in control logic. |
homeassistant/components/generic_thermostat/config_flow.py |
Adds new duration options/selectors and validates min/max relationship (currently options flow only). |
homeassistant/components/generic_thermostat/const.py |
Introduces constants for the new configuration keys. |
homeassistant/components/generic_thermostat/__init__.py |
Migrates pre-1.3 entries by setting cycle_cooldown from the legacy min_cycle_duration. |
homeassistant/components/generic_thermostat/strings.json |
Updates labels/descriptions and adds an options validation error string. |
tests/components/generic_thermostat/test_climate.py |
Adds tests for max run time shutoff, cooldown default, and external-toggle timer cancellation; updates tolerance behavior expectation. |
tests/components/generic_thermostat/test_init.py |
Updates migration version assertions and adds a migration test for 1.2 → 1.3 cooldown copy. |
| CONFIG_FLOW = { | ||
| "user": SchemaFlowFormStep(vol.Schema(CONFIG_SCHEMA), next_step="presets"), | ||
| "presets": SchemaFlowFormStep(vol.Schema(PRESETS_SCHEMA)), |
There was a problem hiding this comment.
The min/max run time validation is only applied in the options flow. As a result, an invalid initial configuration (min >= max) can be created via the main config flow and only later rejected when editing options. Consider applying the same validate_user_input to the config flow "user" step as well so invalid entries can’t be created.
There was a problem hiding this comment.
This isn't my code; can someone validate that this is a legit concern/issue that should be addressed (in a separate PR)?
|
As an FYI - I plan on updating the remaining original test that calls |
emontnemery
left a comment
There was a problem hiding this comment.
Please improve the comment about context, maybe as per my suggestion, and address the remaining bot comments.
After that, this can be merged 👍
emontnemery
left a comment
There was a problem hiding this comment.
I'm fine with the code now, but there's some lack of test coverage
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
emontnemery
left a comment
There was a problem hiding this comment.
Great, thanks @esand 👍
|
|
||
|
|
||
| CONFIG_FLOW = { | ||
| "user": SchemaFlowFormStep(vol.Schema(CONFIG_SCHEMA), next_step="presets"), |
Proposed change
The generic_thermostat has a minimum cycle duration that only reacts to temp change events and doesn't prevent the thermostat from being toggled without delay. The description provided with said setting is also misleading and doesn't convey that it is only effective for temp changes.
This change repurposes and enhances the minimum cycle duration setting (renamed to minimum run time) and introduces two new settings to the generic_thermostat. In all, the three main changes are that there is now a minimum run time, maximum run time, and a cooldown time setting.
The minimum run time setting ensures that once the generic_thermostat is on, it must stay on until at least the specified time has passed. The maximum run time setting does something similar and ensures that the thermostat cannot stay on for more than the configured time. Finally, the cooldown time setting ensures that the specified amount of time is passed in an off state before being turned on again.
The purpose to these settings is to introduce duty cycle type features to the generic_thermostat, as all sorts of devices could be attached to it that may require such control (to ensure safety and lifespan of the devices).
These changes are backwards compatible - it will migrate an existing minimum cycle duration setting to the new minimum run time and cooldown time (effectively providing similar functionality).
These new settings only affect the generic_thermostat control itself for changing state between on and off; it does not prevent the attached switch device from being manually controlled if required.
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
Will create a documentation PR once this code PR is reviewed and ready to be accepted. Documentation changes made in https://github.com/esand/home-assistant.io/tree/generic-thermostat-duty
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: