Skip to content

Commit

Permalink
Fix velbus dimming control (home-assistant#33139)
Browse files Browse the repository at this point in the history
* Fix light control

* Optimize conversion logic
  • Loading branch information
brefra authored Mar 24, 2020
1 parent 3f4a7ec commit 46985bb
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions homeassistant/components/velbus/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def is_on(self):
@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."""
Expand All @@ -80,10 +80,15 @@ def turn_on(self, **kwargs):
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:
Expand Down

0 comments on commit 46985bb

Please sign in to comment.