Skip to content

Commit

Permalink
Fan: add additional percentage and preset parameters to async_turn_on
Browse files Browse the repository at this point in the history
Some time ago HA quietly added a fan specific turn_on method that takes
additional parameters.  In 2023.12 they have quietly broken the fallback
to the standard ToggleEntity turn_on that allowed this integration to keep
functioning.

This change is just to quickly resolve the errors that HA 2023.12
upgrade has caused for fan entities, it does not do anything with the
percentage and preset_mode parameters, that will need to be done in the
next release.

Issue #1380 (from discussion #1379)
  • Loading branch information
make-all committed Dec 7, 2023
1 parent c393f94 commit 4e0ab21
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions custom_components/tuya_local/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Setup for different kinds of Tuya fan devices
"""
import logging
from typing import Any

from homeassistant.components.fan import FanEntity, FanEntityFeature

Expand Down Expand Up @@ -66,11 +67,17 @@ def is_on(self):
return self.available
return self._switch_dps.get_value(self._device)

async def async_turn_on(self, **kwargs):
async def async_turn_on(
self,
percentage: int | None = None,
preset_mode: str | None = None,
**kwargs: Any,
):
"""Turn the switch on"""
if self._switch_dps is None:
raise NotImplementedError()
await self._switch_dps.async_set_value(self._device, True)
if self._switch_dps:
await self._switch_dps.async_set_value(self._device, True)
# TODO: handle percentage and preset_mode parameters, and potentially
# other kwargs.

async def async_turn_off(self, **kwargs):
"""Turn the switch off"""
Expand Down

0 comments on commit 4e0ab21

Please sign in to comment.