# start LighthouseConsole
from subprocess import Popen
import steamvr

lh = []
instances = 4
for i in range(instances):
  lh.append(steamvr.LighthouseConsole.create())
print('Started new LighthouseConsole instance')

devices = lh[0].list_hardware()
print(devices)

# pair USB-connected controllers to the HMD
radios = ['dyx', 'ryb']
radioIndex = 0

for device in devices:
    if device['device_class'] == 'controller':
        lh[radioIndex].open()
        lh[radioIndex].select_device(device['serial'])
        lh[radioIndex+2].open()
        lh[radioIndex+2].select_device(radios[radioIndex])
        lh[radioIndex].pair()
        lh[radioIndex+2].pair()
        radioIndex += 1
        if radioIndex >= len(radios):
            break
for i in range(instances):
    # lh[i].reboot_device()
    lh[i].close()
print('Paired controllers to HMD')

p = Popen("endPairing.bat", cwd=r".")
stdout, stderr = p.communicate()