(func, *args, max_retries=2, **kwargs)
| 88 | |
| 89 | # Helper to retry operations if server disconnected |
| 90 | def safe_command(func, *args, max_retries=2, **kwargs): |
| 91 | for attempt in range(max_retries): |
| 92 | try: |
| 93 | return func(*args, **kwargs) |
| 94 | except ConnectionError: |
| 95 | if attempt < max_retries - 1: |
| 96 | # Server might have disconnected us, try to reconnect |
| 97 | time.sleep(1.0) |
| 98 | try: |
| 99 | api_client.disconnect() |
| 100 | api_client.connect() |
| 101 | except: |
| 102 | pass |
| 103 | else: |
| 104 | # Final attempt failed, ignore |
| 105 | pass |
| 106 | except Exception: |
| 107 | pass |
| 108 | |
| 109 | # Clean up before test |
| 110 | safe_command(api_client.disconnect_device) |
no test coverage detected