File tree Expand file tree Collapse file tree 1 file changed +19
-17
lines changed Expand file tree Collapse file tree 1 file changed +19
-17
lines changed Original file line number Diff line number Diff line change @@ -1145,40 +1145,42 @@ async def async_turn_off(self, **kwargs) -> None:
1145
1145
await self .ewelink .send (self .device , {"lightswitch" : 0 })
1146
1146
1147
1147
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
+
1148
1162
class XT5Light (XOnOffLight ):
1149
1163
params = {"lightSwitch" , "lightMode" }
1150
1164
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 ())
1163
1166
_attr_supported_features = LightEntityFeature .EFFECT
1164
1167
1165
1168
def set_state (self , params : dict ):
1166
1169
if "lightSwitch" in params :
1167
1170
self ._attr_is_on = params ["lightSwitch" ] == "on"
1168
1171
1169
1172
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
1173
1175
)
1174
1176
1175
1177
async def async_turn_on (
1176
1178
self , brightness : int = None , effect : str = None , ** kwargs
1177
1179
) -> None :
1178
1180
params = {}
1179
1181
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 ]
1182
1184
1183
1185
if not params :
1184
1186
params ["lightSwitch" ] = "on"
You can’t perform that action at this time.
0 commit comments