def start(self): for x in range(0, 99): first = dslink.Node("First%i" % x, self.responder.get_super_root()) for y in range(0, 99): second = dslink.Node("Second%i" % y, first) first.add_child(second) self.responder.get_super_root().add_child(first)
def create_bridge(self, bridge_name, host): bridge_node = dslink.Node(bridge_name, self.responder.super_root) bridge_node.set_attribute("@type", "bridge") bridge_node.set_attribute("@host", host) reconnect = dslink.Node("reconnect", bridge_node) reconnect.set_display_name("Reconnect") reconnect.set_profile("reconnect") reconnect.set_invokable("config") edit_bridge = dslink.Node("editBridge", bridge_node) edit_bridge.set_display_name("Edit Bridge") edit_bridge.set_profile("edit_bridge") edit_bridge.set_parameters([{ "name": "Bridge Name", "type": "string", "default": bridge_name }, { "name": "Host", "type": "string", "default": host }]) edit_bridge.set_invokable("config") remove_bridge = dslink.Node("removeBridge", bridge_node) remove_bridge.set_display_name("Remove Bridge") remove_bridge.set_profile("remove_bridge") remove_bridge.set_invokable("config") status = dslink.Node("status", bridge_node) status.set_display_name("Status") status.set_type("string") status.set_value("Unknown") bridge_node.add_child(edit_bridge) bridge_node.add_child(remove_bridge) bridge_node.add_child(reconnect) bridge_node.add_child(status) self.responder.super_root.add_child(bridge_node) try: self.bridges[bridge_name] = Bridge(host) self.bridges[bridge_name].connect() self.bridges[bridge_name].get_light_objects("id") self.create_lights(bridge_node) status.set_value("Connected") except PhueRegistrationException: status.set_value("Not Registered") return [[False]] return [[True]]
def get_default_nodes(self, super_root): for i in range(16): servo = dslink.Node("servo_%i" % i, super_root) servo.set_config("$is", "servo") servo.set_type("number") servo.set_display_name("Servo %i" % i) servo.set_config("$writable", "write") servo.set_value(i) super_root.add_child(servo) return super_root
def get_default_nodes(self, root): metric = dslink.Node("updateRate", root) metric.set_display_name("Update Rate") metric.set_type("number") metric.set_value(1) root.add_child(metric) metric.set_profile("set_speed") metric.set_config("$writable", "write") metric = dslink.Node("add_bridge", root) metric.set_profile("add_bridge") metric.set_display_name("Add Bridge") metric.set_invokable(dslink.Permission.CONFIG) metric.set_parameters([{ "name": "Bridge Name", "type": "string" }, { "name": "Host", "type": "string" }]) metric.set_columns([{"name": "Success", "type": "bool"}]) root.add_child(metric) return root
def create_lights(self, bridge): if self.bridges[bridge.name] is None: print("Bridge is None") return for id in self.bridges[bridge.name].get_light_objects("id"): l = self.bridges[bridge.name].get_light_objects("id")[id] node = dslink.Node("light_" + str(id), bridge) node.set_transient(True) node.set_display_name(l.name) bridge.add_child(node) set_hex = dslink.Node("set_hex", node) set_hex.set_display_name("Set Color") set_hex.set_parameters([{ "name": "value", "type": "string", "editor": "color", "placeholder": "#ffffff" }]) set_hex.set_columns([{ "name": "Success", "type": "bool", "value": False }]) set_hex.set_profile("set_hex") set_hex.set_invokable("write") node.add_child(set_hex) metric = dslink.Node("hue", node) metric.set_type("number") node.add_child(metric) metric.set_profile("set") metric.set_config("$writable", "write") metric = dslink.Node("on", node) metric.set_type("bool") node.add_child(metric) metric.set_profile("set") metric.set_config("$writable", "write") metric = dslink.Node("brightness", node) metric.set_type("number") metric.set_profile("set") metric.set_config("$writable", "write") node.add_child(metric) metric = dslink.Node("saturation", node) metric.set_type("number") metric.set_profile("set") metric.set_config("$writable", "write") node.add_child(metric) metric = dslink.Node("transitiontime", node) metric.set_type("number") metric.set_profile("set") metric.set_config("$writable", "write") node.add_child(metric) metric = dslink.Node("colormode", node) metric.set_type(dslink.Value.build_enum(["hs", "xy", "ct"])) metric.set_profile("set") node.add_child(metric) metric = dslink.Node("alert", node) metric.set_type( dslink.Value.build_enum(["select", "lselect", "none"])) metric.set_profile("set") metric.set_config("$writable", "write") node.add_child(metric) metric = dslink.Node("effect", node) metric.set_type(dslink.Value.build_enum(["none", "colorloop"])) metric.set_profile("set") metric.set_config("$writable", "write") node.add_child(metric) return bridge