Support ZHA light turn_off transition (#19531)

This commit is contained in:
Alexei Chetroi 2018-12-23 06:15:54 -05:00 committed by Martin Hjelmare
parent 0776456b59
commit 5a4e6bbb07

View File

@ -198,8 +198,15 @@ class Light(ZhaEntity, light.Light):
async def async_turn_off(self, **kwargs):
"""Turn the entity off."""
from zigpy.exceptions import DeliveryError
duration = kwargs.get(light.ATTR_TRANSITION)
try:
res = await self._endpoint.on_off.off()
supports_level = self.supported_features & light.SUPPORT_BRIGHTNESS
if duration and supports_level:
res = await self._endpoint.level.move_to_level_with_on_off(
0, duration*10
)
else:
res = await self._endpoint.on_off.off()
_LOGGER.debug("%s was turned off: %s", self.entity_id, res)
except DeliveryError as ex:
_LOGGER.error("%s: Unable to turn the light off: %s",