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

Bug: Fan service "turn on" not working with preset & percentage set #66

Open
MattFromGer opened this issue Jan 11, 2024 · 4 comments
Open

Comments

@MattFromGer
Copy link

Since HA 2023.12 (or even 2023.11) there have been some changes in HA which prevent the fan "Turn On" service from working with a preset or percentage value.

How to reproduce:
Call the service with preset value set:

service: fan.turn_on
target:
  device_id: 5adf8ffed23712345674236e5e7d84ac5
data:
  preset_mode: Auto

Or like this:

service: fan.turn_on
target:
  device_id: 5adf8ffed23712345674236e5e7d84ac5
data:
  preset_mode: Manual
  percentage: 20

It will produce the following error:

  File "/usr/src/homeassistant/homeassistant/components/fan/__init__.py", line 334, in async_handle_turn_on_service
    await self.async_turn_on(percentage, preset_mode, **kwargs)
  File "/config/custom_components/wellbeing/fan.py", line 120, in async_turn_on
    self._speed = math.floor(percentage_to_ranged_value(self._speed_range, percentage or 10))
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/percentage.py", line 96, in percentage_to_ranged_value
    return scale_to_ranged_value((1, 100), low_high_range, percentage)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/scaling.py", line 50, in scale_to_ranged_value
    return (value - source_offset) * (
            ~~~~~~^~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for -: 'str' and 'int'

In previous HA versions this was working fine!

@androidand
Copy link
Collaborator

I am not sure what has changed in HA. I'm making a PR for adding some functionality to the controls of the air purifiers and will add some handling for incorrect percentage values to async_turn_on as well.

androidand added a commit to androidand/homeassistant-wellbeing that referenced this issue Jan 12, 2024
* Support toggling Ionizer, UILight and SafetyLock
* Add Swedish translation
* Small fix for translations
* Handle incorrect fan speed percentage ( hopefully fixing JohNan#66)

Tested on A9/AX9
JohNan pushed a commit that referenced this issue Jan 12, 2024
* Support toggling Ionizer, UILight and SafetyLock
* Add Swedish translation
* Small fix for translations
* Handle incorrect fan speed percentage ( hopefully fixing #66)

Tested on A9/AX9
@JohNan
Copy link
Owner

JohNan commented Jan 14, 2024

All good now @MattFromGer? If not, reopen the issue.

@JohNan JohNan closed this as completed Jan 14, 2024
@MattFromGer
Copy link
Author

MattFromGer commented Jan 15, 2024

Unfortunately it's not fixed. New error is Invalid percentage value: Manual.
Maybe the order of parameters for the functionasync_turn_on() has changed?

Edit: Maybe this PR in HA is causing the conflicts?

@MattFromGer
Copy link
Author

@JohNan can you reopen the issue please? I don't have permissions to do so

@JohNan JohNan reopened this Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants