Skip to content

Commit f3feeea

Browse files
committed
fix: Improve error handling and device selection in Q10 VacuumTrait test script
1 parent ebdf213 commit f3feeea

File tree

1 file changed

+85
-76
lines changed

1 file changed

+85
-76
lines changed

examples/Q10/test_q10_vacuum.py

Lines changed: 85 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
"""Test script for Q10 VacuumTrait functionality."""
2+
"""Basic test script for Q10 VacuumTrait functionality."""
33

44
import asyncio
55
import pathlib
@@ -42,83 +42,92 @@ async def get_or_create_session() -> UserParams:
4242

4343
async def main():
4444
"""Test Q10 vacuum commands."""
45-
user_params = await get_or_create_session()
46-
cache = FileCache(CACHE_PATH)
47-
48-
# Create device manager and get devices
49-
device_manager = await create_device_manager(user_params, cache=cache)
50-
devices = await device_manager.get_devices()
51-
52-
print(f"\n📱 Found {len(devices)} device(s)")
53-
54-
# List all devices
55-
for idx, device in enumerate(devices, 1):
56-
print(f" {idx}. {device.name} ({device.model})")
57-
58-
# Select device
59-
if len(devices) == 1:
60-
device = devices[0]
61-
print(f"\n✅ Using device: {device.name}")
62-
else:
63-
device_idx = int(input("\nSelect device number: ")) - 1
64-
device = devices[device_idx]
65-
66-
# Check if it's a Q10 device with the vacuum trait
67-
if not hasattr(device, 'b01_q10_properties') or device.b01_q10_properties is None:
68-
print("\n❌ This device doesn't support Q10 properties (not a Q10 device?)")
69-
print(f" Device type: {device.model}")
70-
return
71-
72-
vacuum = device.b01_q10_properties.vacuum
73-
74-
print("\n🤖 Q10 Vacuum Trait Test Menu")
75-
print("=" * 50)
76-
print("1. Start cleaning")
77-
print("2. Pause cleaning")
78-
print("3. Resume cleaning")
79-
print("4. Stop cleaning")
80-
print("5. Return to dock")
81-
print("0. Exit")
82-
print("=" * 50)
83-
84-
while True:
85-
try:
86-
choice = input("\nEnter your choice (0-5): ").strip()
87-
88-
if choice == "0":
89-
print("👋 Exiting...")
45+
try:
46+
user_params = await get_or_create_session()
47+
cache = FileCache(CACHE_PATH)
48+
49+
print("🔄 Connecting to devices...")
50+
device_manager = await create_device_manager(user_params, cache=cache)
51+
devices = await device_manager.get_devices()
52+
53+
print(f"\n📱 Found {len(devices)} device(s)")
54+
55+
# List all devices
56+
for idx, device in enumerate(devices, 1):
57+
print(f" {idx}. {device.name} ({device.product.model})")
58+
59+
# Select device
60+
if len(devices) == 1:
61+
device = devices[0]
62+
print(f"\n✅ Using device: {device.name}")
63+
else:
64+
device_idx = int(input("\nSelect device number: ")) - 1
65+
device = devices[device_idx]
66+
print(f"\n✅ Selected device: {device.name}")
67+
68+
# Check if it's a Q10 device
69+
if device.b01_q10_properties is None:
70+
print("\n❌ This device doesn't have Q10 properties")
71+
print(f" Model: {device.product.model}")
72+
await cache.flush()
73+
return
74+
75+
vacuum = device.b01_q10_properties.vacuum
76+
77+
print("\n🤖 Q10 Vacuum Trait Test Menu")
78+
print("=" * 50)
79+
print("1. Start cleaning")
80+
print("2. Pause cleaning")
81+
print("3. Resume cleaning")
82+
print("4. Stop cleaning")
83+
print("5. Return to dock")
84+
print("0. Exit")
85+
print("=" * 50)
86+
87+
while True:
88+
try:
89+
choice = input("\nEnter your choice (0-5): ").strip()
90+
91+
if choice == "0":
92+
print("👋 Exiting...")
93+
break
94+
elif choice == "1":
95+
print("▶️ Starting cleaning...")
96+
await vacuum.start_clean()
97+
print("✅ Start cleaning command sent!")
98+
elif choice == "2":
99+
print("⏸️ Pausing cleaning...")
100+
await vacuum.pause_clean()
101+
print("✅ Pause command sent!")
102+
elif choice == "3":
103+
print("▶️ Resuming cleaning...")
104+
await vacuum.resume_clean()
105+
print("✅ Resume command sent!")
106+
elif choice == "4":
107+
print("⏹️ Stopping cleaning...")
108+
await vacuum.stop_clean()
109+
print("✅ Stop command sent!")
110+
elif choice == "5":
111+
print("🏠 Returning to dock...")
112+
await vacuum.return_to_dock()
113+
print("✅ Return to dock command sent!")
114+
else:
115+
print("❌ Invalid choice, please try again")
116+
except KeyboardInterrupt:
117+
print("\n👋 Exiting...")
90118
break
91-
elif choice == "1":
92-
print("▶️ Starting cleaning...")
93-
await vacuum.start_clean()
94-
print("✅ Start cleaning command sent!")
95-
elif choice == "2":
96-
print("⏸️ Pausing cleaning...")
97-
await vacuum.pause_clean()
98-
print("✅ Pause command sent!")
99-
elif choice == "3":
100-
print("▶️ Resuming cleaning...")
101-
await vacuum.resume_clean()
102-
print("✅ Resume command sent!")
103-
elif choice == "4":
104-
print("⏹️ Stopping cleaning...")
105-
await vacuum.stop_clean()
106-
print("✅ Stop command sent!")
107-
elif choice == "5":
108-
print("🏠 Returning to dock...")
109-
await vacuum.return_to_dock()
110-
print("✅ Return to dock command sent!")
111-
else:
112-
print("❌ Invalid choice, please try again")
113-
except KeyboardInterrupt:
114-
print("\n👋 Exiting...")
115-
break
116-
except Exception as e:
117-
print(f"❌ Error: {e}")
118-
import traceback
119-
traceback.print_exc()
119+
except Exception as e:
120+
print(f"❌ Error: {e}")
121+
import traceback
122+
traceback.print_exc()
123+
124+
await cache.flush()
120125

121-
await cache.flush()
126+
except Exception as e:
127+
print(f"\n❌ Fatal error: {e}")
128+
import traceback
129+
traceback.print_exc()
130+
122131

123132
if __name__ == "__main__":
124133
asyncio.run(main())

0 commit comments

Comments
 (0)