Skip to content

Commit

Permalink
Add support for light effect and effect_list
Browse files Browse the repository at this point in the history
To implement this in your device, add similar converters like the one
down below to devices.py.

> MapConv("effect", mi="1.p.1", parent="light", map={0: "Day", 1: "Night"})
  • Loading branch information
JonathanKang committed Nov 6, 2023
1 parent 9f29521 commit 5fcc6e8
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions custom_components/xiaomi_gateway3/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def __init__(self, gateway: "XGateway", device: XDevice, conv: Converter):
elif hasattr(conv, "mink") and hasattr(conv, "maxk"):
self._attr_min_mireds = int(1000000 / conv.maxk)
self._attr_max_mireds = int(1000000 / conv.mink)
elif conv.attr == ATTR_EFFECT:
self._attr_supported_features |= LightEntityFeature.EFFECT
self._attr_effect_list = list(conv.map.values())

@callback
def async_set_state(self, data: dict):
Expand All @@ -58,12 +61,15 @@ def async_set_state(self, data: dict):
self._attr_brightness = data[ATTR_BRIGHTNESS]
if ATTR_COLOR_TEMP in data:
self._attr_color_temp = data[ATTR_COLOR_TEMP]
if ATTR_EFFECT in data:
self._attr_effect = data[ATTR_EFFECT]

@callback
def async_restore_last_state(self, state: str, attrs: dict):
self._attr_is_on = state == STATE_ON
self._attr_brightness = attrs.get(ATTR_BRIGHTNESS)
self._attr_color_temp = attrs.get(ATTR_COLOR_TEMP)
self._attr_effect = attrs.get(ATTR_EFFECT)

async def async_update(self):
await self.device_read(self.subscribed_attrs)
Expand Down

0 comments on commit 5fcc6e8

Please sign in to comment.