Handle ATTR_HS_COLOR being None in HomeKit (#102290)
This commit is contained in:
parent
7ec2496c81
commit
327bdce561
2 changed files with 38 additions and 1 deletions
|
@ -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))
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue