mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Fix HomeKit behavior with lights supporting color and temperature (#30756)
This commit is contained in:
parent
aeb789ddcc
commit
6b49bea6c4
@ -66,15 +66,20 @@ class Light(HomeAccessory):
|
||||
self._features = self.hass.states.get(self.entity_id).attributes.get(
|
||||
ATTR_SUPPORTED_FEATURES
|
||||
)
|
||||
|
||||
if self._features & SUPPORT_BRIGHTNESS:
|
||||
self.chars.append(CHAR_BRIGHTNESS)
|
||||
if self._features & SUPPORT_COLOR_TEMP:
|
||||
self.chars.append(CHAR_COLOR_TEMPERATURE)
|
||||
|
||||
if self._features & SUPPORT_COLOR:
|
||||
self.chars.append(CHAR_HUE)
|
||||
self.chars.append(CHAR_SATURATION)
|
||||
self._hue = None
|
||||
self._saturation = None
|
||||
elif self._features & SUPPORT_COLOR_TEMP:
|
||||
# ColorTemperature and Hue characteristic should not be
|
||||
# exposed both. Both states are tracked separately in HomeKit,
|
||||
# causing "source of truth" problems.
|
||||
self.chars.append(CHAR_COLOR_TEMPERATURE)
|
||||
|
||||
serv_light = self.add_preload_service(SERV_LIGHTBULB, self.chars)
|
||||
self.char_on = serv_light.configure_char(
|
||||
@ -88,6 +93,7 @@ class Light(HomeAccessory):
|
||||
self.char_brightness = serv_light.configure_char(
|
||||
CHAR_BRIGHTNESS, value=100, setter_callback=self.set_brightness
|
||||
)
|
||||
|
||||
if CHAR_COLOR_TEMPERATURE in self.chars:
|
||||
min_mireds = self.hass.states.get(self.entity_id).attributes.get(
|
||||
ATTR_MIN_MIREDS, 153
|
||||
@ -101,10 +107,12 @@ class Light(HomeAccessory):
|
||||
properties={PROP_MIN_VALUE: min_mireds, PROP_MAX_VALUE: max_mireds},
|
||||
setter_callback=self.set_color_temperature,
|
||||
)
|
||||
|
||||
if CHAR_HUE in self.chars:
|
||||
self.char_hue = serv_light.configure_char(
|
||||
CHAR_HUE, value=0, setter_callback=self.set_hue
|
||||
)
|
||||
|
||||
if CHAR_SATURATION in self.chars:
|
||||
self.char_saturation = serv_light.configure_char(
|
||||
CHAR_SATURATION, value=75, setter_callback=self.set_saturation
|
||||
|
@ -177,6 +177,25 @@ async def test_light_color_temperature(hass, hk_driver, cls, events):
|
||||
assert events[-1].data[ATTR_VALUE] == "color temperature at 250"
|
||||
|
||||
|
||||
async def test_light_color_temperature_and_rgb_color(hass, hk_driver, cls, events):
|
||||
"""Test light with color temperature and rgb color not exposing temperature."""
|
||||
entity_id = "light.demo"
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
{
|
||||
ATTR_SUPPORTED_FEATURES: SUPPORT_COLOR_TEMP | SUPPORT_COLOR,
|
||||
ATTR_COLOR_TEMP: 190,
|
||||
ATTR_HS_COLOR: (260, 90),
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
acc = cls.light(hass, hk_driver, "Light", entity_id, 2, None)
|
||||
|
||||
assert not hasattr(acc, "char_color_temperature")
|
||||
|
||||
|
||||
async def test_light_rgb_color(hass, hk_driver, cls, events):
|
||||
"""Test light with rgb_color."""
|
||||
entity_id = "light.demo"
|
||||
|
Loading…
x
Reference in New Issue
Block a user