Fix Hue brightness values over 127 off by one (#34190)

This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2020-04-14 13:31:38 +02:00
1 parent 91d35c7c5c
commit 6fa29d6e2e
2 files changed
+22 -9

No files matched your search

+16 -3
View File
@@ -184,6 +184,16 @@ def async_update_items(bridge, api, current, async_add_entities, create_item):
async_add_entities(new_items)
def hue_brightness_to_hass(value):
"""Convert hue brightness 1..254 to hass format 0..255."""
return min(255, round((value / 254) * 255))
def hass_to_hue_brightness(value):
"""Convert hass brightness 0..255 to hue 1..254 scale."""
return max(1, round((value / 255) * 254))
class HueLight(Light):
"""Representation of a Hue light."""
@@ -245,8 +255,11 @@ class HueLight(Light):
def brightness(self):
"""Return the brightness of this light between 0..255."""
if self.is_group:
return self.light.action.get("bri")
return self.light.state.get("bri")
bri = self.light.action.get("bri")
else:
bri = self.light.state.get("bri")
return hue_brightness_to_hass(bri)
@property
def _color_mode(self):
@@ -372,7 +385,7 @@ class HueLight(Light):
command["ct"] = max(self.min_mireds, min(temp, self.max_mireds))
if ATTR_BRIGHTNESS in kwargs:
command["bri"] = kwargs[ATTR_BRIGHTNESS]
command["bri"] = hass_to_hue_brightness(kwargs[ATTR_BRIGHTNESS])
flash = kwargs.get(ATTR_FLASH)