JohNan / homeassistant-wellbeing

Get the status from your Electrolux devices connected to Wellbeing
MIT License
79 stars 22 forks source link

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

Open MattFromGer opened 8 months ago

MattFromGer commented 8 months ago

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 commented 8 months ago

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.

JohNan commented 8 months ago

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

MattFromGer commented 8 months ago

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 commented 8 months ago

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