def color_node(self, root):
     node = Node("color", root)
     node.set_attribute("@callback", "rgb_color")
     node.set_display_name("Color")
     node.set_type("dynamic")
     node.set_config("$editor", "color")
     node.set_config("$writable", "write")
     node.set_value_callback = self.set_color
     return node
    def text_node(self, root):
        node = Node("text", root)
        node.set_attribute("@callback", "rgb_text")
        node.set_display_name("Text")
        node.set_type("string")

        node.set_config("$writable", "write")
        node.set_value_callback = self.set_text
        return node
    def add_module(self, parameters):
        if "Name" not in parameters.params:
            return [["Invalid name."]]
        node = Node(str(parameters.params["Name"]), self.super_root)
        node.set_attribute("@callback", "module")
        module_type = parameters.params["Type"]
        address = parameters.params["Address"]
        address_type = self.addresses[address][0]
        node.set_attribute("@module", module_type)
        node.set_attribute("@address", address)
        node.set_attribute("@type", address_type)
        node.set_value_callback = self.set_value
        node.set_config("$writable", "write")
        if module_type == "LED":
            if address_type == "pwm":
                grovepi.pinMode(self.addresses[address][1], "OUTPUT")
                node.set_type("number")
                node.set_attribute("@mode", "output")
                node.set_attribute("@unit", "%")
            elif address_type == "digital":
                grovepi.pinMode(self.addresses[address][1], "OUTPUT")
                node.set_type("bool")
                node.set_attribute("@mode", "output")
            else:
                return [["Requires pwm or digital"]]
        elif module_type == "RGB LCD":
            node.add_child(self.color_node(node))
            node.add_child(self.text_node(node))
        elif module_type == "Light Sensor":
            if address_type == "analog":
                node.set_type("number")
                node.set_attribute("@unit", "%")
                node.set_attribute("@mode", "input")
            else:
                return [["Requires analog"]]
        elif module_type == "Rotary Angle Sensor":
            if address_type == "analog":
                grovepi.pinMode(self.addresses[address][1], "INPUT")
                node.set_type("number")
                node.set_attribute("@unit", "%")
                node.set_attribute("@mode", "input")
            else:
                return [["Requires analog"]]
        elif module_type == "Ultrasonic Ranger":
            if address_type == "digital" or address_type == "pwm":
                grovepi.pinMode(self.addresses[address][1], "INPUT")
                node.set_type("number")
                node.set_attribute("@unit", "cm")
                node.set_attribute("@mode", "input")
            else:
                return [["Requires digital or pwm"]]
        elif module_type == "Buzzer":
            if address_type == "digital" or address_type == "pwm":
                grovepi.pinMode(self.addresses[address][1], "OUTPUT")
                node.set_type("number")
                node.set_attribute("@mode", "output")
            else:
                return [["Requires digital or pwm"]]
        elif module_type == "Sound Sensor":
            if address_type == "analog":
                grovepi.pinMode(self.addresses[address][1], "INPUT")
                node.set_type("number")
                node.set_attribute("@unit", "%")
                node.set_attribute("@mode", "input")
            else:
                return [["Requires analog"]]
        elif module_type == "Button":
            if address_type == "digital" or address_type == "pwm":
                grovepi.pinMode(self.addresses[address][1], "INPUT")
                node.set_type("bool")
                node.set_attribute("@mode", "input")
            else:
                return [["Requires digital or pwm"]]
        elif module_type == "Relay":
            if address_type == "digital" or address_type == "pwm":
                grovepi.pinMode(self.addresses[address][1], "OUTPUT")
                node.set_type("bool")
                node.set_attribute("@mode", "output")
            else:
                return [["Requires digital or pwm"]]
        elif module_type == "Temp and Humid":
            if address_type == "digital" or address_type == "pwm":
                grovepi.pinMode(self.addresses[address][1], "INPUT")
                node.add_child(self.temp_node(node))
                node.add_child(self.humid_node(node))
                node.set_attribute("@mode", "input")
            else:
                return [["Requires digital or pwm"]]

        node.add_child(self.remove_module_node(node))

        self.super_root.add_child(node)

        return [
            [
                "Success!"
            ]
        ]