From 8e48d2c9818a71417e5b308b97c9313bb35e2cd7 Mon Sep 17 00:00:00 2001 From: brefra Date: Sun, 22 Mar 2020 12:09:43 +0100 Subject: [PATCH 1/2] Fix light control --- homeassistant/components/velbus/light.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/velbus/light.py b/homeassistant/components/velbus/light.py index d428b766edca30..7d4404b6e7f8a5 100644 --- a/homeassistant/components/velbus/light.py +++ b/homeassistant/components/velbus/light.py @@ -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.""" @@ -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 0 < kwargs[ATTR_BRIGHTNESS] < 3: + brightness = 1 + else: + brightness = int((kwargs[ATTR_BRIGHTNESS] * 100) / 255) attr, *args = ( "set_dimmer_state", self._channel, - kwargs[ATTR_BRIGHTNESS], + brightness, kwargs.get(ATTR_TRANSITION, 0), ) else: From b0069aaf04a1cbcaac3092861eaac85d99bfb91b Mon Sep 17 00:00:00 2001 From: brefra Date: Tue, 24 Mar 2020 20:25:26 +0100 Subject: [PATCH 2/2] Optimize conversion logic --- homeassistant/components/velbus/light.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/velbus/light.py b/homeassistant/components/velbus/light.py index 7d4404b6e7f8a5..d7654feab2d736 100644 --- a/homeassistant/components/velbus/light.py +++ b/homeassistant/components/velbus/light.py @@ -81,10 +81,10 @@ def turn_on(self, **kwargs): else: if ATTR_BRIGHTNESS in kwargs: # Make sure a low but non-zero value is not rounded down to zero - if 0 < kwargs[ATTR_BRIGHTNESS] < 3: - brightness = 1 + if kwargs[ATTR_BRIGHTNESS] == 0: + brightness = 0 else: - brightness = int((kwargs[ATTR_BRIGHTNESS] * 100) / 255) + brightness = max(int((kwargs[ATTR_BRIGHTNESS] * 100) / 255), 1) attr, *args = ( "set_dimmer_state", self._channel,