mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Fix Hue brightness values over 127 off by one (#34190)
This commit is contained in:
parent
91d35c7c5c
commit
6fa29d6e2e
@ -184,6 +184,16 @@ def async_update_items(bridge, api, current, async_add_entities, create_item):
|
|||||||
async_add_entities(new_items)
|
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):
|
class HueLight(Light):
|
||||||
"""Representation of a Hue light."""
|
"""Representation of a Hue light."""
|
||||||
|
|
||||||
@ -245,8 +255,11 @@ class HueLight(Light):
|
|||||||
def brightness(self):
|
def brightness(self):
|
||||||
"""Return the brightness of this light between 0..255."""
|
"""Return the brightness of this light between 0..255."""
|
||||||
if self.is_group:
|
if self.is_group:
|
||||||
return self.light.action.get("bri")
|
bri = self.light.action.get("bri")
|
||||||
return self.light.state.get("bri")
|
else:
|
||||||
|
bri = self.light.state.get("bri")
|
||||||
|
|
||||||
|
return hue_brightness_to_hass(bri)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _color_mode(self):
|
def _color_mode(self):
|
||||||
@ -372,7 +385,7 @@ class HueLight(Light):
|
|||||||
command["ct"] = max(self.min_mireds, min(temp, self.max_mireds))
|
command["ct"] = max(self.min_mireds, min(temp, self.max_mireds))
|
||||||
|
|
||||||
if ATTR_BRIGHTNESS in kwargs:
|
if ATTR_BRIGHTNESS in kwargs:
|
||||||
command["bri"] = kwargs[ATTR_BRIGHTNESS]
|
command["bri"] = hass_to_hue_brightness(kwargs[ATTR_BRIGHTNESS])
|
||||||
|
|
||||||
flash = kwargs.get(ATTR_FLASH)
|
flash = kwargs.get(ATTR_FLASH)
|
||||||
|
|
||||||
|
@ -222,7 +222,7 @@ async def test_lights(hass, mock_bridge):
|
|||||||
lamp_1 = hass.states.get("light.hue_lamp_1")
|
lamp_1 = hass.states.get("light.hue_lamp_1")
|
||||||
assert lamp_1 is not None
|
assert lamp_1 is not None
|
||||||
assert lamp_1.state == "on"
|
assert lamp_1.state == "on"
|
||||||
assert lamp_1.attributes["brightness"] == 144
|
assert lamp_1.attributes["brightness"] == 145
|
||||||
assert lamp_1.attributes["hs_color"] == (36.067, 69.804)
|
assert lamp_1.attributes["hs_color"] == (36.067, 69.804)
|
||||||
|
|
||||||
lamp_2 = hass.states.get("light.hue_lamp_2")
|
lamp_2 = hass.states.get("light.hue_lamp_2")
|
||||||
@ -238,7 +238,7 @@ async def test_lights_color_mode(hass, mock_bridge):
|
|||||||
lamp_1 = hass.states.get("light.hue_lamp_1")
|
lamp_1 = hass.states.get("light.hue_lamp_1")
|
||||||
assert lamp_1 is not None
|
assert lamp_1 is not None
|
||||||
assert lamp_1.state == "on"
|
assert lamp_1.state == "on"
|
||||||
assert lamp_1.attributes["brightness"] == 144
|
assert lamp_1.attributes["brightness"] == 145
|
||||||
assert lamp_1.attributes["hs_color"] == (36.067, 69.804)
|
assert lamp_1.attributes["hs_color"] == (36.067, 69.804)
|
||||||
assert "color_temp" not in lamp_1.attributes
|
assert "color_temp" not in lamp_1.attributes
|
||||||
|
|
||||||
@ -258,7 +258,7 @@ async def test_lights_color_mode(hass, mock_bridge):
|
|||||||
lamp_1 = hass.states.get("light.hue_lamp_1")
|
lamp_1 = hass.states.get("light.hue_lamp_1")
|
||||||
assert lamp_1 is not None
|
assert lamp_1 is not None
|
||||||
assert lamp_1.state == "on"
|
assert lamp_1.state == "on"
|
||||||
assert lamp_1.attributes["brightness"] == 144
|
assert lamp_1.attributes["brightness"] == 145
|
||||||
assert lamp_1.attributes["color_temp"] == 467
|
assert lamp_1.attributes["color_temp"] == 467
|
||||||
assert "hs_color" not in lamp_1.attributes
|
assert "hs_color" not in lamp_1.attributes
|
||||||
|
|
||||||
@ -277,7 +277,7 @@ async def test_groups(hass, mock_bridge):
|
|||||||
lamp_1 = hass.states.get("light.group_1")
|
lamp_1 = hass.states.get("light.group_1")
|
||||||
assert lamp_1 is not None
|
assert lamp_1 is not None
|
||||||
assert lamp_1.state == "on"
|
assert lamp_1.state == "on"
|
||||||
assert lamp_1.attributes["brightness"] == 254
|
assert lamp_1.attributes["brightness"] == 255
|
||||||
assert lamp_1.attributes["color_temp"] == 250
|
assert lamp_1.attributes["color_temp"] == 250
|
||||||
|
|
||||||
lamp_2 = hass.states.get("light.group_2")
|
lamp_2 = hass.states.get("light.group_2")
|
||||||
@ -328,7 +328,7 @@ async def test_new_group_discovered(hass, mock_bridge):
|
|||||||
new_group = hass.states.get("light.group_3")
|
new_group = hass.states.get("light.group_3")
|
||||||
assert new_group is not None
|
assert new_group is not None
|
||||||
assert new_group.state == "on"
|
assert new_group.state == "on"
|
||||||
assert new_group.attributes["brightness"] == 153
|
assert new_group.attributes["brightness"] == 154
|
||||||
assert new_group.attributes["color_temp"] == 250
|
assert new_group.attributes["color_temp"] == 250
|
||||||
|
|
||||||
|
|
||||||
@ -448,7 +448,7 @@ async def test_other_group_update(hass, mock_bridge):
|
|||||||
assert group_2 is not None
|
assert group_2 is not None
|
||||||
assert group_2.name == "Group 2"
|
assert group_2.name == "Group 2"
|
||||||
assert group_2.state == "on"
|
assert group_2.state == "on"
|
||||||
assert group_2.attributes["brightness"] == 153
|
assert group_2.attributes["brightness"] == 154
|
||||||
assert group_2.attributes["color_temp"] == 250
|
assert group_2.attributes["color_temp"] == 250
|
||||||
|
|
||||||
updated_group_response = dict(GROUP_RESPONSE)
|
updated_group_response = dict(GROUP_RESPONSE)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user