Fix velbus dimming control (#33139)

* Fix light control

* Optimize conversion logic
pull/33225/head
brefra 2020-03-24 21:58:50 +01:00 committed by GitHub
parent 3f4a7ec396
commit 46985bba0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -64,7 +64,7 @@ class VelbusLight(VelbusEntity, Light):
@property
def brightness(self):
"""Return the brightness of the light."""
return self._module.get_dimmer_state(self._channel)
return int((self._module.get_dimmer_state(self._channel) * 255) / 100)
def turn_on(self, **kwargs):
"""Instruct the Velbus light to turn on."""
@ -80,10 +80,15 @@ class VelbusLight(VelbusEntity, Light):
attr, *args = "set_led_state", self._channel, "on"
else:
if ATTR_BRIGHTNESS in kwargs:
# Make sure a low but non-zero value is not rounded down to zero
if kwargs[ATTR_BRIGHTNESS] == 0:
brightness = 0
else:
brightness = max(int((kwargs[ATTR_BRIGHTNESS] * 100) / 255), 1)
attr, *args = (
"set_dimmer_state",
self._channel,
kwargs[ATTR_BRIGHTNESS],
brightness,
kwargs.get(ATTR_TRANSITION, 0),
)
else: