Skip to content

Commit 1c8862f

Browse files
committed
Fix DIY modes for TX Ultimate #1424
1 parent cea6f75 commit 1c8862f

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

custom_components/sonoff/light.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,40 +1145,42 @@ async def async_turn_off(self, **kwargs) -> None:
11451145
await self.ewelink.send(self.device, {"lightswitch": 0})
11461146

11471147

1148+
T5_EFFECTS = {
1149+
"Night Light": 0,
1150+
"Party": 1,
1151+
"Leisure": 2,
1152+
"Color": 3,
1153+
"Childhood": 4,
1154+
"Wiper": 5,
1155+
"Fairy": 6,
1156+
"Starburst": 7,
1157+
"DIY 1": 101,
1158+
"DIY 2": 102,
1159+
}
1160+
1161+
11481162
class XT5Light(XOnOffLight):
11491163
params = {"lightSwitch", "lightMode"}
11501164

1151-
_attr_effect_list = [
1152-
"Night Light",
1153-
"Party",
1154-
"Leisure",
1155-
"Color",
1156-
"Childhood",
1157-
"Wiper",
1158-
"Fairy",
1159-
"Starburst",
1160-
"DIY 1",
1161-
"DIY 2",
1162-
]
1165+
_attr_effect_list = list(T5_EFFECTS.keys())
11631166
_attr_supported_features = LightEntityFeature.EFFECT
11641167

11651168
def set_state(self, params: dict):
11661169
if "lightSwitch" in params:
11671170
self._attr_is_on = params["lightSwitch"] == "on"
11681171

11691172
if "lightMode" in params:
1170-
i = int(params["lightMode"])
1171-
self._attr_effect = (
1172-
self._attr_effect_list[i] if i < len(self._attr_effect_list) else None
1173+
self._attr_effect = next(
1174+
(k for k, v in T5_EFFECTS.items() if v == params["lightMode"]), None
11731175
)
11741176

11751177
async def async_turn_on(
11761178
self, brightness: int = None, effect: str = None, **kwargs
11771179
) -> None:
11781180
params = {}
11791181

1180-
if effect:
1181-
params["lightMode"] = self._attr_effect_list.index(effect)
1182+
if effect and effect in T5_EFFECTS:
1183+
params["lightMode"] = T5_EFFECTS[effect]
11821184

11831185
if not params:
11841186
params["lightSwitch"] = "on"

0 commit comments

Comments
 (0)