Skip to content
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

Add fan support for KNX climate entities #126368

Merged
merged 14 commits into from
Sep 24, 2024

Conversation

somdoron
Copy link
Contributor

@somdoron somdoron commented Sep 20, 2024

Breaking change

Proposed change

Add fan to knx climate device.

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

@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 @somdoron

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!

@home-assistant
Copy link

Hey there @Julius2342, @farmio, @marvin-w, mind taking a look at this pull request as it has been labeled with an integration (knx) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of knx can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign knx Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@farmio
Copy link
Contributor

farmio commented Sep 21, 2024

I was thinking about how to do this configuration in UI.

With free-form integer modes like the current implementations CONF_FAN_PERCENTAGES_MODES it could look something like (but maybe with a number-box instead of a text-box)
Bildschirmfoto 2024-09-21 um 09 31 52
(https://design.home-assistant.io/#components/ha-selector)
when percent mode is selected, whereas steps mode would just show a number-box for max-mode.

If we used CONF_FAN_MAX_STEP for percentage mode as well as for step mode, both would have a number-box for max-mode. In the backend we could use a function to calculate steps from it

 In [5]: def percentage_steps(steps: int) -> list[str]:
   ...:     return [str(int(100/steps*(step+1))) for step in range(steps)]
   ...:

In [8]: percentage_steps(1)
Out[8]: ['100']

In [7]: percentage_steps(2)
Out[7]: ['50', '100']

In [6]: percentage_steps(3)
Out[6]: ['33', '66', '100']

In [9]: percentage_steps(4)
Out[9]: ['25', '50', '75', '100']

In [10]: percentage_steps(5)
Out[10]: ['20', '40', '60', '80', '100']

In [16]: percentage_steps(10)
Out[16]: ['10', '20', '30', '40', '50', '60', '70', '80', '90', '100']

which could also use built-in FAN_HIGH, FAN_LOW, FAN_MEDIUM for <4 steps. Alternatively [f"{int(100/steps*(step+1))} %" ...] to add percent sign.
With that way, it wouldn't be possible for users to define custom percentage modes (like [12, 44, 98, 100] or something like that) but we could possibly provide translations and icon translations for the most common modes.

A third option would be to let users configure key-value pairs instead of a list. This would be the most flexible option.

fan_modes:
  "Low": 20
  "Bit more": 30
  "Medium": 50
  "Blow away": 100

What do you think?

Copy link
Contributor

@farmio farmio left a comment

Choose a reason for hiding this comment

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

Thank you very much for your contribution. 👍
Here are some thoughts and stylistic suggestions.

homeassistant/components/knx/climate.py Outdated Show resolved Hide resolved
homeassistant/components/knx/climate.py Outdated Show resolved Hide resolved
homeassistant/components/knx/climate.py Outdated Show resolved Hide resolved
homeassistant/components/knx/schema.py Outdated Show resolved Hide resolved
homeassistant/components/knx/schema.py Outdated Show resolved Hide resolved
homeassistant/components/knx/climate.py Outdated Show resolved Hide resolved
homeassistant/components/knx/climate.py Outdated Show resolved Hide resolved
@somdoron
Copy link
Contributor Author

@farmio I followed your advice, number of steps apply to both percent and steps.
I added a new configuration field for fan speed mode.

@somdoron
Copy link
Contributor Author

I tested this locally as well with my thermostat. This PR depends on XKNX/xknx#1573 and a release of xknx. I will work on the rest of the checklist in the description.

@farmio farmio mentioned this pull request Sep 23, 2024
19 tasks
@somdoron somdoron marked this pull request as ready for review September 24, 2024 15:46
Copy link
Contributor

@farmio farmio left a comment

Choose a reason for hiding this comment

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

Nice! Thank you very much! 👍

@farmio farmio changed the title Add fan mode support to knx climate Add fan support for KNX climate entities Sep 24, 2024
@farmio farmio merged commit d2d3ab2 into home-assistant:dev Sep 24, 2024
31 checks passed
@farmio farmio added the noteworthy Marks a PR as noteworthy and should be in the release notes (in case it normally would not appear) label Sep 25, 2024
zxdavb pushed a commit to zxdavb/hass that referenced this pull request Sep 25, 2024
* Add fan mode support to knx climate

* fix linting errors

* remove unneeded None protection from CONF_FAN_PERCENTAGES_MODES

* Update homeassistant/components/knx/climate.py

Co-authored-by: Matthias Alphart <[email protected]>

* Update homeassistant/components/knx/climate.py

Co-authored-by: Matthias Alphart <[email protected]>

* Update homeassistant/components/knx/climate.py

Co-authored-by: Matthias Alphart <[email protected]>

* Update homeassistant/components/knx/schema.py

Co-authored-by: Matthias Alphart <[email protected]>

* find closest percentage when not in fan modes

* new field for fan speed mode, max steps apply to both step and percentage

* not picking FAN_OFF when the percentage is closest to zero

* add fan zero mode to support auto mode

* use StrEnum for FanZeroMode

* change default to 'percent'

* fix mypy errors

---------

Co-authored-by: Matthias Alphart <[email protected]>
@github-actions github-actions bot locked and limited conversation to collaborators Sep 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed code-owner-approved has-tests integration: knx new-feature noteworthy Marks a PR as noteworthy and should be in the release notes (in case it normally would not appear) Quality Scale: platinum
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants