Convert fan platform to asyncio

This commit is contained in:
Pierre Ståhl
2020-10-14 13:45:41 +02:00
committed by rospogrigio
parent 136e44c549
commit 5d64cb4e18

View File

@@ -36,8 +36,8 @@ class LocaltuyaFan(LocalTuyaEntity, FanEntity):
"""Initialize the entity."""
super().__init__(device, config_entry, fanid, **kwargs)
self._is_on = False
self._speed = SPEED_OFF
self._oscillating = False
self._speed = None
self._oscillating = None
@property
def oscillating(self):
@@ -59,36 +59,34 @@ class LocaltuyaFan(LocalTuyaEntity, FanEntity):
"""Get the list of available speeds."""
return [SPEED_OFF, SPEED_LOW, SPEED_MEDIUM, SPEED_HIGH]
def turn_on(self, speed: str = None, **kwargs) -> None:
async def async_turn_on(self, speed: str = None, **kwargs) -> None:
"""Turn on the entity."""
self._device.set_dps(True, "1")
await self._device.set_dps(True, "1")
if speed is not None:
self.set_speed(speed)
await self.async_set_speed(speed)
else:
self.schedule_update_ha_state()
def turn_off(self, **kwargs) -> None:
async def async_turn_off(self, **kwargs) -> None:
"""Turn off the entity."""
self._device.set_dps(False, "1")
await self._device.set_dps(False, "1")
self.schedule_update_ha_state()
def set_speed(self, speed: str) -> None:
async def async_set_speed(self, speed: str) -> None:
"""Set the speed of the fan."""
self._speed = speed
if speed == SPEED_OFF:
self._device.set_dps(False, "1")
await self._device.set_dps(False, "1")
elif speed == SPEED_LOW:
self._device.set_dps("1", "2")
await self._device.set_dps("1", "2")
elif speed == SPEED_MEDIUM:
self._device.set_dps("2", "2")
await self._device.set_dps("2", "2")
elif speed == SPEED_HIGH:
self._device.set_dps("3", "2")
await self._device.set_dps("3", "2")
self.schedule_update_ha_state()
def oscillate(self, oscillating: bool) -> None:
async def async_oscillate(self, oscillating: bool) -> None:
"""Set oscillation."""
self._oscillating = oscillating
self._device.set_value("8", oscillating)
await self._device.set_dps(oscillating, "8")
self.schedule_update_ha_state()
@property