mirror of
https://github.com/Electric-Special/ha-core.git
synced 2026-03-21 08:06:00 +01:00
Fix support for new Hue bulbs with very wide color temperature support (#152834)
This commit is contained in:
committed by
GitHub
parent
9ba7dda864
commit
ff47839c61
@@ -162,7 +162,11 @@ class GroupedHueLight(HueBaseEntity, LightEntity):
|
||||
"""Turn the grouped_light on."""
|
||||
transition = normalize_hue_transition(kwargs.get(ATTR_TRANSITION))
|
||||
xy_color = kwargs.get(ATTR_XY_COLOR)
|
||||
color_temp = normalize_hue_colortemp(kwargs.get(ATTR_COLOR_TEMP_KELVIN))
|
||||
color_temp = normalize_hue_colortemp(
|
||||
kwargs.get(ATTR_COLOR_TEMP_KELVIN),
|
||||
color_util.color_temperature_kelvin_to_mired(self.max_color_temp_kelvin),
|
||||
color_util.color_temperature_kelvin_to_mired(self.min_color_temp_kelvin),
|
||||
)
|
||||
brightness = normalize_hue_brightness(kwargs.get(ATTR_BRIGHTNESS))
|
||||
flash = kwargs.get(ATTR_FLASH)
|
||||
|
||||
|
||||
@@ -23,11 +23,12 @@ def normalize_hue_transition(transition: float | None) -> float | None:
|
||||
return transition
|
||||
|
||||
|
||||
def normalize_hue_colortemp(colortemp_k: int | None) -> int | None:
|
||||
def normalize_hue_colortemp(
|
||||
colortemp_k: int | None, min_mireds: int, max_mireds: int
|
||||
) -> int | None:
|
||||
"""Return color temperature within Hue's ranges."""
|
||||
if colortemp_k is None:
|
||||
return None
|
||||
colortemp = color_util.color_temperature_kelvin_to_mired(colortemp_k)
|
||||
# Hue only accepts a range between 153..500
|
||||
colortemp = min(colortemp, 500)
|
||||
return max(colortemp, 153)
|
||||
colortemp_mireds = color_util.color_temperature_kelvin_to_mired(colortemp_k)
|
||||
# Hue only accepts a range between min_mireds..max_mireds
|
||||
return min(max(colortemp_mireds, min_mireds), max_mireds)
|
||||
|
||||
@@ -40,8 +40,8 @@ from .helpers import (
|
||||
normalize_hue_transition,
|
||||
)
|
||||
|
||||
FALLBACK_MIN_KELVIN = 6500
|
||||
FALLBACK_MAX_KELVIN = 2000
|
||||
FALLBACK_MIN_MIREDS = 153 # hue default for most lights
|
||||
FALLBACK_MAX_MIREDS = 500 # hue default for most lights
|
||||
FALLBACK_KELVIN = 5800 # halfway
|
||||
|
||||
# HA 2025.4 replaced the deprecated effect "None" with HA default "off"
|
||||
@@ -177,25 +177,31 @@ class HueLight(HueBaseEntity, LightEntity):
|
||||
# return a fallback value to prevent issues with mired->kelvin conversions
|
||||
return FALLBACK_KELVIN
|
||||
|
||||
@property
|
||||
def max_color_temp_mireds(self) -> int:
|
||||
"""Return the warmest color_temp in mireds (so highest number) that this light supports."""
|
||||
if color_temp := self.resource.color_temperature:
|
||||
return color_temp.mirek_schema.mirek_maximum
|
||||
# return a fallback value if the light doesn't provide limits
|
||||
return FALLBACK_MAX_MIREDS
|
||||
|
||||
@property
|
||||
def min_color_temp_mireds(self) -> int:
|
||||
"""Return the coldest color_temp in mireds (so lowest number) that this light supports."""
|
||||
if color_temp := self.resource.color_temperature:
|
||||
return color_temp.mirek_schema.mirek_minimum
|
||||
# return a fallback value if the light doesn't provide limits
|
||||
return FALLBACK_MIN_MIREDS
|
||||
|
||||
@property
|
||||
def max_color_temp_kelvin(self) -> int:
|
||||
"""Return the coldest color_temp_kelvin that this light supports."""
|
||||
if color_temp := self.resource.color_temperature:
|
||||
return color_util.color_temperature_mired_to_kelvin(
|
||||
color_temp.mirek_schema.mirek_minimum
|
||||
)
|
||||
# return a fallback value to prevent issues with mired->kelvin conversions
|
||||
return FALLBACK_MAX_KELVIN
|
||||
return color_util.color_temperature_mired_to_kelvin(self.min_color_temp_mireds)
|
||||
|
||||
@property
|
||||
def min_color_temp_kelvin(self) -> int:
|
||||
"""Return the warmest color_temp_kelvin that this light supports."""
|
||||
if color_temp := self.resource.color_temperature:
|
||||
return color_util.color_temperature_mired_to_kelvin(
|
||||
color_temp.mirek_schema.mirek_maximum
|
||||
)
|
||||
# return a fallback value to prevent issues with mired->kelvin conversions
|
||||
return FALLBACK_MIN_KELVIN
|
||||
return color_util.color_temperature_mired_to_kelvin(self.max_color_temp_mireds)
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict[str, str] | None:
|
||||
@@ -220,7 +226,11 @@ class HueLight(HueBaseEntity, LightEntity):
|
||||
"""Turn the device on."""
|
||||
transition = normalize_hue_transition(kwargs.get(ATTR_TRANSITION))
|
||||
xy_color = kwargs.get(ATTR_XY_COLOR)
|
||||
color_temp = normalize_hue_colortemp(kwargs.get(ATTR_COLOR_TEMP_KELVIN))
|
||||
color_temp = normalize_hue_colortemp(
|
||||
kwargs.get(ATTR_COLOR_TEMP_KELVIN),
|
||||
self.min_color_temp_mireds,
|
||||
self.max_color_temp_mireds,
|
||||
)
|
||||
brightness = normalize_hue_brightness(kwargs.get(ATTR_BRIGHTNESS))
|
||||
if self._last_brightness and brightness is None:
|
||||
# The Hue bridge sets the brightness to 1% when turning on a bulb
|
||||
|
||||
@@ -178,7 +178,7 @@ async def test_light_turn_on_service(
|
||||
blocking=True,
|
||||
)
|
||||
assert len(mock_bridge_v2.mock_requests) == 6
|
||||
assert mock_bridge_v2.mock_requests[5]["json"]["color_temperature"]["mirek"] == 500
|
||||
assert mock_bridge_v2.mock_requests[5]["json"]["color_temperature"]["mirek"] == 454
|
||||
|
||||
# test enable an effect
|
||||
await hass.services.async_call(
|
||||
|
||||
Reference in New Issue
Block a user