jath03 / openrgb-python

A python client for the OpenRGB SDK
GNU General Public License v3.0
115 stars 22 forks source link

Detect if Client Connected or Not #38

Closed AidenJames1995 closed 3 years ago

AidenJames1995 commented 3 years ago

Is there any mechanism to determine if the client actually connects to the OpenRGB Server? The only way to have this start on log-in automatically (that I can find) is to have OpenRGB and my python script be triggered by the Windows start-up process. But if Windows starts the python script before OpenRGB the python script will never connect.

jath03 commented 3 years ago

The python script should raise an error if it doesn't connect. If it isn't then I'm going to need more information.

AidenJames1995 commented 3 years ago

I ended up doing this:

from openrgb import OpenRGBClient
from openrgb.utils import RGBColor, DeviceType
import time, socket

time.sleep(10)
client = 0
x = 0
while x <= 10:
    try:
        client = OpenRGBClient()
        break
    except socket.timeout:
        if x < 10:
            time.sleep(1)
            x += 1
        else:
            print("Failed to Connect")
            break

client.clear() # Turns everything off

devs = client.devices
for device in range(len(devs)):
    time.sleep(.05)
    d = client.devices[device]
    d.set_mode("direct")
    d.set_color(RGBColor(128, 0, 255))

I tried catching "ConnectionRefusedError" in place of socket.timeout but couldn't seems to catch the error.

jath03 commented 3 years ago

If you want to catch anything related to connection problems, OSError is the base of all those types of errors.