-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbatch_operations.py
More file actions
60 lines (49 loc) · 1.66 KB
/
batch_operations.py
File metadata and controls
60 lines (49 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
"""
Batch operations example.
Demonstrates:
- Importing devices from Python modules
- Creating device collections
- Controlling multiple devices concurrently
- Batch power, brightness, and color operations
"""
import time
# Import devices directly from generated module
# (Run setup script first to generate govee_devices.py)
from govee_devices import garage_left, garage_right
from govee import Colors, GoveeClient
# Initialize client
client = GoveeClient(
api_key="your-api-key-here",
prefer_lan=True,
max_workers=10, # Control up to 10 devices simultaneously
log_level="INFO"
)
# Create a collection of garage lights using imported devices
garage_lights = client.create_collection("garage", [
garage_left,
garage_right
])
print(f"Controlling {len(garage_lights)} devices: {[d.name for d in garage_lights]}")
# Turn all on concurrently
print("\nTurning all on...")
results = client.power_all(garage_lights, on=True)
print(f"Success: {sum(results.values())}/{len(results)}")
time.sleep(1)
# Set brightness on all
print("\nSetting brightness to 75%...")
results = client.set_brightness_all(garage_lights, 75)
print(f"Success: {sum(results.values())}/{len(results)}")
time.sleep(1)
# Cycle through colors
colors = [Colors.RED, Colors.GREEN, Colors.BLUE, Colors.PURPLE]
for color in colors:
print(f"\nSetting color to {color}...")
results = client.set_color_all(garage_lights, color)
print(f"Success: {sum(results.values())}/{len(results)}")
time.sleep(2)
# Turn all off
print("\nTurning all off...")
results = client.power_all(garage_lights, on=False)
print(f"Success: {sum(results.values())}/{len(results)}")
print("\nDone!")