Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions homeassistant/components/hue/v2/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from aiohue.v2 import HueBridgeV2
from aiohue.v2.controllers.events import EventType
from aiohue.v2.controllers.groups import GroupedLight, Room, Zone
from aiohue.v2.models.feature import AlertEffectType

from homeassistant.components.light import (
ATTR_BRIGHTNESS,
Expand Down Expand Up @@ -193,7 +192,6 @@ async def async_turn_on(self, **kwargs: Any) -> None:
color_xy=xy_color if light.supports_color else None,
color_temp=color_temp if light.supports_color_temperature else None,
transition_time=transition,
alert=AlertEffectType.BREATHE if flash is not None else None,
allowed_errors=ALLOWED_ERRORS,
)
for light in self.controller.get_lights(self.resource.id)
Expand Down
60 changes: 48 additions & 12 deletions homeassistant/components/hue/v2/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def __init__(
self._supported_color_modes.add(COLOR_MODE_BRIGHTNESS)
# support transition if brightness control
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
def brightness(self) -> int | None:
Expand All @@ -100,18 +103,6 @@ def brightness(self) -> int | None:
return round((dimming.brightness / 100) * 255)
return None

@property
def color_mode(self) -> str:
"""Return the current color mode of the light."""
if color_temp := self.resource.color_temperature:
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
return COLOR_MODE_ONOFF

@property
def is_on(self) -> bool:
"""Return true if device is on (brightness above 0)."""
Expand Down Expand Up @@ -158,6 +149,11 @@ def extra_state_attributes(self) -> dict[str, str] | None:
"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:
"""Turn the device on."""
transition = normalize_hue_transition(kwargs.get(ATTR_TRANSITION))
Expand Down Expand Up @@ -212,3 +208,43 @@ async def async_set_flash(self, flash: str) -> None:
id=self.resource.id,
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