Fix Homematic transition function on light devices with multiple channels (#45725)

* Update light.py

Fix Transition function on devices with multiple channels

* Update light.py

fix Flake8 Warning W293 blank line contains whitespace
This commit is contained in:
Michael Cicogna 2021-03-19 12:36:03 +01:00 committed by GitHub
parent 993261e7f5
commit b1626f0091
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,6 +9,7 @@ from homeassistant.components.light import (
SUPPORT_COLOR, SUPPORT_COLOR,
SUPPORT_COLOR_TEMP, SUPPORT_COLOR_TEMP,
SUPPORT_EFFECT, SUPPORT_EFFECT,
SUPPORT_TRANSITION,
LightEntity, LightEntity,
) )
@ -53,7 +54,8 @@ class HMLight(HMDevice, LightEntity):
@property @property
def supported_features(self): def supported_features(self):
"""Flag supported features.""" """Flag supported features."""
features = SUPPORT_BRIGHTNESS features = SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION
if "COLOR" in self._hmdevice.WRITENODE: if "COLOR" in self._hmdevice.WRITENODE:
features |= SUPPORT_COLOR features |= SUPPORT_COLOR
if "PROGRAM" in self._hmdevice.WRITENODE: if "PROGRAM" in self._hmdevice.WRITENODE:
@ -95,7 +97,7 @@ class HMLight(HMDevice, LightEntity):
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
"""Turn the light on and/or change color or color effect settings.""" """Turn the light on and/or change color or color effect settings."""
if ATTR_TRANSITION in kwargs: if ATTR_TRANSITION in kwargs:
self._hmdevice.setValue("RAMP_TIME", kwargs[ATTR_TRANSITION]) self._hmdevice.setValue("RAMP_TIME", kwargs[ATTR_TRANSITION], self._channel)
if ATTR_BRIGHTNESS in kwargs and self._state == "LEVEL": if ATTR_BRIGHTNESS in kwargs and self._state == "LEVEL":
percent_bright = float(kwargs[ATTR_BRIGHTNESS]) / 255 percent_bright = float(kwargs[ATTR_BRIGHTNESS]) / 255
@ -123,6 +125,9 @@ class HMLight(HMDevice, LightEntity):
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
"""Turn the light off.""" """Turn the light off."""
if ATTR_TRANSITION in kwargs:
self._hmdevice.setValue("RAMP_TIME", kwargs[ATTR_TRANSITION], self._channel)
self._hmdevice.off(self._channel) self._hmdevice.off(self._channel)
def _init_data_struct(self): def _init_data_struct(self):