Skip to content

Commit

Permalink
💡 fix color mode for light (#844)
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Feb 23, 2023
1 parent 175b485 commit 5cfe22f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions custom_components/xiaomi_miot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,7 @@ async def async_added_to_hass(self):
if not self._miot_service:
return
self._vars['ignore_offline'] = self.custom_config_bool('ignore_offline')
self.logger.debug('%s: Added to hass: %s', self.name_model, [self.custom_config()])

@property
def miot_device(self):
Expand Down
6 changes: 6 additions & 0 deletions custom_components/xiaomi_miot/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,13 @@ def __init__(self, config: dict, miot_service: MiotService, **kwargs):
if not self._prop_color:
self._prop_color = self._srv_ambient_custom.get_property('color')

self._attr_color_mode = ColorMode.UNKNOWN
self._attr_supported_color_modes = set()
if self._prop_power:
self._attr_color_mode = ColorMode.ONOFF
self._attr_supported_color_modes.add(ColorMode.ONOFF)
if self._prop_brightness:
self._attr_color_mode = ColorMode.BRIGHTNESS
self._attr_supported_color_modes.add(ColorMode.BRIGHTNESS)
self._is_percentage_color_temp = None
if self._prop_color_temp:
Expand Down Expand Up @@ -156,6 +159,7 @@ def turn_on(self, **kwargs):
ret = self.set_property(self._prop_brightness, bri)
else:
ret = self.set_property(self._prop_power, True)
self._attr_color_mode = ColorMode.BRIGHTNESS

if self._prop_brightness and ATTR_BRIGHTNESS in kwargs:
brightness = kwargs[ATTR_BRIGHTNESS]
Expand All @@ -181,12 +185,14 @@ def turn_on(self, **kwargs):
ret = self.send_miio_command('set_ct_abx', [color_temp, 'smooth', trs])
else:
ret = self.set_property(self._prop_color_temp, color_temp)
self._attr_color_mode = ColorMode.COLOR_TEMP

if self._prop_color and ATTR_HS_COLOR in kwargs:
rgb = color.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR])
num = rgb_to_int(rgb)
self.logger.debug('%s: Setting light color: %s', self.name_model, rgb)
ret = self.set_property(self._prop_color, num)
self._attr_color_mode = ColorMode.HS

if self._prop_mode and ATTR_EFFECT in kwargs:
mode = kwargs[ATTR_EFFECT]
Expand Down

0 comments on commit 5cfe22f

Please sign in to comment.