10
10
from homeassistant .components .light import (
11
11
ATTR_BRIGHTNESS ,
12
12
ATTR_HS_COLOR ,
13
+ ATTR_EFFECT ,
13
14
SUPPORT_BRIGHTNESS ,
14
15
SUPPORT_COLOR ,
16
+ SUPPORT_EFFECT ,
15
17
LightEntity ,
16
18
)
17
19
import homeassistant .util .color as color_util
@@ -122,14 +124,70 @@ def __init__(self, api, device_id, device_uuid, name):
122
124
self ._brightness = 0
123
125
self ._hs_color = [0 , 0 ]
124
126
self ._state = False
127
+ self ._scenes : list [str ] = [
128
+ "Normal" ,
129
+ "Flashing" ,
130
+ "DeCongest" ,
131
+ "ColorWipe" ,
132
+ "ColorWipeBackwards" ,
133
+ "ColorWipeRandom" ,
134
+ "RandomColor" ,
135
+ "RandomPixelColorSingle" ,
136
+ "RainbowAll" ,
137
+ "RainbowStream" ,
138
+ "Scanner" ,
139
+ "DualScanner" ,
140
+ "RunningLight" ,
141
+ "Sparkle" ,
142
+ "RandomSparkle" ,
143
+ "HyperSparkle" ,
144
+ "RunningColor" ,
145
+ "LarsonScanner" ,
146
+ "Comet" ,
147
+ "Fireworks" ,
148
+ "RandomFireworks" ,
149
+ "FireFlicker" ,
150
+ "FireFlickerLight" ,
151
+ "FireFlickerHeavy" ,
152
+ "FireFlickerNaturely"
153
+ ]
154
+ self ._scenes_mapping : list [int ] = [
155
+ "0" ,
156
+ "1" ,
157
+ "2" ,
158
+ "3" ,
159
+ "5" ,
160
+ "7" ,
161
+ "8" ,
162
+ "9" ,
163
+ "11" ,
164
+ "12" ,
165
+ "13" ,
166
+ "14" ,
167
+ "18" ,
168
+ "19" ,
169
+ "20" ,
170
+ "25" ,
171
+ "40" ,
172
+ "43" ,
173
+ "44" ,
174
+ "45" ,
175
+ "46" ,
176
+ "48" ,
177
+ "49" ,
178
+ "50" ,
179
+ "55"
180
+ ]
181
+ self ._effect = None
182
+ self ._available = False
125
183
self ._supported_features = self ._determine_features ()
126
184
self ._logger = logging .getLogger (
127
185
("%s:%s:<%s>" ) % (__name__ , self .__class__ .__name__ , self ._device_uuid )
128
186
)
129
187
130
188
def _determine_features (self ):
131
189
"""Get features supported by the device."""
132
- features = SUPPORT_BRIGHTNESS | SUPPORT_COLOR
190
+ features = SUPPORT_BRIGHTNESS | SUPPORT_COLOR | SUPPORT_EFFECT
133
191
134
192
return features
135
193
@@ -162,6 +220,12 @@ async def async_turn_on(self, **kwargs) -> None:
162
220
await self ._api .setDeviceParameter (
163
221
self ._device_uuid , "COLOR_WHITE" , str (color_white )
164
222
)
223
+ if ATTR_EFFECT in kwargs :
224
+ effect = kwargs [ATTR_EFFECT ]
225
+ index = self ._scenes .index (effect )
226
+ await self ._api .setDeviceParameter (
227
+ self ._device_uuid , "MODE" , str (self ._scenes_mapping [index ])
228
+ )
165
229
if not self ._state :
166
230
await self ._api .setDeviceParameter (self ._device_uuid , "STATE" , "1" )
167
231
self ._state = True
@@ -190,6 +254,7 @@ async def async_update(self):
190
254
result = await self ._api .getDeviceById (self ._device_id )
191
255
192
256
self ._mac = result ["hardwareAddress" ]
257
+ self ._available = result ["online" ] == 1
193
258
194
259
color = None
195
260
color_white = None
@@ -213,6 +278,14 @@ async def async_update(self):
213
278
color = i ["value" ]
214
279
if self ._supported_features & SUPPORT_COLOR and i ["type" ] == "COLOR_WHITE" :
215
280
color_white = i ["valueNumeric" ]
281
+
282
+ # Effect
283
+ if (
284
+ self ._supported_features & SUPPORT_EFFECT
285
+ and i ["type" ] == "MODE"
286
+ ):
287
+ index = self ._scenes_mapping .index (i ["value" ])
288
+ self ._effect = self ._scenes [index ]
216
289
217
290
if (color != None and color_white != None ):
218
291
r , g , b = int ("0x%s" % color [1 :3 ], base = 16 ), int ("0x%s" % color [3 :5 ], base = 16 ), int ("0x%s" % color [5 :7 ], base = 16 )
@@ -284,3 +357,20 @@ def min_mireds(self):
284
357
def supported_features (self ) -> int :
285
358
"""Flag supported features."""
286
359
return self ._supported_features
360
+
361
+ @property
362
+ def effect (self ):
363
+ """Return the current effect."""
364
+ return self ._effect
365
+
366
+ @property
367
+ def effect_list (self ):
368
+ """Return the list of supported effects.
369
+ URL: https://docs.pro.wizconnected.com/#light-modes
370
+ """
371
+ return self ._scenes
372
+
373
+ @property
374
+ def available (self ):
375
+ """Return if able to retrieve information from device or not."""
376
+ return self ._available
0 commit comments