Percentage and preset mode support for MQTT fan#47944
Percentage and preset mode support for MQTT fan#47944emontnemery merged 29 commits intohome-assistant:devfrom
Conversation
|
I might need some help with updating documentation and defining additional test. |
|
Hey there @home-assistant/core, mind taking a look at this pull request as its been labeled with an integration ( |
|
Some tests are failing, I think it should be possible to make this a non-breaking change. The new code needs to be tested. The tests are in tests/components/mqtt/test_fan.py.
Comment or ping me on discord if you need some more pointers to get started with the tests. PS |
I am still working on the tests to complete them and fixing some code. There is good progress in this. |
|
I have completed and fixed the tests. Where can I sign the CLA, cannot find a link. I will do a PR for the fixes asap. |
|
Looks like still I have to clean op some _LOGGER code. Further tests seem ok. Can some one advise me on this? Can see now not all new code is covered with tests. Perhaps there a simple way check this locally this in the dev container. |
|
Run this to check coverage locally: |
|
@jbouwh You don't allow combining preset modes with percentage although that is allowed by the entity model: https://developers.home-assistant.io/docs/core/entity/fan/ |
|
There are still a few tests needed as you can see, but I will try to fix those today. The only thing I wonder this might be a bug in the core fan integration is the calculation from numeric ranges to percentages to percentages and back. from homeassistant.util.percentage import int_states_in_range, ranged_value_to_percentage, percentage_to_ranged_value
SPEED_RANGE = (1, 255) # off is not included
percentage = ranged_value_to_percentage(SPEED_RANGE, 127)
value_in_range = math.ceil(percentage_to_ranged_value(SPEED_RANGE, 50))If the base is 1 (whiteout off), the functions work fine. But when you select a higher range bottom. The code is not working correct when e.g. the SPEED_RANGE = (80, 1023) |
|
@bdraco can you have a look at #47944 (comment), is it a bug in the base component? |
What is not allowed is combining a percentage_command_topic with preset_mode_command_topic. I will have a look if this can be combined and what will be de consequence of that. |
|
I have fixed the constraint not being able to combine preset modes with percentages. De speed step will be combined with speeds or preset modes if they are combined. I will update the documentation in this PR. The problem with the base component still exists but will only have impact if |
|
Documentation update PR (home-assistant/home-assistant.io#17048) |
emontnemery
left a comment
There was a problem hiding this comment.
Looks good overall 👍
Please fix the comments.
Comment speeds for mqtt fan are deprecated not needed here Co-authored-by: Erik Montnemery <erik@montnemery.com>
Comment speeds for mqtt fan are deprecated not needed here Co-authored-by: Erik Montnemery <erik@montnemery.com>
Comment speeds for mqtt fan are deprecated not needed here Co-authored-by: Erik Montnemery <erik@montnemery.com>
Comment speeds for mqtt fan are deprecated not needed here Co-authored-by: Erik Montnemery <erik@montnemery.com>
You can use This will output 0 for 0% and 12 for 100%. |
Thanks for your response. Are you saying the best way of sending the mqtt speed commands is not directly though yaml and is to make a seperate automation for setting the fan speed? I didn't necessarily want to use templates, I just thought that would be the easiest way of converting a speed of 1 to a tuya send of '2,1' Sorry for the questions, I am just trying to prepare for this awesome change. |
No problem, There might be a good reason to implement a |
|
Let's add support for templates in a separate PR, this one is big enough as it is 👍 |
Co-authored-by: Erik Montnemery <erik@montnemery.com>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
|
Documentation PR home-assistant/home-assistant.io#17048 |
|
I will save with black and commit the changes 👍 |
|
Thanks, @jbouwh, this is a great first PR! 🎉 |
Awesome, and congrats on the awesome pull request. If/when this happens could you link the pull request here? Thanks for you work! |
Breaking change
The fan entity model has been changed. This impacts the way the MQTT Fan supports speeds and the following configuration options are deprecated and will become invalid in core-2021.7.0:
speed_command_topic,speed_state_topic,speed_value_template,speeds,payload_off_speed,payload_low_speed,payload_medium_speed,payload_high_speed.Proposed change
The existing
speedsmechanism that supports the three speeds 'low', 'medium' and 'high' will be replaced with a percentage based speed capability that can be operated using a slider. Using preset modes it is possible to supply a ordered list of speeds supported. The legacyspeedswill keep working for backwards compatibility.New settings are introduced to support controlling the speed using percentage or preset modes.
Settings for percentage based speed control:
offnot included).Settings for preset mode based speed control:
Type of change
Example entry for
configuration.yaml:Additional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
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..coveragerc.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: