def restore(self, node):
     for child_name in node.children:
         child = node.children[child_name]
         if node.children:
             self.restore(child)
         if "@callback" in child.attributes:
             if child.attributes["@callback"] == "module":
                 child.set_value_callback = self.set_value
             elif child.attributes["@callback"] == "rgb_text":
                 child.set_value_callback = self.set_text
             elif child.attributes["@callback"] == "rgb_color":
                 child.set_value_callback = self.set_color
         if "@mode" in child.attributes and "@address":
             mode = child.attributes["@mode"]
             address = self.addresses[child.attributes["@address"]][1]
             if mode == "output":
                 grovepi.pinMode(address, "OUTPUT")
             elif mode == "input":
                 grovepi.pinMode(address, "INPUT")
    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!"
            ]
        ]