Beispiel #1
0
def pair_device(deviceAddress, scriptBasePath=''):
    script_path = scriptBasePath + PAIRING_AGENT
    script = str.join(' ', [sys.executable, script_path, deviceAddress])
    child = pexpect.spawn(script)
    paired = False
    while True:
        try:
            index = child.expect(['@EOL'], timeout=None)
            split = child.before.split('SOL@')
            if len(split[0]) > 0:
                log('Output From Pairing Agent ' + split[0])
            d = json.loads(split[1])
            return_value = d.keys()[0]
            messages = d.values()[0]
            log([
                'return_value = ' + return_value, 'Messages = ' + str(messages)
            ])
            if return_value == 'PAIRING_OK':
                paired = True
                break
            if return_value == 'DEVICE_NOT_FOUND':
                return False  # return early no need to call remove_device()
            if RUNNING_IN_KODI:
                deviceAlias = get_device_property(deviceAddress, 'Alias')
                returnValue = handleAgentInteraction(deviceAlias, return_value,
                                                     messages)
                if returnValue:
                    sendStr = encode_return('RETURN_VALUE', [returnValue])
                    child.sendline(sendStr)
        except pexpect.EOF:
            break
    if not paired:
        bluetooth.remove_device(deviceAddress)
        return False
    return True
Beispiel #2
0
def pair_device(deviceAddress, scriptBasePath = ''):
    script_path = scriptBasePath + PAIRING_AGENT
    script = str.join(' ', [sys.executable, script_path,deviceAddress])
    child = pexpect.spawn(script)
    paired = False
    while True:
        try:
            index = child.expect(['@EOL'], timeout=None)
            split = child.before.split('SOL@')
            if len(split[0]) >0:
                log('Output From Pairing Agent ' + split[0])
            d = json.loads(split[1])
            return_value = d.keys()[0]
            messages = d.values()[0]
            log(['return_value = '+ return_value, 'Messages = ' + str(messages)])
            if return_value == 'PAIRING_OK':
                paired = True
                break
            if return_value == 'DEVICE_NOT_FOUND':
                return False  # return early no need to call remove_device()
            if RUNNING_IN_KODI:
                deviceAlias = get_device_property(deviceAddress, 'Alias')
                returnValue = handleAgentInteraction(deviceAlias, return_value , messages)
                if returnValue:
                    if returnValue == 'NO_PIN_ENTERED':
                        return False
                    sendStr = encode_return('RETURN_VALUE', [ returnValue ])
                    child.sendline(sendStr)
        except pexpect.EOF:
            break
    if not paired:
        bluetooth.remove_device(deviceAddress)
        return False
    return True
Beispiel #3
0
def pair_device(deviceAddress, scriptBasePath=''):
    print 'Attempting to pair with ' + deviceAddress
    paired = False
    paired = pair_using_agent(deviceAddress, scriptBasePath)
    if not paired:
        bluetooth.remove_device(deviceAddress)
        return False
    return paired
Beispiel #4
0
def pair_device(deviceAddress, scriptBasePath = ''):
    print 'Attempting to pair with ' + deviceAddress
    paired = False
    paired = pair_using_agent(deviceAddress, scriptBasePath)
    if not paired:
        bluetooth.remove_device(deviceAddress)
        return False
    return paired
Beispiel #5
0
def pair_device(deviceAddress, scriptBasePath=""):
    print "Attempting to pair with " + deviceAddress
    paired = False
    paired = pair_using_agent(deviceAddress, scriptBasePath)
    if not paired:
        try:
            bluetooth.remove_device(deviceAddress)
        except:
            pass
        return False
    return paired
Beispiel #6
0
def pair_device(deviceAddress):
    try:
        exit_status = subprocess.call(
            [sys.executable, PAIRING_AGENT, deviceAddress])
    except:
        bluetooth.remove_device(deviceAddress)
        return False
    if not exit_status == 0:
        # if we have had issues connecting remove the device
        bluetooth.remove_device(deviceAddress)
        return False
    return True
Beispiel #7
0
def remove_device(deviceAddress):
    bluetooth.remove_device(deviceAddress)
Beispiel #8
0
def remove_device(deviceAddress):
    bluetooth.remove_device(deviceAddress)