Skip to content

Commit

Permalink
Fixed color mode / brightness as per latest developer documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
c503ghosh committed Mar 24, 2024
1 parent d689fad commit d391b9f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
15 changes: 12 additions & 3 deletions custom_components/dirigera_platform/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def set_state(self):
can_receive = self._json_data.capabilities.can_receive
logger.debug("Got can_receive in state")
logger.debug(can_receive)
self._color_mode = ColorMode.UNKNOWN
self._color_mode = ColorMode.ONOFF
for cap in can_receive:
if cap == "lightLevel":
color_modes.append(ColorMode.BRIGHTNESS)
Expand All @@ -74,9 +74,17 @@ def set_state(self):
elif cap == "colorHue" or cap == "colorSaturation":
color_modes.append(ColorMode.HS)

# Based on documentation here
# https://developers.home-assistant.io/docs/core/entity/light#color-modes
if len(color_modes) > 1:
# If there are more color modes which means we have either temperature
# or HueSaturation. then lets make sure BRIGHTNESS is not part of it
# as per above documentation
color_modes.remove(ColorMode.BRIGHTNESS)

if len(color_modes) == 0:
logger.debug("Color modes array is zero, setting to UNKNOWN")
self._supported_color_modes = [ColorMode.UNKNOWN]
self._supported_color_modes = [ColorMode.ONOFF]
else:
self._supported_color_modes = color_modes
if ColorMode.HS in self._supported_color_modes:
Expand All @@ -86,8 +94,9 @@ def set_state(self):
elif ColorMode.BRIGHTNESS in self._supported_color_modes:
self._color_mode = ColorMode.BRIGHTNESS

logger.debug("supported color mode set to ")
logger.debug("supported color mode set to:")
logger.debug(self._supported_color_modes)
logger.debug("color mode set to:")
logger.debug(self._color_mode)

@property
Expand Down
8 changes: 7 additions & 1 deletion custom_components/dirigera_platform/mocks/ikea_bulb_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ def __init__(self) -> None:
ColorMode.COLOR_TEMP,
ColorMode.HS,
]


if len(self._supported_color_modes) > 1:
# If there are more color modes which means we have either temperature
# or HueSaturation. then lets make sure BRIGHTNESS is not part of it
# as per above documentation
self._supported_color_modes.remove(ColorMode.BRIGHTNESS)

if len(self._supported_color_modes) == 0:
logger.debug("Color modes array is zero, setting to UNKNOWN")
self._supported_color_modes = [ColorMode.UNKNOWN]
Expand Down

0 comments on commit d391b9f

Please sign in to comment.