Skip to content

Commit e7787f4

Browse files
committed
cleanup: uv formatted code.
1 parent 9b66b5e commit e7787f4

16 files changed

+308
-257
lines changed

selection_demo.py

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ def demo_light_discovery():
1212
"""Show what lights are available and their names."""
1313
print("🔍 Light Discovery")
1414
print("=" * 50)
15-
15+
1616
with LightController() as controller:
1717
print(f"Total lights detected: {len(controller)}")
18-
18+
1919
if controller:
2020
print("\nAvailable lights:")
2121
for i, name in enumerate(controller.list_lights()):
2222
print(f" {i}: {name}")
2323
else:
2424
print("No lights found - connect some USB lights to see the demo!")
2525
return False
26-
26+
2727
print()
2828
return True
2929

@@ -32,90 +32,90 @@ def demo_select_all():
3232
"""Demonstrate selecting all lights."""
3333
print("🌟 Select All Lights")
3434
print("=" * 50)
35-
35+
3636
with LightController() as controller:
3737
selection = controller.all()
3838
print(f"Selected {len(selection)} lights: {selection.names()}")
39-
39+
4040
if selection:
4141
print("Turning all lights GREEN for 2 seconds...")
4242
selection.turn_on("green")
4343
time.sleep(2)
4444
selection.turn_off()
45-
45+
4646
print()
4747

4848

4949
def demo_select_by_index():
5050
"""Demonstrate selecting lights by index."""
5151
print("🎯 Select by Index")
5252
print("=" * 50)
53-
53+
5454
with LightController() as controller:
5555
# First light only
5656
selection = controller.by_index(0)
5757
print(f"First light: {selection.names()}")
58-
58+
5959
if selection:
6060
print("Blinking first light BLUE 3 times...")
6161
selection.blink("blue", count=3, speed="fast")
6262
time.sleep(2)
63-
63+
6464
# Multiple specific indices
6565
if len(controller) >= 3:
6666
selection = controller.by_index(0, 2)
6767
print(f"Lights 0 and 2: {selection.names()}")
68-
68+
6969
print("Turning lights 0 and 2 RED...")
7070
selection.turn_on("red")
7171
time.sleep(1)
7272
selection.turn_off()
73-
73+
7474
print()
7575

7676

7777
def demo_select_by_name():
7878
"""Demonstrate selecting lights by exact name."""
79-
print("📛 Select by Name")
79+
print("📛 Select by Name")
8080
print("=" * 50)
81-
81+
8282
with LightController() as controller:
8383
available_names = controller.list_lights()
84-
84+
8585
if available_names:
8686
# Select first available light by name
8787
first_name = available_names[0]
8888
selection = controller.by_name(first_name)
8989
print(f"Selected '{first_name}': {len(selection)} light(s)")
90-
90+
9191
if selection:
9292
print(f"Turning '{first_name}' YELLOW...")
9393
selection.turn_on("yellow")
9494
time.sleep(1)
9595
selection.turn_off()
96-
96+
9797
# Try to select multiple by name (if available)
9898
if len(available_names) >= 2:
9999
selection = controller.by_name(available_names[0], available_names[1])
100100
print(f"Selected multiple by name: {selection.names()}")
101-
101+
102102
if selection:
103103
print("Blinking selected lights PURPLE...")
104104
selection.blink("purple", count=2)
105105
time.sleep(2)
106-
106+
107107
print()
108108

109109

110110
def demo_select_by_pattern():
111111
"""Demonstrate selecting lights using regex patterns."""
112112
print("🔍 Select by Pattern")
113113
print("=" * 50)
114-
114+
115115
with LightController() as controller:
116116
available_names = controller.list_lights()
117117
print(f"Available lights: {available_names}")
118-
118+
119119
# Try common patterns
120120
patterns_to_try = [
121121
("Blyn.*", "Blynclight devices"),
@@ -124,108 +124,108 @@ def demo_select_by_pattern():
124124
("Mute.*", "MuteMe devices"),
125125
(r".*\(\d+\)", "Devices with numbers in parentheses"),
126126
]
127-
127+
128128
for pattern, description in patterns_to_try:
129129
selection = controller.by_pattern(pattern)
130130
if selection:
131131
print(f"Pattern '{pattern}' ({description}): {selection.names()}")
132-
132+
133133
print(f" Blinking matched lights CYAN...")
134134
selection.blink("cyan", count=2, speed="medium")
135135
time.sleep(1.5)
136136
else:
137137
print(f"Pattern '{pattern}' ({description}): No matches")
138-
138+
139139
print()
140140

141141

142142
def demo_practical_scenarios():
143143
"""Show practical real-world usage scenarios."""
144144
print("💡 Practical Usage Scenarios")
145145
print("=" * 50)
146-
146+
147147
with LightController() as controller:
148148
print("Scenario 1: Status Light System")
149-
149+
150150
# Use first light as status indicator
151151
status_light = controller.first()
152152
if status_light:
153153
print(" System OK (GREEN)")
154154
status_light.turn_on("green")
155155
time.sleep(1)
156-
156+
157157
print(" Warning (YELLOW blink)")
158158
status_light.blink("yellow", count=3)
159159
time.sleep(2)
160-
160+
161161
print(" Error (RED blink)")
162162
status_light.blink("red", count=5)
163163
time.sleep(3)
164-
164+
165165
status_light.turn_off()
166-
166+
167167
print("\nScenario 2: Work Lighting Control")
168-
168+
169169
# Turn on work lights (any lights available)
170170
work_lights = controller.all()
171171
if work_lights:
172172
print(" Setting work lighting (soft white)")
173173
work_lights.turn_on("white")
174174
time.sleep(1)
175-
175+
176176
print(" Focus mode (bright blue)")
177177
work_lights.turn_on("blue")
178178
time.sleep(1)
179-
179+
180180
print(" Break time (off)")
181181
work_lights.turn_off()
182-
182+
183183
print("\nScenario 3: Meeting Status")
184-
184+
185185
# Use pattern to control webcam-related lights
186-
meeting_lights = controller.by_pattern(".*") # All lights for demo
186+
meeting_lights = controller.by_pattern(".*") # All lights for demo
187187
if meeting_lights:
188188
print(" Meeting started (steady red)")
189189
meeting_lights.turn_on("red")
190190
time.sleep(1)
191-
191+
192192
print(" Do not disturb (blinking red)")
193193
meeting_lights.blink("red", count=3)
194194
time.sleep(2)
195-
195+
196196
print(" Meeting ended (brief green)")
197197
meeting_lights.turn_on("green")
198198
time.sleep(1)
199199
meeting_lights.turn_off()
200-
200+
201201
print()
202202

203203

204204
def demo_error_handling():
205205
"""Show how selection methods handle errors gracefully."""
206206
print("⚠️ Error Handling")
207207
print("=" * 50)
208-
208+
209209
with LightController() as controller:
210210
# These won't crash - they'll log warnings and return empty selections
211-
211+
212212
print("Trying invalid index (999)...")
213213
invalid_selection = controller.by_index(999)
214214
print(f" Result: {len(invalid_selection)} lights selected")
215215
invalid_selection.turn_on("red") # No-op, no error
216-
216+
217217
print("Trying non-existent name...")
218218
missing_selection = controller.by_name("NonExistentLight")
219219
print(f" Result: {len(missing_selection)} lights selected")
220220
missing_selection.blink("blue") # No-op, no error
221-
221+
222222
print("Trying pattern with no matches...")
223223
empty_selection = controller.by_pattern("ZZZZZ_NO_MATCH")
224224
print(f" Result: {len(empty_selection)} lights selected")
225225
empty_selection.turn_off() # No-op, no error
226-
226+
227227
print("All operations completed without errors!")
228-
228+
229229
print()
230230

231231

@@ -235,26 +235,26 @@ def main():
235235
print("=" * 60)
236236
print("This demo shows all the ways to select specific lights.")
237237
print("Connect some USB lights to see the full effect!\n")
238-
238+
239239
# Check if lights are available
240240
has_lights = demo_light_discovery()
241-
241+
242242
if not has_lights:
243243
print("Demo requires USB lights to be connected.")
244244
print("The selection methods will work, but you won't see any visual effects.")
245245
print()
246-
246+
247247
# Run all demos
248248
demo_select_all()
249249
demo_select_by_index()
250250
demo_select_by_name()
251251
demo_select_by_pattern()
252252
demo_practical_scenarios()
253253
demo_error_handling()
254-
254+
255255
print("✅ Demo complete! The new LightController provides flexible,")
256256
print(" intuitive ways to select exactly the lights you want to control.")
257257

258258

259259
if __name__ == "__main__":
260-
main()
260+
main()

src/busylight/api/busylight_api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ def off(self, light_id: int = None) -> None:
9797
else:
9898
self.controller.by_index(light_id).turn_off()
9999

100-
async def apply_effect(self, effect: Effects, light_id: int = None, led: int = 0) -> None:
100+
async def apply_effect(
101+
self, effect: Effects, light_id: int = None, led: int = 0
102+
) -> None:
101103
if light_id is None:
102104
self.controller.all().apply_effect(effect, led=led)
103105
else:

0 commit comments

Comments
 (0)