Skip to content

Commit

Permalink
Add example\dump_devices.py
Browse files Browse the repository at this point in the history
  • Loading branch information
intrueder committed Mar 4, 2023
1 parent c57981e commit 244a879
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions example/dump_devices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from cuesdk import (CueSdk, CorsairDeviceFilter, CorsairDeviceType,
CorsairError, CorsairSessionState, CorsairDeviceInfo)
import sys

COLS = ["Device type", "Model name", "LED count", "Channel count"]
COL_WIDTH = 28


def hr():
print("—" * COL_WIDTH * len(COLS))


def print_device(device: CorsairDeviceInfo):
print(f"{str(device.type)[18:]:{COL_WIDTH-2}} |"
f" {device.model:{COL_WIDTH-3}} |"
f" {device.led_count:{COL_WIDTH-3}} |"
f" {device.channel_count:{COL_WIDTH-2}}")


def main():
sdk = CueSdk()

def on_state_changed(evt):
print(evt.state)
# the app must wait for CSS_Connected event before proceeding
if evt.state == CorsairSessionState.CSS_Connected:
details, err = sdk.get_session_details()
print(details)

devices, err = sdk.get_devices(
CorsairDeviceFilter(
device_type_mask=CorsairDeviceType.CDT_All))
if err == CorsairError.CE_Success and devices:
hr()
print("|".join([f"{col:^{COL_WIDTH-1}}" for col in COLS]))
hr()
for d in devices:
device, err = sdk.get_device_info(d.device_id)
if device:
print_device(device)
hr()
else:
print(err)

err = sdk.connect(on_state_changed)
if err != CorsairError.CE_Success:
print("\nERROR: Unable to connect to iCUE")
print(err)
sys.exit()


if __name__ == "__main__":
main()
input() # wait for <Enter>

0 comments on commit 244a879

Please sign in to comment.