Fix Hue light crash when the bridge reports no color temperature (#185218)

This commit is contained in:
Franck Nijhof
2026-10-09 19:10:36 +00:00
parent adacbcdbdc
commit d133a48433
2 changed files with 26 additions and 1 deletions
+1 -1
View File
@@ -175,7 +175,7 @@ class HueLight(HueBaseEntity, LightEntity):
@override
def color_temp_kelvin(self) -> int | None:
"""Return the color temperature value in Kelvin."""
if color_temp := self.resource.color_temperature:
if (color_temp := self.resource.color_temperature) and color_temp.mirek:
return color_util.color_temperature_mired_to_kelvin(color_temp.mirek)
# return a fallback value to prevent issues with mired->kelvin conversions
return FALLBACK_KELVIN
+25
View File
@@ -1072,3 +1072,28 @@ async def test_light_with_zero_mirek(
# Should fall back to defaults instead of crashing
assert test_light.attributes["max_color_temp_kelvin"] == 6535
assert test_light.attributes["min_color_temp_kelvin"] == 2000
async def test_light_with_null_mirek(
hass: HomeAssistant, mock_bridge_v2: Mock, v2_resources_test_data: JsonArrayType
) -> None:
"""Test a color temperature only light doesn't crash without a mirek value."""
for resource in v2_resources_test_data:
if resource["id"] == "3a6710fa-4474-4eba-b533-5e6e72968feb":
resource["on"]["on"] = True
resource["color_temperature"]["mirek"] = None
resource["color_temperature"]["mirek_valid"] = False
break
await mock_bridge_v2.api.load_test_data(v2_resources_test_data)
await setup_platform(hass, mock_bridge_v2, Platform.LIGHT)
test_light = hass.states.get(
"light.test_room_hue_light_with_color_temperature_only"
)
assert test_light is not None
assert test_light.state == "on"
assert test_light.attributes["color_mode"] == ColorMode.COLOR_TEMP
# Falls back instead of converting the missing mirek value
assert test_light.attributes["color_temp_kelvin"] == 5800