Skip to content
Open
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
20 changes: 14 additions & 6 deletions custom_components/dirigera_platform/hub_event_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,17 @@ def _apply_scene_actions(self, msg):
except Exception as ex:
logger.warning(f"Scene action: failed to set {key} on {device_id}: {ex}")

# Update color_mode based on scene attributes
# Update color_mode based on scene attributes.
# Only switch to a mode the bulb actually supports - otherwise HA core
# rejects the state write with "unsupported color mode hs, expected
# color_temp" (e.g. a color_temp-only bulb in a mixed device set that
# receives a colorHue attribute from a group scene).
if updated and hasattr(entity, '_color_mode'):
if "colorHue" in attributes or "colorSaturation" in attributes:
supported = getattr(entity, 'supported_color_modes', None) or []
if ("colorHue" in attributes or "colorSaturation" in attributes) and ColorMode.HS in supported:
entity._color_mode = ColorMode.HS
logger.debug(f"Scene action: set color_mode to HS for {device_id}")
elif "colorTemperature" in attributes:
elif "colorTemperature" in attributes and ColorMode.COLOR_TEMP in supported:
entity._color_mode = ColorMode.COLOR_TEMP
logger.debug(f"Scene action: set color_mode to COLOR_TEMP for {device_id}")

Expand Down Expand Up @@ -602,11 +607,14 @@ def on_message(self, ws:Any, ws_msg:str):
logger.warn(f"Failed to set attribute key: {key} converted to {key_attr} on device: {id}")
logger.warn(ex)

# Update color_mode for lights when color attributes change
# Update color_mode for lights when color attributes change.
# Guard against switching to a mode the bulb does not support
# (see _apply_scene_actions) to avoid HA core rejecting the write.
if device_type == "light" and hasattr(entity, '_color_mode'):
if "colorHue" in attributes or "colorSaturation" in attributes:
supported = getattr(entity, 'supported_color_modes', None) or []
if ("colorHue" in attributes or "colorSaturation" in attributes) and ColorMode.HS in supported:
entity._color_mode = ColorMode.HS
elif "colorTemperature" in attributes:
elif "colorTemperature" in attributes and ColorMode.COLOR_TEMP in supported:
entity._color_mode = ColorMode.COLOR_TEMP

# Lights behave odd with hubs when setting attribute one event is generated which
Expand Down
25 changes: 21 additions & 4 deletions custom_components/dirigera_platform/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ async def async_turn_on(self, **kwargs):
self._color_mode = ColorMode.COLOR_TEMP
self._ignore_update = True

if ATTR_HS_COLOR in kwargs:
if ATTR_HS_COLOR in kwargs and ColorMode.HS in self._supported_color_modes:
logger.debug("Request to set color HS")
hs_tuple = kwargs[ATTR_HS_COLOR]
self._color_hue = hs_tuple[0]
Expand All @@ -341,6 +341,15 @@ async def async_turn_on(self, **kwargs):
await self.hass.async_add_executor_job(self._json_data.set_light_color,self._color_hue, self._color_saturation)
self._color_mode = ColorMode.HS
self._ignore_update = True
elif ATTR_HS_COLOR in kwargs:
# A hs_color was requested for a bulb that does not support HS
# (e.g. a color_temp-only bulb reached via a mixed device set).
# Ignore it instead of forcing color_mode=hs, which HA core rejects
# with "unsupported color mode hs, expected color_temp".
logger.debug(
"Ignoring hs_color for %s: HS not in supported color modes %s",
self.name, self._supported_color_modes,
)
self.async_schedule_update_ha_state(False)
except Exception as ex:
logger.error("error encountered turning on : {}".format(self.name))
Expand Down Expand Up @@ -494,15 +503,23 @@ async def async_turn_on(self, **kwargs):
await self.hass.async_add_executor_job(self.patch_command, {"colorTemperature" : ct})
self._controller._ignore_update = True

if ATTR_HS_COLOR in kwargs:
if ATTR_HS_COLOR in kwargs and ColorMode.HS in self._controller.supported_color_modes:
logger.debug("Request to set color HS device_set")
hs_tuple = kwargs[ATTR_HS_COLOR]
self._color_hue = hs_tuple[0]
self._color_saturation = hs_tuple[1] / 100
# Saturation is 0 - 1 at IKEA
self._controller._ignore_update = True
self._controller._ignore_update = True

await self.hass.async_add_executor_job(self.patch_command,{ "colorHue" : self._color_hue, "colorSaturation" : self._color_saturation})
elif ATTR_HS_COLOR in kwargs:
# hs_color requested for a device set whose controller bulb does not
# support HS (color_temp-only). Ignore it to avoid pushing an
# unsupported color mode to the group.
logger.debug(
"Ignoring hs_color for device_set %s: HS not in supported color modes %s",
self.name, self._controller.supported_color_modes,
)

except Exception as ex:
logger.error("error encountered turning on device_set : {}".format(self.name))
Expand Down