diff --git a/homeassistant/components/homekit/type_lights.py b/homeassistant/components/homekit/type_lights.py index 13301c3f507..b45e9e1c17b 100644 --- a/homeassistant/components/homekit/type_lights.py +++ b/homeassistant/components/homekit/type_lights.py @@ -274,8 +274,11 @@ class Light(HomeAccessory): hue, saturation = color_temperature_to_hs(color_temp) elif color_mode == ColorMode.WHITE: hue, saturation = 0, 0 + elif hue_sat := attributes.get(ATTR_HS_COLOR): + hue, saturation = hue_sat else: - hue, saturation = attributes.get(ATTR_HS_COLOR, (None, None)) + hue = None + saturation = None if isinstance(hue, (int, float)) and isinstance(saturation, (int, float)): self.char_hue.set_value(round(hue, 0)) self.char_saturation.set_value(round(saturation, 0)) diff --git a/tests/components/homekit/test_type_lights.py b/tests/components/homekit/test_type_lights.py index b023b7255a8..6fae8337aae 100644 --- a/tests/components/homekit/test_type_lights.py +++ b/tests/components/homekit/test_type_lights.py @@ -1031,6 +1031,40 @@ async def test_light_rgb_with_white_switch_to_temp( assert acc.char_brightness.value == 100 +async def test_light_rgb_with_hs_color_none( + hass: HomeAssistant, + hk_driver, + events, +) -> None: + """Test lights hs color set to None.""" + entity_id = "light.demo" + + hass.states.async_set( + entity_id, + STATE_ON, + { + ATTR_SUPPORTED_COLOR_MODES: [ColorMode.RGB], + ATTR_RGBWW_COLOR: (128, 50, 0, 255, 255), + ATTR_RGB_COLOR: (128, 50, 0), + ATTR_HS_COLOR: None, + ATTR_BRIGHTNESS: 255, + ATTR_COLOR_MODE: ColorMode.RGB, + }, + ) + await hass.async_block_till_done() + acc = Light(hass, hk_driver, "Light", entity_id, 1, None) + hk_driver.add_accessory(acc) + + assert acc.char_hue.value == 0 + assert acc.char_saturation.value == 75 + + await acc.run() + await hass.async_block_till_done() + assert acc.char_hue.value == 0 + assert acc.char_saturation.value == 75 + assert acc.char_brightness.value == 100 + + async def test_light_rgbww_with_color_temp_conversion( hass: HomeAssistant, hk_driver,