10000 Add effect support for KL430 · python-kasa/python-kasa@33f36fa · GitHub
[go: up one dir, main page]

Skip to content

Commit 33f36fa

Browse files
committed
Add effect support for KL430
1 parent 5bf6fda commit 33f36fa

File tree

8 files changed

+476
-5
lines changed

8 files changed

+476
-5
lines changed

kasa/cli.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,26 @@ async def temperature(dev: SmartBulb, temperature: int, transition: int):
366366
return await dev.set_color_temp(temperature, transition=transition)
367367

368368

369+
@cli.command()
370+
@click.argument("effect", type=click.STRING, default=None, required=False)
371+
@click.pass_context
372+
@pass_dev
373+
async def effect(dev, ctx, effect):
374+
"""Set an effect."""
375+
if not dev.has_effects:
376+
click.echo("Device does not support effects")
377+
return
378+
if effect is None:
379+
raise click.BadArgumentUsage(
380+
"Setting an effect requires a named built-in effect.", ctx
381+
)
382+
if effect not in dev.effect_list:
383+
raise click.BadArgumentUsage(f"Effect must be one of: {dev.effect_list}", ctx)
384+
385+
click.echo(f"Setting Effect: {effect}")
386+
return await dev.set_effect(effect)
387+
388+
369389
@cli.command()
370390
@click.argument("h", type=click.IntRange(0, 360), default=None, required=False)
371391
@click.argument("s", type=click.IntRange(0, 100), default=None, required=False)

kasa/effects.py

Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
1+
"""Module for light strip effects (LB*, KL*, KB*)."""
2+
3+
from typing import List, cast
4+
5+
EFFECT_AURORA = {
6+
"custom": 0,
7+
"id": "xqUxDhbAhNLqulcuRMyPBmVGyTOyEMEu",
8+
"brightness": 100,
9+
"name": "Aurora",
10+
"segments": [0],
11+
"expansion_strategy": 1,
12+
"enable": 1,
13+
"type": "sequence",
14+
"duration": 0,
15+
"transition": 1500,
16+
"direction": 4,
17+
"spread": 7,
18+
"repeat_times": 0,
19+
"sequence": [[120, 100, 100], [240, 100, 100], [260, 100, 100], [280, 100, 100]],
20+
}
21+
EFFECT_BUBBLING_CAULDRON = {
22+
"custom": 0,
23+
"id": "tIwTRQBqJpeNKbrtBMFCgkdPTbAQGfRP",
24+
"brightness": 100,
25+
"name": "Bubbling Cauldron",
26+
"segments": [0],
27+
"expansion_strategy": 1,
28+
"enable": 1,
29+
"type": "random",
30+
"hue_range": [100, 270],
31+
"saturation_range": [80, 100],
32+
"brightness_range": [50, 100],
33+
"duration": 0,
34+
"transition": 200,
35+
"init_states": [[270, 100, 100]],
36+
"fadeoff": 1000,
37+
"random_seed": 24,
38+
"backgrounds": [[270, 40, 50]],
39+
}
40+
EFFECT_CANDY_CANE = {
41+
"custom": 0,
42+
"id": "HCOttllMkNffeHjEOLEgrFJjbzQHoxEJ",
43+
"brightness": 100,
44+
"name": "Candy Cane",
45+
"segments": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
46+
"expansion_strategy": 1,
47+
"enable": 1,
48+
"type": "sequence",
49+
"duration": 700,
50+
"transition": 500,
51+
"direction": 1,
52+
"spread": 1,
53+
"repeat_times": 0,
54+
"sequence": [
55+
[0, 0, 100],
56+
[0, 0, 100],
57+
[360, 81, 100],
58+
[0, 0, 100],
59+
[0, 0, 100],
60+
[360, 81, 100],
61+
[360, 81, 100],
62+
[0, 0, 100],
63+
[0, 0, 100],
64+
[360, 81, 100],
65+
[360, 81, 100],
66+
[360, 81, 100],
67+
[360, 81, 100],
68+
[0, 0, 100],
69+
[0, 0, 100],
70+
[360, 81, 100],
71+
],
72+
}
73+
EFFECT_CHRISTMAS = {
74+
"custom": 0,
75+
"id": "bwTatyinOUajKrDwzMmqxxJdnInQUgvM",
76+
"brightness": 100,
77+
"name": "Christmas",
78+
"segments": [0],
79+
"expansion_strategy": 1,
80+
"enable": 1,
81+
"type": "random",
82+
"hue_range": [136, 146],
83+
"saturation_range": [90, 100],
84+
"brightness_range": [50, 100],
85+
"duration": 5000,
86+
"transition": 0,
87+
"init_states": [[136, 0, 100]],
88+
"fadeoff": 2000,
89+
"random_seed": 100,
90+
"backgrounds": [[136, 98, 75], [136, 0, 0], [350, 0, 100], [350, 97, 94]],
91+
}
92+
EFFECT_FLICKER = {
93+
"custom": 0,
94+
"id": "bCTItKETDFfrKANolgldxfgOakaarARs",
95+
"brightness": 100,
96+
"name": "Flicker",
97+
"segments": [1],
98+
"expansion_strategy": 1,
99+
"enable": 1,
100+
"type": "random",
101+
"hue_range": [30, 40],
102+
"saturation_range": [100, 100],
103+
"brightness_range": [50, 100],
104+
"duration": 0,
105+
"transition": 0,
106+
"transition_range": [375, 500],
107+
"init_states": [[30, 81, 80]],
108+
}
109+
EFFECT_HANUKKAH = {
110+
"custom": 0,
111+
"id": "CdLeIgiKcQrLKMINRPTMbylATulQewLD",
112+
"brightness": 100,
113+
"name": "Hanukkah",
114+
"segments": [1],
115+
"expansion_strategy": 1,
116+
"enable": 1,
117+
"type": "random",
118+
"hue_range": [200, 210],
119+
"saturation_range": [0, 100],
120+
"brightness_range": [50, 100],
121+
"duration": 1500,
122+
"transition": 0,
123+
"transition_range": [400, 500],
124+
"init_states": [[35, 81, 80]],
125+
}
126+
EFFECT_HAUNTED_MANSION = {
127+
"custom": 0,
128+
"id": "oJnFHsVQzFUTeIOBAhMRfVeujmSauhjJ",
129+
"brightness": 80,
130+
"name": "Haunted Mansion",
131+
"segments": [80],
132+
"expansion_strategy": 2,
133+
"enable": 1,
134+
"type": "random",
135+
"hue_range": [45, 45],
136+
"saturation_range": [10, 10],
137+
"brightness_range": [0, 80],
138+
"duration": 0,
139+
"transition": 0,
140+
"transition_range": [50, 1500],
141+
"init_states": [[45, 10, 100]],
142+
"fadeoff": 200,
143+
"random_seed": 1,
144+
"backgrounds": [[45, 10, 100]],
145+
}
146+
EFFECT_ICICLE = {
147+
"custom": 0,
148+
"id": "joqVjlaTsgzmuQQBAlHRkkPAqkBUiqeb",
149+
"brightness": 70,
150+
"name": "Icicle",
151+
"segments": [0],
152+
"expansion_strategy": 1,
153+
"enable": 1,
154+
"type": "sequence",
155+
"duration": 0,
156+
"transition": 400,
157+
"direction": 4,
158+
"spread": 3,
159+
"repeat_times": 0,
160+
"sequence": [
161+
[190, 100, 70],
162+
[190, 100, 70],
163+
[190, 30, 50],
164+
[190, 100, 70],
165+
[190, 100, 70],
166+
],
167+
}
168+
EFFECT_LIGHTNING = {
169+
"custom": 0,
170+
"id": "ojqpUUxdGHoIugGPknrUcRoyJiItsjuE",
171+
"brightness": 100,
172+
"name": "Lightning",
173+
"segments": [7, 20, 23, 32, 34, 35, 49, 65, 66, 74, 80],
174+
"expansion_strategy": 1,
175+
"enable": 1,
176+
"type": "random",
177+
"hue_range": [240, 240],
178+
"saturation_range": [10, 11],
179+
"brightness_range": [90, 100],
180+
"duration": 0,
181+
"transition": 50,
182+
"init_states": [[240, 30, 100]],
183+
"fadeoff": 150,
184+
"random_seed": 600,
185+
"backgrounds": [[200, 100, 100], [200, 50, 10], [210, 10, 50], [240, 10, 0]],
186+
}
187+
EFFECT_OCEAN = {
188+
"custom": 0,
189+
"id": "oJjUMosgEMrdumfPANKbkFmBcAdEQsPy",
190+
"brightness": 30,
191+
"name": "Ocean",
192+
"segments": [0],
193+
"expansion_strategy": 1,
194+
"enable": 1,
195+
"type": "sequence",
196+
"duration": 0,
197+
"transition": 2000,
198+
"direction": 3,
199+
"spread": 16,
200+
"repeat_times": 0,
201+
"sequence": [[198, 84, 30], [198, 70, 30], [198, 10, 30]],
202+
}
203+
EFFECT_RAINBOW = {
204+
"custom": 0,
205+
"id": "izRhLCQNcDzIKdpMPqSTtBMuAIoreAuT",
206+
"brightness": 100,
207+
"name": "Rainbow",
208+
"segments": [0],
209+
"expansion_strategy": 1,
210+
"enable": 1,
211+
"type": "sequence",
212+
"duration": 0,
213+
"transition": 1500,
214+
"direction": 1,
215+
"spread": 12,
216+
"repeat_times": 0,
217+
"sequence": [[0, 100, 100], [100, 100, 100], [200, 100, 100], [300, 100, 100]],
218+
}
219+
EFFECT_RAINDROP = {
220+
"custom": 0,
221+
"id": "QbDFwiSFmLzQenUOPnJrsGqyIVrJrRsl",
222+
"brightness": 30,
223+
"name": "Raindrop",
224+
"segments": [0],
225+
"expansion_strategy": 1,
226+
"enable": 1,
227+
"type": "random",
228+
"hue_range": [200, 200],
229+
"saturation_range": [10, 20],
230+
"brightness_range": [10, 30],
231+
"duration": 0,
232+
"transition": 1000,
233+
"init_states": [[200, 40, 100]],
234+
"fadeoff": 1000,
235+
"random_seed": 24,
236+
"backgrounds": [[200, 40, 0]],
237+
}
238+
EFFECT_SPRING = {
239+
"custom": 0,
240+
"id": "URdUpEdQbnOOechDBPMkKrwhSupLyvAg",
241+
"brightness": 100,
242+
"name": "Spring",
243+
"segments": [0],
244+
"expansion_strategy": 1,
245+
"enable": 1,
246+
"type": "random",
247+
"hue_range": [0, 90],
248+
"saturation_range": [30, 100],
249+
"brightness_range": [90, 100],
250+
"duration": 600,
251+
"transition": 0,
252+
"transition_range": [2000, 6000],
253+
"init_states": [[80, 30, 100]],
254+
"fadeoff": 1000,
255+
"random_seed": 20,
256+
"backgrounds": [[130, 100, 40]],
257+
}
258+
EFFECT_VALENTINES = {
259+
"custom": 0,
260+
"id": "QglBhMShPHUAuxLqzNEefFrGiJwahOmz",
261+
"brightness": 100,
262+
"name": "Valentines",
263+
"segments": [0],
264+
"expansion_strategy": 1,
265+
"enable": 1,
266+
"type": "random",
267+
"hue_range": [340, 340],
268+
"saturation_range": [30, 40],
269+
"brightness_range": [90, 100],
270+
"duration": 600,
271+
"transition": 2000,
272+
"init_states": [[340, 30, 100]],
273+
"fadeoff": 3000,
274+
"random_seed": 100,
275+
"backgrounds": [[340, 20, 50], [20, 50, 50], [0, 100, 50]],
276+
}
277+
278+
EFFECTS_LIST_V1 = [
279+
EFFECT_AURORA,
280+
EFFECT_BUBBLING_CAULDRON,
281+
EFFECT_CANDY_CANE,
282+
EFFECT_CHRISTMAS,
283+
EFFECT_FLICKER,
284+
EFFECT_HANUKKAH,
285+
EFFECT_HAUNTED_MANSION,
286+
EFFECT_ICICLE,
287+
EFFECT_LIGHTNING,
288+
EFFECT_OCEAN,
289+
EFFECT_RAINBOW,
290+
EFFECT_RAINDROP,
291+
EFFECT_SPRING,
292+
EFFECT_VALENTINES,
293+
]
294+
295+
EFFECT_NAMES_V1: List[str] = [cast(str, effect["name"]) for effect in EFFECTS_LIST_V1]
296+
EFFECT_MAPPING_V1 = {effect["name"]: effect for effect in EFFECTS_LIST_V1}

kasa/smartdevice.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,16 @@ def is_variable_color_temp(self) -> bool:
714714
"""Return True if the device supports color temperature."""
715715
return False
716716

717+
@property # type: ignore
718+
@requires_update
719+
def has_effects(self) -> bool:
720+
"""Return True if the device supports effects."""
721+
# Currently limited to KL430 since other strips
722+
# were not available for testing
723+
return "lighting_effect_state" in self.sys_info and self.sys_info[
724+
"model"
725+
].startswith("KL430")
726+
717727
@property
718728
def is_color(self) -> bool:
719729
"""Return True if the device supports color changes."""

0 commit comments

Comments
 (0)
0