From 5fcc6e8fb02ce99d1ccaa54cab209b45ae2c79d5 Mon Sep 17 00:00:00 2001 From: Jonathan Kang Date: Mon, 6 Nov 2023 20:29:38 +0800 Subject: [PATCH] Add support for light effect and effect_list 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"}) --- custom_components/xiaomi_gateway3/light.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/custom_components/xiaomi_gateway3/light.py b/custom_components/xiaomi_gateway3/light.py index 790ae5e8..7a170f41 100644 --- a/custom_components/xiaomi_gateway3/light.py +++ b/custom_components/xiaomi_gateway3/light.py @@ -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): @@ -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)