Skip to content

Commit

Permalink
Fibaro Light fixes (#18972)
Browse files Browse the repository at this point in the history
* minor fixes to color scaling

* capped input to fibaro on setcolor
  • Loading branch information
pbalogh77 authored and balloob committed Dec 4, 2018
1 parent b65bffd commit 2a0c2d5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
11 changes: 7 additions & 4 deletions homeassistant/components/fibaro.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,14 @@ def call_turn_off(self):

def call_set_color(self, red, green, blue, white):
"""Set the color of Fibaro device."""
color_str = "{},{},{},{}".format(int(red), int(green),
int(blue), int(white))
red = int(max(0, min(255, red)))
green = int(max(0, min(255, green)))
blue = int(max(0, min(255, blue)))
white = int(max(0, min(255, white)))
color_str = "{},{},{},{}".format(red, green, blue, white)
self.fibaro_device.properties.color = color_str
self.action("setColor", str(int(red)), str(int(green)),
str(int(blue)), str(int(white)))
self.action("setColor", str(red), str(green),
str(blue), str(white))

def action(self, cmd, *args):
"""Perform an action on the Fibaro HC."""
Expand Down
18 changes: 11 additions & 7 deletions homeassistant/components/light/fibaro.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ def scaleto255(value):
# depending on device type (e.g. dimmer vs led)
if value > 98:
value = 100
return max(0, min(255, ((value * 256.0) / 100.0)))
return max(0, min(255, ((value * 255.0) / 100.0)))


def scaleto100(value):
"""Scale the input value from 0-255 to 0-100."""
# Make sure a low but non-zero value is not rounded down to zero
if 0 < value < 3:
return 1
return max(0, min(100, ((value * 100.4) / 255.0)))
return max(0, min(100, ((value * 100.0) / 255.0)))


async def async_setup_platform(hass,
Expand Down Expand Up @@ -122,11 +122,11 @@ def _turn_on(self, **kwargs):
self._color = kwargs.get(ATTR_HS_COLOR, self._color)
rgb = color_util.color_hs_to_RGB(*self._color)
self.call_set_color(
int(rgb[0] * self._brightness / 99.0 + 0.5),
int(rgb[1] * self._brightness / 99.0 + 0.5),
int(rgb[2] * self._brightness / 99.0 + 0.5),
int(self._white * self._brightness / 99.0 +
0.5))
round(rgb[0] * self._brightness / 100.0),
round(rgb[1] * self._brightness / 100.0),
round(rgb[2] * self._brightness / 100.0),
round(self._white * self._brightness / 100.0))

if self.state == 'off':
self.set_level(int(self._brightness))
return
Expand Down Expand Up @@ -168,6 +168,10 @@ def _update(self):
# Brightness handling
if self._supported_flags & SUPPORT_BRIGHTNESS:
self._brightness = float(self.fibaro_device.properties.value)
# Fibaro might report 0-99 or 0-100 for brightness,
# based on device type, so we round up here
if self._brightness > 99:
self._brightness = 100
# Color handling
if self._supported_flags & SUPPORT_COLOR and \
'color' in self.fibaro_device.properties and \
Expand Down

0 comments on commit 2a0c2d5

Please sign in to comment.