diff --git a/homeassistant/components/hue/v2/light.py b/homeassistant/components/hue/v2/light.py index 8b025dad5351..2f1c1987b7b8 100644 --- a/homeassistant/components/hue/v2/light.py +++ b/homeassistant/components/hue/v2/light.py @@ -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 diff --git a/tests/components/hue/test_light_v2.py b/tests/components/hue/test_light_v2.py index dac308cb9788..702138d98c9d 100644 --- a/tests/components/hue/test_light_v2.py +++ b/tests/components/hue/test_light_v2.py @@ -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