Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for light effect and effect_list #1204

Merged
merged 1 commit into from
Nov 6, 2023
Merged
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
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