Convert pytuya to asyncio

This commit is contained in:
Pierre Ståhl
2020-10-01 09:40:12 +02:00
committed by rospogrigio
parent 084b3a741a
commit cad31f1ffe
8 changed files with 457 additions and 308 deletions

View File

@@ -86,12 +86,12 @@ class LocaltuyaLight(LocalTuyaEntity, LightEntity):
supports = supports | SUPPORT_COLOR_TEMP
return supports
def turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs):
"""Turn on or control the light."""
self._device.set_dps(True, self._dps_id)
await self._device.set_dps(True, self._dps_id)
if ATTR_BRIGHTNESS in kwargs:
self._device.set_dps(
await self._device.set_dps(
max(int(kwargs[ATTR_BRIGHTNESS]), 25), self._config.get(CONF_BRIGHTNESS)
)
@@ -104,11 +104,11 @@ class LocaltuyaLight(LocalTuyaEntity, LightEntity):
- (255 / (MAX_MIRED - MIN_MIRED))
* (int(kwargs[ATTR_COLOR_TEMP]) - MIN_MIRED)
)
self._device.set_dps(color_temp, self._config.get(CONF_COLOR_TEMP))
await self._device.set_dps(color_temp, self._config.get(CONF_COLOR_TEMP))
def turn_off(self, **kwargs):
async def async_turn_off(self, **kwargs):
"""Turn Tuya light off."""
self._device.set_dps(False, self._dps_id)
await self._device.set_dps(False, self._dps_id)
def status_updated(self):
"""Device status was updated."""