mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Fibaro Light fixes (#18972)
* minor fixes to color scaling * capped input to fibaro on setcolor
This commit is contained in:
parent
b65bffd849
commit
2a0c2d5247
@ -303,11 +303,14 @@ class FibaroDevice(Entity):
|
|||||||
|
|
||||||
def call_set_color(self, red, green, blue, white):
|
def call_set_color(self, red, green, blue, white):
|
||||||
"""Set the color of Fibaro device."""
|
"""Set the color of Fibaro device."""
|
||||||
color_str = "{},{},{},{}".format(int(red), int(green),
|
red = int(max(0, min(255, red)))
|
||||||
int(blue), int(white))
|
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.fibaro_device.properties.color = color_str
|
||||||
self.action("setColor", str(int(red)), str(int(green)),
|
self.action("setColor", str(red), str(green),
|
||||||
str(int(blue)), str(int(white)))
|
str(blue), str(white))
|
||||||
|
|
||||||
def action(self, cmd, *args):
|
def action(self, cmd, *args):
|
||||||
"""Perform an action on the Fibaro HC."""
|
"""Perform an action on the Fibaro HC."""
|
||||||
|
@ -27,7 +27,7 @@ def scaleto255(value):
|
|||||||
# depending on device type (e.g. dimmer vs led)
|
# depending on device type (e.g. dimmer vs led)
|
||||||
if value > 98:
|
if value > 98:
|
||||||
value = 100
|
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):
|
def scaleto100(value):
|
||||||
@ -35,7 +35,7 @@ def scaleto100(value):
|
|||||||
# Make sure a low but non-zero value is not rounded down to zero
|
# Make sure a low but non-zero value is not rounded down to zero
|
||||||
if 0 < value < 3:
|
if 0 < value < 3:
|
||||||
return 1
|
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,
|
async def async_setup_platform(hass,
|
||||||
@ -122,11 +122,11 @@ class FibaroLight(FibaroDevice, Light):
|
|||||||
self._color = kwargs.get(ATTR_HS_COLOR, self._color)
|
self._color = kwargs.get(ATTR_HS_COLOR, self._color)
|
||||||
rgb = color_util.color_hs_to_RGB(*self._color)
|
rgb = color_util.color_hs_to_RGB(*self._color)
|
||||||
self.call_set_color(
|
self.call_set_color(
|
||||||
int(rgb[0] * self._brightness / 99.0 + 0.5),
|
round(rgb[0] * self._brightness / 100.0),
|
||||||
int(rgb[1] * self._brightness / 99.0 + 0.5),
|
round(rgb[1] * self._brightness / 100.0),
|
||||||
int(rgb[2] * self._brightness / 99.0 + 0.5),
|
round(rgb[2] * self._brightness / 100.0),
|
||||||
int(self._white * self._brightness / 99.0 +
|
round(self._white * self._brightness / 100.0))
|
||||||
0.5))
|
|
||||||
if self.state == 'off':
|
if self.state == 'off':
|
||||||
self.set_level(int(self._brightness))
|
self.set_level(int(self._brightness))
|
||||||
return
|
return
|
||||||
@ -168,6 +168,10 @@ class FibaroLight(FibaroDevice, Light):
|
|||||||
# Brightness handling
|
# Brightness handling
|
||||||
if self._supported_flags & SUPPORT_BRIGHTNESS:
|
if self._supported_flags & SUPPORT_BRIGHTNESS:
|
||||||
self._brightness = float(self.fibaro_device.properties.value)
|
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
|
# Color handling
|
||||||
if self._supported_flags & SUPPORT_COLOR and \
|
if self._supported_flags & SUPPORT_COLOR and \
|
||||||
'color' in self.fibaro_device.properties and \
|
'color' in self.fibaro_device.properties and \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user