mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Remove color temperature workaround in Hue integration (#68531)
This commit is contained in:
parent
e1ae940a34
commit
7381c2114f
@ -95,9 +95,6 @@ class HueLight(HueBaseEntity, LightEntity):
|
|||||||
self._supported_color_modes.add(COLOR_MODE_BRIGHTNESS)
|
self._supported_color_modes.add(COLOR_MODE_BRIGHTNESS)
|
||||||
# support transition if brightness control
|
# support transition if brightness control
|
||||||
self._attr_supported_features |= SUPPORT_TRANSITION
|
self._attr_supported_features |= SUPPORT_TRANSITION
|
||||||
self._last_xy: tuple[float, float] | None = self.xy_color
|
|
||||||
self._last_color_temp: int = self.color_temp
|
|
||||||
self._set_color_mode()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def brightness(self) -> int | None:
|
def brightness(self) -> int | None:
|
||||||
@ -112,6 +109,20 @@ class HueLight(HueBaseEntity, LightEntity):
|
|||||||
"""Return true if device is on (brightness above 0)."""
|
"""Return true if device is on (brightness above 0)."""
|
||||||
return self.resource.on.on
|
return self.resource.on.on
|
||||||
|
|
||||||
|
@property
|
||||||
|
def color_mode(self) -> str | None:
|
||||||
|
"""Return the color mode of the light."""
|
||||||
|
if color_temp := self.resource.color_temperature:
|
||||||
|
# Hue lights return `mired_valid` to indicate CT is active
|
||||||
|
if color_temp.mirek_valid and color_temp.mirek is not None:
|
||||||
|
return COLOR_MODE_COLOR_TEMP
|
||||||
|
if self.resource.supports_color:
|
||||||
|
return COLOR_MODE_XY
|
||||||
|
if self.resource.supports_dimming:
|
||||||
|
return COLOR_MODE_BRIGHTNESS
|
||||||
|
# fallback to on_off
|
||||||
|
return COLOR_MODE_ONOFF
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def xy_color(self) -> tuple[float, float] | None:
|
def xy_color(self) -> tuple[float, float] | None:
|
||||||
"""Return the xy color."""
|
"""Return the xy color."""
|
||||||
@ -153,11 +164,6 @@ class HueLight(HueBaseEntity, LightEntity):
|
|||||||
"dynamics": self.resource.dynamics.status.value,
|
"dynamics": self.resource.dynamics.status.value,
|
||||||
}
|
}
|
||||||
|
|
||||||
@callback
|
|
||||||
def on_update(self) -> None:
|
|
||||||
"""Call on update event."""
|
|
||||||
self._set_color_mode()
|
|
||||||
|
|
||||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn the device on."""
|
"""Turn the device on."""
|
||||||
transition = normalize_hue_transition(kwargs.get(ATTR_TRANSITION))
|
transition = normalize_hue_transition(kwargs.get(ATTR_TRANSITION))
|
||||||
@ -212,43 +218,3 @@ class HueLight(HueBaseEntity, LightEntity):
|
|||||||
id=self.resource.id,
|
id=self.resource.id,
|
||||||
short=flash == FLASH_SHORT,
|
short=flash == FLASH_SHORT,
|
||||||
)
|
)
|
||||||
|
|
||||||
@callback
|
|
||||||
def _set_color_mode(self) -> None:
|
|
||||||
"""Set current colormode of light."""
|
|
||||||
last_xy = self._last_xy
|
|
||||||
last_color_temp = self._last_color_temp
|
|
||||||
self._last_xy = self.xy_color
|
|
||||||
self._last_color_temp = self.color_temp
|
|
||||||
|
|
||||||
# Certified Hue lights return `mired_valid` to indicate CT is active
|
|
||||||
if color_temp := self.resource.color_temperature:
|
|
||||||
if color_temp.mirek_valid and color_temp.mirek is not None:
|
|
||||||
self._attr_color_mode = COLOR_MODE_COLOR_TEMP
|
|
||||||
return
|
|
||||||
|
|
||||||
# Non-certified lights do not report their current color mode correctly
|
|
||||||
# so we keep track of the color values to determine which is active
|
|
||||||
if last_color_temp != self.color_temp:
|
|
||||||
self._attr_color_mode = COLOR_MODE_COLOR_TEMP
|
|
||||||
return
|
|
||||||
if last_xy != self.xy_color:
|
|
||||||
self._attr_color_mode = COLOR_MODE_XY
|
|
||||||
return
|
|
||||||
|
|
||||||
# if we didn't detect any changes, abort and use previous values
|
|
||||||
if self._attr_color_mode is not None:
|
|
||||||
return
|
|
||||||
|
|
||||||
# color mode not yet determined, work it out here
|
|
||||||
# Note that for lights that do not correctly report `mirek_valid`
|
|
||||||
# we might have an invalid startup state which will be auto corrected
|
|
||||||
if self.resource.supports_color:
|
|
||||||
self._attr_color_mode = COLOR_MODE_XY
|
|
||||||
elif self.resource.supports_color_temperature:
|
|
||||||
self._attr_color_mode = COLOR_MODE_COLOR_TEMP
|
|
||||||
elif self.resource.supports_dimming:
|
|
||||||
self._attr_color_mode = COLOR_MODE_BRIGHTNESS
|
|
||||||
else:
|
|
||||||
# fallback to on_off
|
|
||||||
self._attr_color_mode = COLOR_MODE_ONOFF
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user