Esempio n. 1
0
def connect_wifi():
    interface = selectWirelessInterface()
    if interface is None:
        print "There is no wireless interface available"
        return

    params = {}
    params['interface'] = interface
    wifiNetworks = []
    wifiNetworkStrings = []
    response = guh.send_command("NetworkManager.GetWirelessAccessPoints",
                                params)
    wifiNetworks = response['params']['wirelessAccessPoints']
    for accessPoint in wifiNetworks:
        wifiNetworkStrings.append(
            ("%10s | %s%s | %s %s | %s" %
             (accessPoint['ssid'], accessPoint['signalStrength'], '%',
              accessPoint['frequency'], '[GHz]', accessPoint['macAddress'])))

    selection = selector.get_selection("Wifi access points",
                                       wifiNetworkStrings)
    if not selection:
        return None

    params['ssid'] = wifiNetworks[selection]['ssid']
    if wifiNetworks[selection]['protected'] == True:
        params['password'] = raw_input(
            "Please enter the password for wifi network %s: " %
            (params['ssid']))

    response = guh.send_command("NetworkManager.ConnectWifiNetwork", params)
    guh.print_networkmanager_error_code(
        response['params']['networkManagerError'])
Esempio n. 2
0
def execute_rule_actions():
    ruleDescription = select_rule()
    if ruleDescription == None:
        print "\n    No rules found"
        return None
    ruleId = ruleDescription['id']
    params = {}
    params['ruleId'] = ruleId

    rule = guh.send_command("Rules.GetRuleDetails", params)['params']['rule']

    if len(rule['exitActions']) == 0:
        options = ["Execute actions"]
        selection = guh.get_selection(
            "Which actions of the rule should be executed?", options)
        response = guh.send_command("Rules.ExecuteActions", params)
        guh.print_rule_error_code(response['params']['ruleError'])
    else:
        options = ["Execute actions", "Execute exit actions"]
        selection = guh.get_selection(
            "Which actions of the rule should be executed?", options)
        if selection == None:
            return None

        if (options[selection] == "Execute actions"):
            response = guh.send_command("Rules.ExecuteActions", params)
            guh.print_rule_error_code(response['params']['ruleError'])
        else:
            response = guh.send_command("Rules.ExecuteExitActions", params)
            guh.print_rule_error_code(response['params']['ruleError'])

    return None
Esempio n. 3
0
def add_discovered_device(deviceClassId, deviceDescriptorId):
    deviceClass = get_deviceClass(deviceClassId)
    if deviceClass['setupMethod'] == "SetupMethodJustAdd":
        params = {}
        params['deviceClassId'] = deviceClassId
        params['deviceDescriptorId'] = deviceDescriptorId
        params['name'] = raw_input("\nEnter the \"name\" of the device: ")
        response = guh.send_command("Devices.AddConfiguredDevice", params)
        if not response['status'] != "success":
            guh.print_device_error_code(response['params']['deviceError'])
        else:
            print "Device added successfully. Device ID: %s\n" % response[
                'params']['deviceId']
    elif deviceClass['setupMethod'] == "SetupMethodPushButton":
        params = {}
        params['deviceClassId'] = deviceClassId
        params['deviceDescriptorId'] = deviceDescriptorId
        params['name'] = raw_input("\nEnter the \"name\" of the device: ")
        response = guh.send_command("Devices.PairDevice", params)
        #guh.print_json_format(response)
        if not response['status'] == "success":
            print "Pairing failed: %s", response['params']['deviceError']
            return
        print "\nPairing device %s\n\n%s\n\n" % (
            deviceClass['name'], response['params']['displayMessage'])
        if response['params']['setupMethod'] == "SetupMethodPushButton":
            raw_input("\nPress \"enter\" to confirm\n")
        params = {}
        params['pairingTransactionId'] = response['params'][
            'pairingTransactionId']
        response = guh.send_command("Devices.ConfirmPairing", params)
        guh.print_device_error_code(response['params']['deviceError'])
    elif deviceClass['setupMethod'] == "SetupMethodDisplayPin":
        params = {}
        params['deviceClassId'] = deviceClassId
        params['deviceDescriptorId'] = deviceDescriptorId
        params['name'] = raw_input("\nEnter the \"name\" of the device: ")
        response = guh.send_command("Devices.PairDevice", params)
        #guh.print_json_format(response)
        if not response['status'] == "success":
            print "Pairing failed: %s", response['params']['deviceError']
            return
        print "\nPairing device %s\n\n%s\n\n" % (
            deviceClass['name'], response['params']['displayMessage'])
        if response['params']['setupMethod'] == "SetupMethodDisplayPin":
            pin = raw_input("Pin: ")
        params = {}
        params['secret'] = pin
        params['pairingTransactionId'] = response['params'][
            'pairingTransactionId']
        response = guh.send_command("Devices.ConfirmPairing", params)
        guh.print_device_error_code(response['params']['deviceError'])
Esempio n. 4
0
def list_rule_details():
    ruleDescription = select_rule()
    if ruleDescription == None:
        print "\n    No rules found"
        return None
    params = {}
    params['ruleId'] = ruleDescription['id']
    rule = guh.send_command("Rules.GetRuleDetails", params)['params']['rule']
    print guh.print_json_format(rule)
    print "========================================================"
    print "-> Details for rule \"%s\" (%s):\n" % (rule['name'], rule['id'])
    print "Rule is %s" % (print_rule_enabled_status(bool(rule['enabled'])))
    print "Rule is %s" % (print_rule_active_status(bool(rule['active'])))
    print "Rule is %s" % (print_rule_executable_status(bool(
        rule['executable'])))

    print "\nTimeDescriptor:\n"
    timedescriptor.printTimeDescriptor(rule['timeDescriptor'])

    if len(rule['eventDescriptors']) > 0:
        print "\nEvents:\n"
        events.print_eventDescriptors(rule['eventDescriptors'])
    if rule['stateEvaluator']:
        print "\nStates:\n",
        states.print_stateEvaluator(rule['stateEvaluator'])
    print "\nActions:\n"
    ruleactions.print_ruleActionList(rule['actions'])
    if len(rule['exitActions']) > 0:
        print "\nExit actions:\n"
        ruleactions.print_ruleActionList(rule['exitActions'])
Esempio n. 5
0
def list_logEntries():
    params = {}
    lines = []
    response = guh.send_command("Logging.GetLogEntries", params)
    for i in range(len(response['params']['logEntries'])):
        line = get_log_entry_line(response['params']['logEntries'][i])
        print line
Esempio n. 6
0
def discover_device(deviceClassId=None):
    if deviceClassId == None:
        deviceClassId = select_deviceClass()
    deviceClass = get_deviceClass(deviceClassId)
    if not deviceClass:
        return None
    params = {}
    params['deviceClassId'] = deviceClassId
    discoveryParams = parameters.read_params(
        deviceClass['discoveryParamTypes'])
    if len(discoveryParams) > 0:
        params['discoveryParams'] = discoveryParams
    print "\ndiscovering..."
    response = guh.send_command("Devices.GetDiscoveredDevices", params)
    if not 'deviceDescriptors' in response['params']:
        print "no devices found"
    deviceDescriptorList = []
    deviceDescriptorIdList = []
    for deviceDescriptor in response['params']['deviceDescriptors']:
        deviceDescriptorList.append(
            "%s (%s)" %
            (deviceDescriptor['title'], deviceDescriptor['description']))
        deviceDescriptorIdList.append(deviceDescriptor['id'])
    if not deviceDescriptorIdList:
        print "\n    Timeout: no device found."
        return None
    selection = guh.get_selection("Please select a device descriptor",
                                  deviceDescriptorList)
    if selection != None:
        return deviceDescriptorIdList[selection]
    return None
Esempio n. 7
0
def edit_device():
    deviceId = select_configured_device()
    params = {}
    params['deviceId'] = deviceId
    params['name'] = raw_input("\nEnter the new \"name\" of the device: ")
    response = guh.send_command("Devices.EditDevice", params)
    guh.print_device_error_code(response['params']['deviceError'])
Esempio n. 8
0
def get_stateType(stateTypeId):
    params = {}
    params['stateTypeId'] = stateTypeId
    response = guh.send_command("States.GetStateType", params)
    if "stateType" in response['params']:
        return response['params']['stateType']
    return None
Esempio n. 9
0
def get_actionType(actionTypeId):
    params = {}
    params['actionTypeId'] = actionTypeId
    response = guh.send_command("Actions.GetActionType", params)
    if not 'actionType' in response['params']:
        return None
    return response['params']['actionType']
Esempio n. 10
0
def get_rule_description(ruleId):
    ruleDescriptions = []
    ruleDescriptions = guh.send_command("Rules.GetRules",
                                        {})['params']['ruleDescriptions']
    for ruleDescription in ruleDescriptions:
        if ruleDescription['id'] == ruleId:
            return ruleDescription
    return None
Esempio n. 11
0
def get_stateTypes(deviceClassId):
    params = {}
    params['deviceClassId'] = deviceClassId
    response = guh.send_command("Devices.GetStateTypes", params)
    if "stateTypes" in response['params']:
        return response['params']['stateTypes']
    else:
        return None
Esempio n. 12
0
def get_log_entry_lines():
    global logFilter
    lines = []
    response = guh.send_command("Logging.GetLogEntries", logFilter)
    for i in range(len(response['params']['logEntries'])):
        line = get_log_entry_line(response['params']['logEntries'][i])
        lines.append(line)
    return lines
Esempio n. 13
0
def show_network_status():
    params = {}
    response = guh.send_command("NetworkManager.GetNetworkStatus", params)
    if 'status' in response['params']:
        guh.print_json_format(response['params']['status'])
    else:
        guh.print_networkmanager_error_code(
            response['params']['networkManagerError'])
Esempio n. 14
0
def cloud_authenticate():
    params = {}
    params['username'] = raw_input(
        "\nEnter the \"username\" of your cloud account: ")
    params['password'] = raw_input(
        "\nEnter the \"password\" of your cloud account: ")
    response = guh.send_command("Cloud.Authenticate", params)
    guh.print_cloud_error_code(response['params']['cloudError'])
Esempio n. 15
0
def get_eventTypes(deviceClassId):
    params = {}
    params['deviceClassId'] = deviceClassId
    eventTypes = guh.send_command("Devices.GetEventTypes",
                                  params)['params']['eventTypes']
    if eventTypes:
        return eventTypes
    return None
Esempio n. 16
0
def set_plugin_configuration():
    pluginId = select_configurable_plugin()
    plugin = get_plugin(pluginId)
    paramTypes = plugin['paramTypes']
    params = {}
    params['pluginId'] = pluginId
    params['configuration'] = parameters.read_params(paramTypes)
    response = guh.send_command("Devices.SetPluginConfiguration", params)
    guh.print_device_error_code(response['params']['deviceError'])
Esempio n. 17
0
def remove_rule():
    ruleDescription = select_rule()
    if ruleDescription == None:
        print "\n    No rule found"
        return None
    params = {}
    params['ruleId'] = ruleDescription['id']
    response = guh.send_command("Rules.RemoveRule", params)
    guh.print_rule_error_code(response['params']['ruleError'])
Esempio n. 18
0
def enable_disable_rule():
    ruleDescription = select_rule()
    if ruleDescription == None:
        print "\n    No rules found"
        return
    actionTypes = ["enable", "disable"]
    selection = guh.get_selection("What do you want to do with this rule: ",
                                  actionTypes)
    if selection == 0:
        params = {}
        params['ruleId'] = ruleDescription['id']
        response = guh.send_command("Rules.EnableRule", params)
        guh.print_rule_error_code(response['params']['ruleError'])
    else:
        params = {}
        params['ruleId'] = ruleDescription['id']
        response = guh.send_command("Rules.DisableRule", params)
        guh.print_rule_error_code(response['params']['ruleError'])
Esempio n. 19
0
def disconnect_networkdevice():
    interface = selectWirelessInterface()
    if interface is None:
        print "There is no wireless interface available"
        return

    params = {}
    params['interface'] = interface
    response = guh.send_command("NetworkManager.DisconnectInterface", params)
    guh.print_networkmanager_error_code(
        response['params']['networkManagerError'])
Esempio n. 20
0
def set_language():
    params = {}
    languages = get_languages()
    selection = guh.get_selection(
        "Please select one of following allowed values:", languages)
    if selection == None:
        return None

    params['language'] = languages[selection]
    response = guh.send_command("Configuration.SetLanguage", params)
    guh.print_json_format(response['params'])
Esempio n. 21
0
def add_configured_device(deviceClassId):
    deviceClass = get_deviceClass(deviceClassId)
    params = {}
    params['deviceClassId'] = deviceClassId
    params['name'] = raw_input("\nEnter the \"name\" of the device: ")
    deviceParams = parameters.read_params(deviceClass['paramTypes'])
    if deviceParams:
        params['deviceParams'] = deviceParams
    print "\nAdding device with params:", guh.print_json_format(params)
    response = guh.send_command("Devices.AddConfiguredDevice", params)
    guh.print_device_error_code(response['params']['deviceError'])
Esempio n. 22
0
def scan_wirelessaccesspoints():
    interface = selectWirelessInterface()
    if interface is None:
        print "There is no wireless interface available"
        return

    params = {}
    params['interface'] = interface
    response = guh.send_command("NetworkManager.ScanWifiNetworks", params)
    guh.print_networkmanager_error_code(
        response['params']['networkManagerError'])
Esempio n. 23
0
def set_timezone():
    params = {}
    timeZones = []
    timeZones = get_timezones()
    selection = guh.get_selection(
        "Please select one of following allowed values:", timeZones)
    if selection == None:
        return None

    params['timeZone'] = timeZones[selection]
    response = guh.send_command("Configuration.SetTimeZone", params)
    guh.print_json_format(response['params'])
Esempio n. 24
0
def list_rules():
    response = guh.send_command("Rules.GetRules", {})
    if not response['params']['ruleDescriptions']:
        print "\n    No rules found. \n"
        return None
    print "-> List of configured Rules:\n"
    for i in range(len(response['params']['ruleDescriptions'])):
        ruleDescription = response['params']['ruleDescriptions'][i]
        print "%20s ( %s ) -> %s / %s" % (
            ruleDescription['name'], ruleDescription['id'],
            print_rule_enabled_status(bool(ruleDescription['enabled'])),
            print_rule_active_status(bool(ruleDescription['active'])))
Esempio n. 25
0
def enable_cloud_connection():
    params = {}
    options = ["enable", "disable"]
    selection = guh.get_selection(
        "Do you want to do with the cloud connection: ", options)
    if selection == 0:
        params['enable'] = True
    else:
        params['enable'] = False

    response = guh.send_command("Cloud.Enable", params)
    guh.print_json_format(response['params'])
Esempio n. 26
0
def enable_networking():
    params = {}
    options = ["enable", "disable"]
    selection = guh.get_selection("Do you want to do with the networking: ",
                                  options)
    if selection == 0:
        params['enable'] = True
    else:
        params['enable'] = False

    response = guh.send_command("NetworkManager.EnableNetworking", params)
    guh.print_networkmanager_error_code(
        response['params']['networkManagerError'])
Esempio n. 27
0
def reconfigure_device():
    deviceId = select_configured_device()
    device = get_device(deviceId)
    if not device:
        return None
    deviceClass = get_deviceClass(device['deviceClassId'])
    if not deviceClass:
        return None
    deviceParamTypes = deviceClass['paramTypes']
    currentDeviceParams = device['params']
    createMethod = select_createMethod(
        "Please select how do you want to edit this device",
        deviceClass['createMethods'])
    print " --> Using create method \"%s\"\n" % (createMethod)
    params = {}
    if createMethod == "CreateMethodUser":
        newDeviceParams = parameters.edit_params(currentDeviceParams,
                                                 deviceParamTypes)
        params['deviceId'] = deviceId
        params['deviceParams'] = newDeviceParams
        response = guh.send_command("Devices.ReconfigureDevice", params)
        guh.print_device_error_code(response['params']['deviceError'])
    elif createMethod == "CreateMethodDiscovery":
        deviceDescriptorId = discover_device(device['deviceClassId'])
        if not deviceDescriptorId:
            return None
        print "using descriptorId %s" % (deviceDescriptorId)
        params['deviceId'] = deviceId
        params['deviceDescriptorId'] = deviceDescriptorId
        response = guh.send_command("Devices.ReconfigureDevice", params)
        guh.print_device_error_code(response['params']['deviceError'])
    elif createMethod == "CreateMethodAuto":
        newDeviceParams = parameters.edit_params(currentDeviceParams,
                                                 deviceParamTypes)
        params['deviceId'] = deviceId
        params['deviceParams'] = newDeviceParams
        response = guh.send_command("Devices.ReconfigureDevice", params)
        guh.print_device_error_code(response['params']['deviceError'])
Esempio n. 28
0
def remove_configured_device():
    deviceId = select_configured_device()
    if not deviceId:
        return None
    print "Removing device with DeviceId%s" % deviceId
    params = {}
    params['deviceId'] = deviceId
    response = guh.send_command("Devices.RemoveConfiguredDevice", params)

    if response['params']['deviceError'] == 'DeviceErrorDeviceInRule':
        selectionString = "This device is used in a rule. How do you want to remove the device from the rules?"
        removePolicys = [
            "Remove the device from the rules", "Delete all offending rules"
        ]
        selection = guh.get_selection(selectionString, removePolicys)

        if removePolicys[selection] == "Remove the device from the rules":
            params['removePolicy'] = "RemovePolicyUpdate"
        else:
            params['removePolicy'] = "RemovePolicyCascade"

        response = guh.send_command("Devices.RemoveConfiguredDevice", params)

    guh.print_device_error_code(response['params']['deviceError'])
Esempio n. 29
0
def list_device_states():
    deviceId = select_configured_device()
    if deviceId == None:
        return None
    device = get_device(deviceId)
    deviceClass = get_deviceClass(device['deviceClassId'])
    print "-> States of device \"%s\" %s:\n" % (get_full_device_name(deviceId),
                                                device['id'])
    for i in range(len(deviceClass['stateTypes'])):
        params = {}
        params['deviceId'] = deviceId
        params['stateTypeId'] = deviceClass['stateTypes'][i]['id']
        response = guh.send_command("Devices.GetStateValue", params)
        print "%35s: %s" % (deviceClass['stateTypes'][i]['name'],
                            response['params']['value'])
Esempio n. 30
0
def add_rule():
    params = {}
    params['name'] = raw_input("Please enter the name of the rule: ")

    print "\n========================================================"
    if selector.getYesNoSelection("Do you want to create a TimeDescriptor"):
        params['timeDescriptor'] = timedescriptor.createTimeDescriptor()

    if selector.getYesNoSelection(
            "Do you want to define \"Events\" for this rule?"):
        eventDescriptors = events.create_eventDescriptors()
        print guh.print_json_format(eventDescriptors)
        params['eventDescriptors'] = eventDescriptors

        if selector.getYesNoSelection(
                "Do you want to add conditions (\"States\") for the events?"):
            print "\n========================================================"
            raw_input("-> Create a state descriptor!  ")
            stateEvaluator = states.create_stateEvaluator()
            params['stateEvaluator'] = stateEvaluator

        params['actions'] = ruleactions.create_rule_actions(eventDescriptors)

    else:

        if selector.getYesNoSelection(
                "Do you want to define \"States\" for this rule?"):
            print "\n========================================================"
            raw_input("-> Press \"enter\" to create a state descriptor!  ")
            params['stateEvaluator'] = states.create_stateEvaluator()

        params['actions'] = ruleactions.create_rule_actions()

        if selector.getYesNoSelection(
                "Do you want to add (\"ExitActions\") for this rule?"):
            params['exitActions'] = ruleactions.create_rule_actions()

    params['enabled'] = selector.getBoolSelection(
        "-> Should the rule initially be enabled?")
    params['executable'] = selector.getBoolSelection(
        "-> Should the rule be executable?")

    print "\n========================================================\n"
    print "Adding rule with params:\n", guh.print_json_format(params)
    response = guh.send_command("Rules.AddRule", params)
    guh.print_rule_error_code(response['params']['ruleError'])