Exemple #1
0
    def default_config():
        # create core config
        Module.create_config(Core.get_config_definition())

        # iterate over module types
        for i in ("input", "output", "platform", "sleep", "status"):
            # list module folder
            for j in Module.list_modules(i):

                # load module class
                klass = Module.load_class(i, j)

                # skip unloadable classes
                if klass == None:
                    continue

                # get config definition
                cd = klass.get_config_definition()

                # skip if module has no configuration
                if cd == None:
                    continue

                # create configuration file
                Module.create_config(cd)
Exemple #2
0
def test_modules():
    # load all module classes to check for import and syntax errors
    for i in ("platform", "input", "output", "sleep", "status"):
        log_info("Test loading " + i + " module classes.")
        for j in Module.list_modules(i):
            Module.load_class(i, j)

    # check if input device id's are unique
    log_info("Testing for unique input module ids.")
    ids = []
    for i in range(0, 256):
        ids.append("")

    for i in Module.list_modules("input"):
        klass = Module.load_class("input", i)
        if len(ids[klass.get_id()]) == 0:
            ids[klass.get_id()] = i
        else:
            raise Exception("Id " + str(klass.get_id()) + " should be unique but is used by input modules '" + ids[klass.get_id()] + "' and '" + i + "'.")
Exemple #3
0
    def __decode(array):
        # create an array of all the input modules
        modules = [None] * 256

        for i in Module.list_modules("input"):
            klass = Module.load_class("input", i)
            if modules[klass.get_id()] != None:
                Exception(
                    "Input module id " + str(klass.get_id()) +
                    " is used by multiple classes, run tests for more information."
                )
            modules[klass.get_id()] = klass

        # first check if we have a valid measurement array by adding together
        # the lengths and checking if it fits the size
        l = len(array)
        if l < 2:
            raise Exception("invalid measurement string - too small")

        s = 0
        while s < l:
            if modules[array[s]] == None:
                raise Exception(
                    "invalid measurement string - unknown input module id")

            if array[s + 1] == 0:
                raise Exception(
                    "invalid measurement string - length cannot be zero")
            s += array[s + 1]

        if l != s:
            raise Exception(
                "invalid measurement string - lenght does not add up")

        # decoded string
        s = ""

        # read counter
        c = 0

        while c < l:
            # input module id
            id = array[c]

            # measurement length
            ml = array[c + 1]

            # measurement array
            ma = bytearray(ml)
            for i in range(0, ml):
                ma[i] = array[c + 2 + i]

            # set read counter
            c = c + 2 + ml

            # add to decoded string
            if len(s) != 0:
                s += ",\n"
            s += modules[id].decode(ma)

        return "{\n" + s + "\n}"