Skip to content

Enhance generic_thermostat with min/max run time and cooldown time#136298

Merged
emontnemery merged 13 commits intohome-assistant:devfrom
esand:generic-thermostat-duty
Mar 13, 2026
Merged

Enhance generic_thermostat with min/max run time and cooldown time#136298
emontnemery merged 13 commits intohome-assistant:devfrom
esand:generic-thermostat-duty

Conversation

@esand
Copy link
Copy Markdown
Contributor

@esand esand commented Jan 23, 2025

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

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

Copy link
Copy Markdown
Contributor

@home-assistant home-assistant Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @esand

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@alexfj0
Copy link
Copy Markdown

alexfj0 commented Feb 15, 2025

Thank you for the great work, would really like to see this merged!

@alexfj0
Copy link
Copy Markdown

alexfj0 commented Feb 15, 2025

Its really weird because the generic_hygrostat's minimum cycle duration works differently. with the exact same name and description

@MartinHjelmare MartinHjelmare changed the title Enhance generic_thermostat with min/max run time and cooldown time. Enhance generic_thermostat with min/max run time and cooldown time Feb 23, 2025
@github-actions
Copy link
Copy Markdown

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.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions Bot added the stale label May 20, 2025
@esand
Copy link
Copy Markdown
Contributor Author

esand commented May 21, 2025

Will work on rebasing and also see about creating some tests (now that I know a bit about how to do that).

@github-actions github-actions Bot removed the stale label May 21, 2025
@esand esand marked this pull request as draft June 11, 2025 12:49
@esand
Copy link
Copy Markdown
Contributor Author

esand commented Jun 11, 2025

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.

@emontnemery
Copy link
Copy Markdown
Contributor

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.

@github-actions
Copy link
Copy Markdown

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.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions Bot added the stale label Aug 25, 2025
@esand
Copy link
Copy Markdown
Contributor Author

esand commented Aug 26, 2025

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.

@emontnemery
Copy link
Copy Markdown
Contributor

Working on it mr bot.

Please feel free to message me on Discord if you need any help with the tests

I did merge all upstream changes and resolved conflicts. Might not be pretty, but that's git's fault.

We squash before merge, so it doesn't matter if there are a lot of merge commits etc.

@github-actions github-actions Bot removed the stale label Aug 27, 2025
@github-actions
Copy link
Copy Markdown

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.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions Bot added the stale label Dec 20, 2025
Comment thread homeassistant/components/generic_thermostat/climate.py Outdated
Comment thread homeassistant/components/generic_thermostat/climate.py Outdated
@esand esand marked this pull request as ready for review March 10, 2026 00:09
Copilot AI review requested due to automatic review settings March 10, 2026 00:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) and cycle_cooldown (minimum off-time) to the generic thermostat logic and configuration.
  • Update config entry migration to copy the legacy min_cycle_duration into cycle_cooldown for 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.

Comment on lines 118 to 120
CONFIG_FLOW = {
"user": SchemaFlowFormStep(vol.Schema(CONFIG_SCHEMA), next_step="presets"),
"presets": SchemaFlowFormStep(vol.Schema(PRESETS_SCHEMA)),
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't my code; can someone validate that this is a legit concern/issue that should be addressed (in a separate PR)?

Comment thread homeassistant/components/generic_thermostat/strings.json Outdated
Comment thread homeassistant/components/generic_thermostat/climate.py
Comment thread homeassistant/components/generic_thermostat/climate.py
Comment thread homeassistant/components/generic_thermostat/climate.py
@esand
Copy link
Copy Markdown
Contributor Author

esand commented Mar 10, 2026

As an FYI - I plan on updating the remaining original test that calls freeze_time() in a separate PR.
I will also see about porting some or all of the changes in this PR into generic_hygrostat so that it maintains feature parity (and it shouldn't take me as long to do that one as this PR did 😄).

Copy link
Copy Markdown
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please improve the comment about context, maybe as per my suggestion, and address the remaining bot comments.

After that, this can be merged 👍

Comment thread homeassistant/components/generic_thermostat/climate.py Outdated
Copy link
Copy Markdown
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with the code now, but there's some lack of test coverage

Comment thread homeassistant/components/generic_thermostat/climate.py
Copilot AI review requested due to automatic review settings March 13, 2026 13:15
emontnemery

This comment was marked as duplicate.

@home-assistant home-assistant Bot marked this pull request as draft March 13, 2026 13:20
@home-assistant
Copy link
Copy Markdown
Contributor

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

Copy link
Copy Markdown
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks @esand 👍

@emontnemery emontnemery marked this pull request as ready for review March 13, 2026 13:22
@home-assistant home-assistant Bot requested a review from emontnemery March 13, 2026 13:22
@emontnemery emontnemery merged commit fab4355 into home-assistant:dev Mar 13, 2026
33 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Comment thread homeassistant/components/generic_thermostat/climate.py


CONFIG_FLOW = {
"user": SchemaFlowFormStep(vol.Schema(CONFIG_SCHEMA), next_step="presets"),
Comment thread homeassistant/components/generic_thermostat/climate.py
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants