Skip to content

Commit

Permalink
💡 fix for light entity (#2039)
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Dec 14, 2024
1 parent 01a4605 commit 9a38dac
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
8 changes: 7 additions & 1 deletion custom_components/xiaomi_miot/core/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,13 @@ def init_converters(self):
for p in cfg.get('converters') or []:
if not (props := p.get('props')):
continue
for prop in service.get_properties(*props, excludes=self._exclude_miot_properties):
for p in props:
if '.' in p:
prop = self.spec.get_property(p)
else:
prop = service.get_property(p)
if not prop:
continue
attr = p.get('attr', prop.full_name)
c = p.get('class', MiotPropConv)
d = p.get('domain', None)
Expand Down
61 changes: 28 additions & 33 deletions custom_components/xiaomi_miot/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,40 +86,35 @@ def on_init(self):
self._brightness_for_on = self.custom_config_number('brightness_for_on')
self._brightness_for_off = self.custom_config_number('brightness_for_off')
self._attr_color_mode = ColorMode.ONOFF
modes = set()

for conv in self.device.converters:
if not self._miot_service:
break
prop = getattr(conv, 'prop', None)
if isinstance(prop, MiotProperty):
if conv.attr == ATTR_BRIGHTNESS or prop.in_list(['brightness']):
self.listen_attrs.add(conv.attr)
self._attr_names[ATTR_BRIGHTNESS] = conv.attr
self._attr_color_mode = ColorMode.BRIGHTNESS
elif conv.attr == ATTR_COLOR_TEMP or prop.in_list(['color_temperature', 'color_temp']):
self.listen_attrs.add(conv.attr)
self._attr_color_mode = ColorMode.COLOR_TEMP
modes.add(ColorMode.COLOR_TEMP)
if prop.unit in ['kelvin']:
self._attr_min_color_temp_kelvin = prop.range_min()
self._attr_max_color_temp_kelvin = prop.range_max()
self._attr_names[ATTR_COLOR_TEMP_KELVIN] = conv.attr
else:
self._attr_min_mireds = prop.range_min()
self._attr_max_mireds = prop.range_max()
self._attr_names[ATTR_COLOR_TEMP] = conv.attr
elif conv.attr == ATTR_RGB_COLOR or prop.in_list(['color']):
self.listen_attrs.add(conv.attr)
self._attr_names[ATTR_RGB_COLOR] = conv.attr
modes.add(ColorMode.RGB)
elif conv.attr == ATTR_EFFECT or prop.in_list(['mode']):
self.listen_attrs.add(conv.attr)
self._attr_names[ATTR_EFFECT] = conv.attr
self._attr_effect_list = prop.list_descriptions()
self._attr_supported_features |= LightEntityFeature.EFFECT

self._attr_supported_color_modes = modes if modes else {self._attr_color_mode}
modes = set()
for attr in self.conv.attrs:
prop = self._miot_service.spec.get_property(attr) if self._miot_service else None
if not prop:
continue
if prop.in_list(['brightness']):
self._attr_names[ATTR_BRIGHTNESS] = attr
self._attr_color_mode = ColorMode.BRIGHTNESS
elif prop.in_list(['color_temperature', 'color_temp']):
self._attr_color_mode = ColorMode.COLOR_TEMP
modes.add(ColorMode.COLOR_TEMP)
if prop.unit in ['kelvin']:
self._attr_min_color_temp_kelvin = prop.range_min()
self._attr_max_color_temp_kelvin = prop.range_max()
self._attr_names[ATTR_COLOR_TEMP_KELVIN] = attr
else:
self._attr_min_mireds = prop.range_min()
self._attr_max_mireds = prop.range_max()
self._attr_names[ATTR_COLOR_TEMP] = attr
elif prop.in_list(['color']):
self._attr_names[ATTR_RGB_COLOR] = attr
modes.add(ColorMode.RGB)
elif prop.in_list(['mode']):
self._attr_names[ATTR_EFFECT] = attr
self._attr_effect_list = prop.list_descriptions()
self._attr_supported_features |= LightEntityFeature.EFFECT

self._attr_supported_color_modes = modes if modes else {self._attr_color_mode}

def get_state(self) -> dict:
return {
Expand Down

0 comments on commit 9a38dac

Please sign in to comment.