Example #1
0
def createCalendarItem():
    print "\n========================================================"
    print "Create calendar item\n"
    calendarItem = {}
    if selector.getYesNoSelection(
            "Do you want a calendar entry for a certain date and time?"):
        timeString = raw_input(
            "Please enter unix time for this calendar item (\"DD.MM.YYYY hh:mm\"): "
        )
        calendarItem['datetime'] = int(
            time.mktime(time.strptime(timeString, "%d.%m.%Y %H:%M")))
        if selector.getYesNoSelection(
                "Do you want to define a repeating option for this calendar item?"
        ):
            calendarItem['repeating'] = createRepeatingOption(True)

    else:
        calendarItem['startTime'] = raw_input(
            "Please enter the start time of this calendar item (\"hh:mm\"): ")
        if selector.getYesNoSelection(
                "Do you want to define a repeating option for this calendar item?"
        ):
            calendarItem['repeating'] = createRepeatingOption()

    print "\n========================================================"
    calendarItem['duration'] = int(
        raw_input("duration of the calendar item (\"minutes\") = "))
    print calendarItem
    return calendarItem
Example #2
0
def createTimeEventItem():
    print "\n========================================================"
    print "Create time event item\n"
    timeEventItem = {}
    if selector.getYesNoSelection(
            "Do you want a time event for a certain date and time?"):
        timeString = raw_input(
            "Please enter unix time for this time event (\"DD.MM.YYYY hh:mm\"): "
        )
        timeEventItem['datetime'] = int(
            time.mktime(time.strptime(timeString, "%d.%m.%Y %H:%M")))
        if selector.getYesNoSelection(
                "Do you want to define a repeating option for this time event item?"
        ):
            timeEventItem['repeating'] = createRepeatingOption(True)

    else:
        timeEventItem['time'] = raw_input(
            "Please enter the time for this time event (\"hh:mm\"): ")
        if selector.getYesNoSelection(
                "Do you want to define a repeating option for this time event item?"
        ):
            timeEventItem['repeating'] = createRepeatingOption()

    return timeEventItem
Example #3
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 nymea.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", nymea.print_json_format(params)
    response = nymea.send_command("Rules.AddRule", params)
    nymea.print_rule_error_code(response['params']['ruleError'])
Example #4
0
def set_debug_server_interface():
    params = {}
    enabled = selector.getYesNoSelection(
        "Should the debug server interface be enabled?")
    if enabled == None:
        return None

    params['enabled'] = enabled
    response = nymea.send_command("Configuration.SetDebugServerEnabled",
                                  params)
    nymea.print_json_format(response['params'])
Example #5
0
def edit_rule():
    ruleDescription = select_rule()
    if ruleDescription == None:
        print "\n    No rules found"
        return None

    boolTypes = ["yes", "no"]

    params = {}
    params['ruleId'] = ruleDescription['id']
    originalRule = nymea.send_command("Rules.GetRuleDetails",
                                      params)['params']['rule']
    print "\n========================================================"
    print "Original rule JSON:\n"
    print nymea.print_json_format(originalRule)

    if selector.getYesNoSelection(
            "Do you want to chane the name (current = \"%s\"): " %
        (originalRule['name'])):
        print "\n========================================================"
        params['name'] = raw_input(
            "Please enter the new name of the rule (current = \"%s\"): " %
            (originalRule['name']))
    else:
        params['name'] = originalRule['name']

    if len(originalRule['eventDescriptors']) > 0:
        print "\nCurrent \"Events\":\n"
        events.print_eventDescriptors(originalRule['eventDescriptors'])
        print "\n========================================================\n"

        input = raw_input("Do you want change this \"Events\" (y/N): ")
        if input == "y":
            eventDescriptors = events.create_eventDescriptors()
            print nymea.print_json_format(eventDescriptors)
            params['eventDescriptors'] = eventDescriptors
        else:
            params['eventDescriptors'] = originalRule['eventDescriptors']

        if originalRule['stateEvaluator']:
            print "\nStates:\n",
            states.print_stateEvaluator(originalRule['stateEvaluator'])

        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

        print "\ncurrent \"Actions\":\n"
        ruleactions.print_ruleActionList(originalRule['actions'])
        print "\n========================================================\n"
        input = raw_input("Do you want change this \"Actions\" (y/N): ")
        if input == "y":
            params['actions'] = ruleactions.create_rule_actions()
        else:
            params['actions'] = originalRule['actions']
    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()

        # there will always be at least one action
        print "\n========================================================\n"
        print "Current \"Actions\":\n"
        ruleactions.print_ruleActionList(originalRule['actions'])

        print "\n========================================================\n"
        input = raw_input("Do you want change this \"Actions\" (y/N): ")
        if input == "y":
            params['actions'] = ruleactions.create_rule_actions()
        else:
            params['actions'] = originalRule['actions']

        if len(originalRule['exitActions']) > 0:
            print "\n========================================================\n"
            print "Current \"Actions\":\n"
            ruleactions.print_ruleActionList(originalRule['exitActions'])
            input = raw_input("Do you want change this \"Events\" (y/N): ")
            if input == "y":
                params['exitActions'] = ruleactions.create_rule_actions()
            else:
                params['exitActions'] = originalRule['exitActions']

        else:
            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 "Edit rule with params:\n", nymea.print_json_format(params)
    response = nymea.send_command("Rules.EditRule", params)
    nymea.print_rule_error_code(response['params']['ruleError'])
Example #6
0
def configure_webSocketServer():
    configurations = nymea.send_command("Configuration.GetConfigurations")
    webSocketConfigs = configurations['params'][
        'webSocketServerConfigurations']
    configList = []
    for i in range(len(webSocketConfigs)):
        configList.append(
            "%s:%s   SSL:%s   Auth:%s" %
            (webSocketConfigs[i]['address'], webSocketConfigs[i]['port'],
             webSocketConfigs[i]['sslEnabled'],
             webSocketConfigs[i]['authenticationEnabled']))
    configList.append("New entry")
    selection = nymea.get_selection("Please select a configuration",
                                    configList)
    if selection == None:
        return None

    params = {}
    configuration = {}
    if selection == len(configList) - 1:
        # new config
        configuration['id'] = str(uuid.uuid4())
        configuration['address'] = raw_input(
            "\nEnter the \"address\" of the WebSocket server: ")
        configuration['port'] = raw_input(
            "\nEnter the \"port\" of the WebSocket server: ")
        configuration['sslEnabled'] = selector.getYesNoSelection(
            "Should SSL be enabled?")
        configuration['authenticationEnabled'] = selector.getYesNoSelection(
            "Should authentication be enabled?")
    else:

        selectedConfig = webSocketConfigs[selection]

        editList = []
        editList.append("Modify")
        editList.append("Delete")
        editSelection = nymea.get_selection(
            "Do you want to edit or delete the server interface?", editList)
        if editSelection == None:
            return None

        if editSelection == 1:  #delete
            params = {}
            params['id'] = selectedConfig['id']
            nymea.send_command(
                "Configuration.DeleteWebSocketServerConfiguration", params)
            return None

        configuration['id'] = selectedConfig['id']
        configuration['address'] = raw_input(
            "\nEnter the \"address\" of the WebSocket server (current \"%s\"): "
            % (selectedConfig['address']))
        configuration['port'] = raw_input(
            "\nEnter the \"port\" of the WebSocket server (current %s): " %
            (selectedConfig['port']))
        configuration['sslEnabled'] = selector.getYesNoSelection(
            "Should SSL be enabled? (current \"%s\"): " %
            (selectedConfig['sslEnabled']))
        configuration['authenticationEnabled'] = selector.getYesNoSelection(
            "Should authentication be enabled? (current %s): " %
            (selectedConfig['authenticationEnabled']))
    params['configuration'] = configuration
    response = nymea.send_command(
        "Configuration.SetWebSocketServerConfiguration", params)
    nymea.print_json_format(response['params'])