Ejemplo n.º 1
0
def print_ruleActionList(actionList):
    for i in range(len(actionList)):
        action = actionList[i]
        deviceName = devices.get_full_device_name(action['deviceId'])
        actionType = actions.get_actionType(actionList[i]['actionTypeId'])
        actionParams = actionList[i]['ruleActionParams']
        print "%5s. -> %40s -> action: \"%s\"" % (i, deviceName,
                                                  actionType['displayName'])
        for i in range(len(actionParams)):
            if 'eventTypeId' in actionParams[i].keys():
                eventTypeId = actionParams[i]['eventTypeId']
                eventType = events.get_eventType(eventTypeId)
                print "%50s: -> value from event:  \"%s\" %s -> param \"%s\"" % (
                    parameters.getParamName(actionParams[i]['paramTypeId'],
                                            actionType['paramTypes']),
                    eventType['displayName'], eventTypeId,
                    parameters.getParamName(
                        actionParams[i]['eventParamTypeId'],
                        eventType['paramTypes']))
            else:
                print "%50s: %s" % (parameters.getParamName(
                    actionParams[i]['paramTypeId'],
                    actionType['paramTypes']), actionParams[i]['value'])
Ejemplo n.º 2
0
def get_log_entry_line(entry, checkFilter=False):
    global stateTypeIdCache
    global actionTypeIdCache
    global eventTypeIdCache
    global deviceIdCache
    global ruleIdCache

    global logFilter

    if checkFilter:
        if not verify_filter(entry):
            return None

    if entry['loggingLevel'] == "LoggingLevelInfo":
        levelString = "(I)"
        error = "-"
    else:
        levelString = "(A)"
        error = entry['errorCode']
    if entry['source'] == "LoggingSourceSystem":
        deviceName = "nymea server"
        sourceType = "System"
        symbolString = "->"
        sourceName = "Active changed"
        if entry['active'] == True:
            value = "active"
        else:
            value = "inactive"
    if entry['source'] == "LoggingSourceStates":
        typeId = entry['typeId']
        sourceType = "State Changed"
        symbolString = "->"
        if typeId in stateTypeIdCache:
            sourceName = stateTypeIdCache[typeId]
        else:
            stateType = states.get_stateType(typeId)
            if stateType is not None:
                sourceName = stateType["displayName"]
                stateTypeIdCache[typeId] = sourceName
            else:
                sourceName = typeId
        value = entry['value']
        deviceName = get_device_name(entry)
    if entry['source'] == "LoggingSourceActions":
        typeId = entry['typeId']
        sourceType = "Action executed"
        symbolString = "()"
        if typeId in actionTypeIdCache:
            sourceName = actionTypeIdCache[typeId]
        else:
            actionType = actions.get_actionType(typeId)
            if actionType is not None:
                sourceName = actionType['displayName']
            else:
                sourceName = typeId
            actionTypeIdCache[typeId] = sourceName
        value = entry['value']
        deviceName = get_device_name(entry)
    if entry['source'] == "LoggingSourceEvents":
        typeId = entry['typeId']
        sourceType = "Event triggered"
        symbolString = "()"
        if typeId in eventTypeIdCache:
            sourceName = eventTypeIdCache[typeId]
        else:
            eventType = events.get_eventType(typeId)
            sourceName = eventType['displayName']
            eventTypeIdCache[typeId] = sourceName
        value = entry['value']
        deviceName = get_device_name(entry)
    if entry['source'] == "LoggingSourceRules":
        typeId = entry['typeId']
        if entry['eventType'] == "LoggingEventTypeTrigger":
            sourceType = "Rule triggered"
            sourceName = "triggered"
            symbolString = "()"
            value = ""
        elif entry['eventType'] == "LoggingEventTypeActionsExecuted":
            sourceType = "Rule executed"
            sourceName = "actions"
            symbolString = "()"
            value = ""
        elif entry['eventType'] == "LoggingEventTypeExitActionsExecuted":
            sourceType = "Rule executed"
            sourceName = "exit actions"
            symbolString = "()"
            value = ""
        elif entry['eventType'] == "LoggingEventTypeEnabledChange":
            sourceType = "Rule changed"
            sourceName = "enabled"
            symbolString = "->"
            if entry['active']:
                value = "true"
            else:
                value = "false"

        else:
            sourceType = "Rule changed"
            symbolString = "()"
            sourceName = "active"
            if entry['active']:
                value = "active"
            else:
                value = "inactive"

        if typeId in ruleIdCache:
            deviceName = ruleIdCache[typeId]
        else:
            rule = rules.get_rule_description(typeId)
            if rule is not None and 'name' in rule:
                deviceName = rule['name']
            else:
                deviceName = typeId
            ruleIdCache[typeId] = deviceName
    timestamp = datetime.datetime.fromtimestamp(entry['timestamp'] / 1000)
    line = "%s %s | %19s | %38s | %20s %3s %20s | %10s" % (
        levelString.encode('utf-8'), timestamp, sourceType.encode('utf-8'),
        deviceName.encode('utf-8'), sourceName.encode('utf-8'),
        symbolString.encode('utf-8'), value.encode('utf-8'),
        error.encode('utf-8'))
    return line
Ejemplo n.º 3
0
def read_ruleActionParams(paramTypes, eventDescriptors=[]):
    params = []
    for paramType in paramTypes:
        print nymea.print_json_format(paramType)
        if any("allowedValues" in item for item in paramType):
            selection = nymea.get_selection(
                "Please select one of following allowed values:",
                paramType['allowedValues'])
            if selection == None:
                return None
            paramValue = paramType['allowedValues'][selection]
            param = {}
            param['paramTypeId'] = paramType['id']
            param['value'] = paramValue
            params.append(param)
        else:
            # check if we want normal action params or if we want to use an eventtypeid
            if eventDescriptors:
                selectionTypes = ["yes", "no"]
                selectionText = "-> Should the ruleActionParam \"%s\" depend on an event?" % (
                    paramType['displayName'])
                selection = nymea.get_selection(selectionText, selectionTypes)
                if selection == None:
                    return None
                if selectionTypes[selection] == "yes":
                    eventTypeIds = []
                    for i in eventDescriptors:
                        eventTypeIds.append(i['eventTypeId'])
                    selection = nymea.get_selection(
                        "Please select an eventTypeId", eventTypeIds)
                    eventTypeId = eventTypeIds[selection]
                    eventType = events.get_eventType(eventTypeId)
                    eventParamNames = []
                    eventParamTypeIds = []
                    for i in eventType['paramTypes']:
                        eventParamNames.append(i['displayName'])
                        eventParamTypeIds.append(i['id'])
                    paramSelection = nymea.get_selection(
                        "Please select the name of the eventParam for the action",
                        eventParamNames)
                    param = {}
                    param['paramTypeId'] = paramType['id']
                    param['eventTypeId'] = eventTypeId
                    param['eventParamTypeId'] = eventParamTypeIds[
                        paramSelection]
                    params.append(param)
                else:
                    if paramType['type'] == "Bool":
                        boolTypes = ["true", "false"]
                        selectionString = "Please enter value for parameter %s (type: %s): " % (
                            paramType['displayName'], paramType['type'])
                        selection = nymea.get_selection(
                            selectionString, boolTypes)
                        if selection == None:
                            return None
                        paramValue = boolTypes[selection]
                    elif paramType['type'] == "Int":
                        paramValue = int(
                            raw_input(
                                "Please enter value for parameter \"%s\" (type: %s): "
                                %
                                (paramType['displayName'], paramType['type'])))
                    elif paramType['type'] == "Double":
                        paramValue = double(
                            raw_input(
                                "Please enter value for parameter \"%s\" (type: %s): "
                                %
                                (paramType['displayName'], paramType['type'])))
                    elif paramType['type'] == "Uint":
                        paramValue = uint(
                            raw_input(
                                "Please enter value for parameter \"%s\" (type: %s): "
                                %
                                (paramType['displayName'], paramType['type'])))
                    else:
                        paramValue = raw_input(
                            "Please enter value for parameter \"%s\" (type: %s): "
                            % (paramType['displayName'], paramType['type']))
                    param = {}
                    param['paramTypeId'] = paramType['id']
                    param['value'] = paramValue
                    params.append(param)
            else:
                # make bool selectable to make shore they are "true" or "false"
                if paramType['type'] == "Bool":
                    boolTypes = ["true", "false"]
                    selectionString = "Please enter value for parameter %s (type: %s): " % (
                        paramType['displayName'], paramType['type'])
                    selection = nymea.get_selection(selectionString, boolTypes)
                    if selection == None:
                        return None
                    paramValue = boolTypes[selection]
                elif paramType['type'] == "Int":
                    paramValue = int(
                        raw_input(
                            "Please enter value for parameter \"%s\" (type: %s): "
                            % (paramType['displayName'], paramType['type'])))
                elif paramType['type'] == "Double":
                    paramValue = float(
                        raw_input(
                            "Please enter value for parameter \"%s\" (type: %s): "
                            % (paramType['displayName'], paramType['type'])))
                elif paramType['type'] == "Uint":
                    paramValue = int(
                        raw_input(
                            "Please enter value for parameter \"%s\" (type: %s): "
                            % (paramType['displayName'], paramType['type'])))
                else:
                    paramValue = raw_input(
                        "Please enter value for parameter \"%s\" (type: %s): "
                        % (paramType['displayName'], paramType['type']))

                param = {}
                param['paramTypeId'] = paramType['id']
                param['value'] = paramValue
                params.append(param)
    return params