Adjust set_percentage routine in fans (#73837)

This commit is contained in:
epenet 2022-06-22 18:22:01 +02:00 committed by GitHub
parent 86fde1a644
commit 837957d89e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 6 deletions

View File

@ -67,8 +67,11 @@ class EsphomeFan(EsphomeEntity[FanInfo, FanState], FanEntity):
api_version = self._api_version
return api_version.major == 1 and api_version.minor > 3
async def async_set_percentage(self, percentage: int | None) -> None:
async def async_set_percentage(self, percentage: int) -> None:
"""Set the speed percentage of the fan."""
await self._async_set_percentage(percentage)
async def _async_set_percentage(self, percentage: int | None) -> None:
if percentage == 0:
await self.async_turn_off()
return
@ -95,7 +98,7 @@ class EsphomeFan(EsphomeEntity[FanInfo, FanState], FanEntity):
**kwargs: Any,
) -> None:
"""Turn on the fan."""
await self.async_set_percentage(percentage)
await self._async_set_percentage(percentage)
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn off the fan."""

View File

@ -52,8 +52,11 @@ class SmartThingsFan(SmartThingsEntity, FanEntity):
_attr_supported_features = FanEntityFeature.SET_SPEED
async def async_set_percentage(self, percentage: int | None) -> None:
async def async_set_percentage(self, percentage: int) -> None:
"""Set the speed percentage of the fan."""
await self._async_set_percentage(percentage)
async def _async_set_percentage(self, percentage: int | None) -> None:
if percentage is None:
await self._device.switch_on(set_status=True)
elif percentage == 0:
@ -72,7 +75,7 @@ class SmartThingsFan(SmartThingsEntity, FanEntity):
**kwargs,
) -> None:
"""Turn the fan on."""
await self.async_set_percentage(percentage)
await self._async_set_percentage(percentage)
async def async_turn_off(self, **kwargs) -> None:
"""Turn the fan off."""

View File

@ -136,15 +136,18 @@ class WemoHumidifier(WemoBinaryStateEntity, FanEntity):
**kwargs: Any,
) -> None:
"""Turn the fan on."""
self.set_percentage(percentage)
self._set_percentage(percentage)
def turn_off(self, **kwargs: Any) -> None:
"""Turn the switch off."""
with self._wemo_call_wrapper("turn off"):
self.wemo.set_state(FanMode.Off)
def set_percentage(self, percentage: int | None) -> None:
def set_percentage(self, percentage: int) -> None:
"""Set the fan_mode of the Humidifier."""
self._set_percentage(percentage)
def _set_percentage(self, percentage: int | None) -> None:
if percentage is None:
named_speed = self._last_fan_on_mode
elif percentage == 0: