Update fan.py
Changes: Changed set_speed in turn_on method Changed set_percentage method for better flow Logger changes
This commit is contained in:
@@ -104,19 +104,18 @@ class LocaltuyaFan(LocalTuyaEntity, FanEntity):
|
|||||||
"""Return the current percentage."""
|
"""Return the current percentage."""
|
||||||
return self._percentage
|
return self._percentage
|
||||||
|
|
||||||
async def async_turn_on(self, speed: str = None, **kwargs) -> None:
|
async def async_turn_on(self, percentage: str = None, **kwargs) -> None:
|
||||||
"""Turn on the entity."""
|
"""Turn on the entity."""
|
||||||
_LOGGER.debug("Fan async_turn_on")
|
_LOGGER.debug("Fan async_turn_on")
|
||||||
await self._device.set_dp(True, self._dp_id)
|
await self._device.set_dp(True, self._dp_id)
|
||||||
if speed is not None:
|
if percentage is not None:
|
||||||
await self.async_set_speed(speed)
|
await self.async_set_percentage(speed)
|
||||||
else:
|
else:
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs) -> None:
|
async def async_turn_off(self, **kwargs) -> None:
|
||||||
"""Turn off the entity."""
|
"""Turn off the entity."""
|
||||||
|
_LOGGER.debug("Fan async_turn_off")
|
||||||
_LOGGER.debug("Fan async_turn_on")
|
|
||||||
|
|
||||||
await self._device.set_dp(False, self._dp_id)
|
await self._device.set_dp(False, self._dp_id)
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
@@ -126,13 +125,12 @@ class LocaltuyaFan(LocalTuyaEntity, FanEntity):
|
|||||||
|
|
||||||
_LOGGER.debug("Fan async_set_percentage: %s", percentage)
|
_LOGGER.debug("Fan async_set_percentage: %s", percentage)
|
||||||
|
|
||||||
if percentage == 0:
|
|
||||||
return await self.async_turn_off()
|
|
||||||
|
|
||||||
if not self.is_on:
|
|
||||||
await self.async_turn_on()
|
|
||||||
|
|
||||||
if percentage is not None:
|
if percentage is not None:
|
||||||
|
if percentage == 0:
|
||||||
|
return await self.async_turn_off()
|
||||||
|
elif not self.is_on:
|
||||||
|
await self.async_turn_on()
|
||||||
if self._use_ordered_list:
|
if self._use_ordered_list:
|
||||||
await self._device.set_dp(
|
await self._device.set_dp(
|
||||||
str(
|
str(
|
||||||
@@ -150,6 +148,7 @@ class LocaltuyaFan(LocalTuyaEntity, FanEntity):
|
|||||||
self._config.get(CONF_FAN_SPEED_CONTROL)
|
self._config.get(CONF_FAN_SPEED_CONTROL)
|
||||||
)
|
)
|
||||||
_LOGGER.debug("Fan async_set_percentage: %s > %s", percentage, percentage_to_ranged_value(self._speed_range, percentage))
|
_LOGGER.debug("Fan async_set_percentage: %s > %s", percentage, percentage_to_ranged_value(self._speed_range, percentage))
|
||||||
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
|
|
||||||
async def async_oscillate(self, oscillating: bool) -> None:
|
async def async_oscillate(self, oscillating: bool) -> None:
|
||||||
@@ -230,7 +229,6 @@ class LocaltuyaFan(LocalTuyaEntity, FanEntity):
|
|||||||
|
|
||||||
if value == self._config.get(CONF_FAN_DIRECTION_REV):
|
if value == self._config.get(CONF_FAN_DIRECTION_REV):
|
||||||
self._direction = DIRECTION_REVERSE
|
self._direction = DIRECTION_REVERSE
|
||||||
|
|
||||||
_LOGGER.debug("Fan current_direction : %s > %s", value, self._direction)
|
_LOGGER.debug("Fan current_direction : %s > %s", value, self._direction)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user