Beispiel #1
0
    def on_api_command(self, command, data):
        if command in ['turnPSUOn', 'turnPSUOff', 'togglePSU']:
            try:
                if not Permissions.PLUGIN_PSUCONTROL_CONTROL.can():
                    return make_response("Insufficient rights", 403)
            except:
                if not user_permission.can():
                    return make_response("Insufficient rights", 403)
        elif command in ['getPSUState']:
            try:
                if not Permissions.STATUS.can():
                    return make_response("Insufficient rights", 403)
            except:
                if not user_permission.can():
                    return make_response("Insufficient rights", 403)

        if command == 'turnPSUOn':
            self.turn_psu_on()
        elif command == 'turnPSUOff':
            self.turn_psu_off()
        elif command == 'togglePSU':
            if self.isPSUOn:
                self.turn_psu_off()
            else:
                self.turn_psu_on()
        elif command == 'getPSUState':
            return jsonify(isPSUOn=self.isPSUOn)
Beispiel #2
0
    def on_api_command(self, command, data):
        if not user_permission.can():
            return flask.make_response("Insufficient rights", 403)

        configuration = self._settings.get(["gpio_configurations"
                                            ])[int(data["id"])]
        pin = self.get_pin_number(int(configuration["pin"]))

        if command == "getGpioState":
            return flask.jsonify(
                "" if pin < 0 else self._get_pin_state(pin, configuration))
        elif command == "turnGpioOn":
            if pin > 0:
                self.pin_states[pin] = True
                GPIO.output(pin,
                            self.active_states[configuration["active_mode"]])
                self._logger.info("Turned on GPIO{}".format(
                    configuration["pin"]))
        elif command == "turnGpioOff":
            if pin > 0:
                self.pin_states[pin] = False
                GPIO.output(
                    pin, not self.active_states[configuration["active_mode"]])
                self._logger.info("Turned off GPIO{}".format(
                    configuration["pin"]))
    def on_api_command(self, command, data):
        if not user_permission.can():
            return flask.make_response("Insufficient rights", 403)

        if command == 'turnOn':
            response = self.turn_on("{ip}".format(**data))
            self._plugin_manager.send_plugin_message(self._identifier,
                                                     response)
        elif command == 'turnOff':
            response = self.turn_off("{ip}".format(**data))
            self._plugin_manager.send_plugin_message(self._identifier,
                                                     response)
        elif command == 'checkStatus':
            response = self.check_status("{ip}".format(**data))
        elif command == 'getEnergyData':
            db = sqlite3.connect(self.db_path)
            cursor = db.cursor()
            cursor.execute(
                '''SELECT timestamp, current, power, total, voltage FROM energy_data WHERE ip=? ORDER BY timestamp DESC LIMIT ?,?''',
                (
                    data["ip"],
                    data["record_offset"],
                    data["record_limit"],
                ))
            response = {'energy_data': cursor.fetchall()}
            db.close()
            self._logger.info(response)
            #SELECT * FROM energy_data WHERE ip = '192.168.0.102' LIMIT 0,30
        else:
            response = dict(ip=data.ip, currentState="unknown")
        return flask.jsonify(response)
Beispiel #4
0
    def on_api_command(self, command, data):
        if not user_permission.can():
            return flask.make_response("Insufficient rights", 403)

        if command == "register_printer":
            """
			if "manufacturer" not in data:
				data["manufacturer"] = "cars"
			if "model" not in data:
				data["model"] = "fdm-printer"
			"""
            self._on_regist_printer(data)

        if command == "forget_printer":
            # new_supported_printers = self.get_supported_printers()
            self.mqtt_disconnect(force=True)
            self._settings.set(["printer_serial_number"], "")
            self._settings.set(["printer_token"], "")
            self._settings.set_boolean(["registration_complete"], False)
            # self._settings.set(["supported_printers"],new_supported_printers)
            self._settings.save()
            # self._plugin_manager.send_plugin_message(self._identifier, dict(printer_removed=True))
            return flask.jsonify(
                {"printer_removed":
                 True})  #,"supported_printers":new_supported_printers})

        if command == "mmf_print_complete":
            self._mmf_print = False
            self._current_action_code = "000"
            self._settings.set_boolean(["mmf_print_complete"], False)
            self._settings.set_boolean(["mmf_print_cancelled"], False)
            self._settings.save()
            return flask.jsonify(bed_cleared=True)
Beispiel #5
0
    def on_api_command(self, command, data):
        if not user_permission.can():
            return make_response("Insufficient rights", 403)

        if command == "enable":
            self._shutdown_printer_enabled = True
        elif command == "disable":
            self._shutdown_printer_enabled = False
        elif command == "shutdown":
            self._shutdown_printer_API_CMD(
                data["mode"]
            )  #mode 1 = gcode, mode 2 = api, mode 3 = custom api
        elif command == "abort":
            if self._abort_timer is not None:
                self._abort_timer.cancel()
                self._abort_timer = None
                self._abort_timer_temp.cancel()
                self._abort_timer_temp = None
            self._timeout_value = None
            self._logger.info("Shutdown aborted.")

        if command == "enable" or command == "disable":
            self.lastCheckBoxValue = self._shutdown_printer_enabled
            if self.rememberCheckBox:
                self._settings.set_boolean(["lastCheckBoxValue"],
                                           self.lastCheckBoxValue)
                self._settings.save()
                eventManager().fire(Events.SETTINGS_UPDATED)

        self._plugin_manager.send_plugin_message(
            self._identifier,
            dict(shutdownprinterEnabled=self._shutdown_printer_enabled,
                 type="timeout",
                 timeout_value=self._timeout_value))
Beispiel #6
0
	def on_api_get(self, request):
		if not user_permission.can():
			return flask.abort(403, "Insufficient permissions")
		if self._prompt is None:
			return flask.jsonify()
		else:
			return flask.jsonify(text=self._prompt.text, choices=self._prompt.choices)
Beispiel #7
0
	def on_api_command(self, command, data):
                if not user_permission.can():
                        return make_response("Insufficient rights", 403)

                if command == "enable":
                        self._automatic_shutdown_enabled = True
                elif command == "disable":
                        self._automatic_shutdown_enabled = False
                elif command == "abort":
                        if self._wait_for_timelapse_timer is not None:
                                self._wait_for_timelapse_timer.cancel()
                                self._wait_for_timelapse_timer = None
                        if self._abort_timer is not None:
                                self._abort_timer.cancel()
                                self._abort_timer = None
                        self._timeout_value = None
                        self._logger.info("Shutdown aborted.")
                
                if command == "enable" or command == "disable":
                        self.lastCheckBoxValue = self._automatic_shutdown_enabled
                        if self.rememberCheckBox:
                                self._settings.set_boolean(["lastCheckBoxValue"], self.lastCheckBoxValue)
                                self._settings.save()
                                eventManager().fire(Events.SETTINGS_UPDATED)
                        
                self._plugin_manager.send_plugin_message(self._identifier, dict(automaticShutdownEnabled=self._automatic_shutdown_enabled, type="timeout", timeout_value=self._timeout_value))
    def on_api_command(self, command, data):
        if not user_permission.can():
            return flask.make_response("Insufficient rights", 403)

        configuration = self._settings.get(["gpio_configurations"
                                            ])[int(data["id"])]
        pin = self.get_pin_number(int(configuration["pin"]))

        if command == "getGpioState":
            if pin < 0:
                return flask.jsonify("")
            elif configuration["active_mode"] == "active_low":
                return flask.jsonify("off" if GPIO.input(pin) else "on")
            elif configuration["active_mode"] == "active_high":
                return flask.jsonify("on" if GPIO.input(pin) else "off")
        elif command == "turnGpioOn":
            if pin > 0:
                self._logger.info("Turned on GPIO{}".format(
                    configuration["pin"]))

                if configuration["active_mode"] == "active_low":
                    GPIO.output(pin, GPIO.LOW)
                elif configuration["active_mode"] == "active_high":
                    GPIO.output(pin, GPIO.HIGH)
        elif command == "turnGpioOff":
            if pin > 0:
                self._logger.info("Turned off GPIO{}".format(
                    configuration["pin"]))

                if configuration["active_mode"] == "active_low":
                    GPIO.output(pin, GPIO.HIGH)
                elif configuration["active_mode"] == "active_high":
                    GPIO.output(pin, GPIO.LOW)
	def on_api_command(self, command, data):
		self._tasmota_logger.debug(data)
		if not user_permission.can():
			from flask import make_response
			return make_response("Insufficient rights", 403)
        
		if command == 'turnOn':
			if "username" in data and data["username"] != "":
				self._tasmota_logger.debug("Using authentication for %s." % "{ip}".format(**data))
				self.turn_on("{ip}".format(**data),"{idx}".format(**data),username="******".format(**data),password="******".format(**data))
			else:
				self.turn_on("{ip}".format(**data),"{idx}".format(**data))
		elif command == 'turnOff':
			if "username" in data and data["username"] != "":
				self._tasmota_logger.debug("Using authentication for %s." % "{ip}".format(**data))
				self.turn_off("{ip}".format(**data),"{idx}".format(**data),username="******".format(**data),password="******".format(**data))
			else:				
				self.turn_off("{ip}".format(**data),"{idx}".format(**data))
		elif command == 'checkStatus':
			if "username" in data and data["username"] != "":
				self._tasmota_logger.debug("Using authentication for %s." % "{ip}".format(**data))
				self.check_status("{ip}".format(**data),"{idx}".format(**data),username="******".format(**data),password="******".format(**data))
			else:
				self.check_status("{ip}".format(**data),"{idx}".format(**data))
		elif command == 'connectPrinter':
			self._tasmota_logger.debug("Connecting printer.")
			self._printer.connect()
		elif command == 'disconnectPrinter':
			self._tasmota_logger.debug("Disconnecting printer.")
			self._printer.disconnect()
		elif command == 'sysCommand':
			self._tasmota_logger.debug("Running system command %s." % "{cmd}".format(**data))
			os.system("{cmd}".format(**data))
    def on_api_command(self, command, data):
        if not user_permission.can():
            return flask.make_response("Insufficient rights", 403)

        if command == 'updateToken':
            # Convert from ASCII to UTF-8 since somce chars will fail otherwise
            data["deviceName"] = data["deviceName"].encode("utf-8")
            printer_name = data[
                "printerName"] if 'printerName' in data else None
            language_code = data[
                "languageCode"] if 'languageCode' in data else None

            self.update_token("{oldToken}".format(**data),
                              "{newToken}".format(**data),
                              "{deviceName}".format(**data),
                              "{printerID}".format(**data), printer_name,
                              language_code)
        elif command == 'test':
            payload = dict(state_id="OPERATIONAL", state_string="Operational")
            code = self._job_notifications.send__print_job_notification(
                self._settings, self._printer, payload, data["server_url"],
                data["camera_snapshot_url"], True)
            return flask.jsonify(dict(code=code))
        elif command == 'snooze':
            if data["eventCode"] == 'mmu-event':
                self._mmu_assitance.snooze(data["minutes"])
            else:
                return flask.make_response("Snooze for unknown event", 400)
        else:
            return flask.make_response("Unknown command", 400)
    def on_api_command(self, command, data):
        if not user_permission.can():
            return make_response("Insufficient rights", 403)

        if command == 'turnPSUOn':
            self.turn_psu_on()
        elif command == 'turnPSUOff':
            self.turn_psu_off()
	def on_api_command(self, command, data):
		if not user_permission.can():
			return flask.make_response("Insufficient rights", 403)

		if command == 'turnOn':
			response = self.turn_on("{ip}".format(**data))
			self._plugin_manager.send_plugin_message(self._identifier, response)
		elif command == 'turnOff':
			response = self.turn_off("{ip}".format(**data))
			self._plugin_manager.send_plugin_message(self._identifier, response)
		elif command == 'checkStatus':
			response = self.check_status("{ip}".format(**data))
		elif command == 'getEnergyData':
			db = sqlite3.connect(self.db_path)
			cursor = db.cursor()
			cursor.execute('''SELECT timestamp, current, power, total, voltage FROM energy_data WHERE ip=? ORDER BY timestamp DESC LIMIT ?,?''', (data["ip"],data["record_offset"],data["record_limit"]))
			response = {'energy_data' : cursor.fetchall()}
			db.close()
			self._tplinksmartplug_logger.debug(response)
			#SELECT * FROM energy_data WHERE ip = '192.168.0.102' LIMIT 0,30
		elif command == 'enableAutomaticShutdown':
			self.powerOffWhenIdle = True
			self._reset_idle_timer()
		elif command == 'disableAutomaticShutdown':
			self.powerOffWhenIdle = False
			self._stop_idle_timer()
			if self._abort_timer is not None:
				self._abort_timer.cancel()
				self._abort_timer = None
			self._timeout_value = None
		elif command == 'abortAutomaticShutdown':
			if self._abort_timer is not None:
				self._abort_timer.cancel()
				self._abort_timer = None
			self._timeout_value = None
			for plug in self._settings.get(["arrSmartplugs"]):
				if plug["useCountdownRules"] and int(plug["countdownOffDelay"]) > 0:
					if "/" in plug["ip"]:
						plug_ip, plug_num = plug["ip"].split("/")
					else:
						plug_ip = plug["ip"]
						plug_num = -1
					self.sendCommand(json.loads('{"count_down":{"delete_all_rules":null}}'),plug_ip,plug_num)
					self._tplinksmartplug_logger.debug("Cleared countdown rules for %s" % plug["ip"])
			self._tplinksmartplug_logger.debug("Power off aborted.")
			self._tplinksmartplug_logger.debug("Restarting idle timer.")
			self._reset_idle_timer()
		else:
			response = dict(ip = data.ip, currentState = "unknown")
		if command == "enableAutomaticShutdown" or command == "disableAutomaticShutdown":
			self._tplinksmartplug_logger.debug("Automatic power off setting changed: %s" % self.powerOffWhenIdle)
			self._settings.set_boolean(["powerOffWhenIdle"], self.powerOffWhenIdle)
			self._settings.save()
			#eventManager().fire(Events.SETTINGS_UPDATED)
		if command == "enableAutomaticShutdown" or command == "disableAutomaticShutdown" or command == "abortAutomaticShutdown":
			self._plugin_manager.send_plugin_message(self._identifier, dict(powerOffWhenIdle=self.powerOffWhenIdle, type="timeout", timeout_value=self._timeout_value))
		else:
			return flask.jsonify(response)
Beispiel #13
0
    def on_api_command(self, comm, data):
        if not user_permission.can():
            return make_response("Insufficient rights", 403)

        if comm == 'executeCommand':
            return self.execute_command(data)

        if comm == 'sendMessage':
            return self.unpack_message(data)
Beispiel #14
0
    def on_api_command(self, command, data):
        if not user_permission.can():
            from flask import make_response
            return make_response("Insufficient rights", 403)

        if command == 'toggleRelay' or command == "turnOn" or command == "turnOff":
            for relay in self._settings.get(["arrRelays"]):
                if relay["topic"] == "{topic}".format(
                        **data) and relay["relayN"] == "{relayN}".format(
                            **data):
                    if command == "turnOff" or (command == "toggleRelay" and
                                                relay["currentstate"] == "ON"):
                        self._logger.info(
                            "turning off {topic} relay {relayN}".format(
                                **data))
                        self.turn_off(relay)
                    if command == "turnOn" or (command == "toggleRelay" and
                                               relay["currentstate"] == "OFF"):
                        self._logger.info(
                            "turning on {topic} relay {relayN}".format(**data))
                        self.turn_on(relay)
        if command == 'checkStatus':
            for relay in self._settings.get(["arrRelays"]):
                self._logger.info("checking status of %s relay %s" %
                                  (relay["topic"], relay["relayN"]))
                try:
                    self.mqtt_publish(
                        self.generate_mqtt_full_topic(relay, "cmnd"), "")
                except:
                    self._plugin_manager.send_plugin_message(
                        self._identifier, dict(noMQTT=True))

        if command == 'checkRelay':
            self._logger.info(
                "subscribing to {topic} relay {relayN}".format(**data))
            for relay in self._settings.get(["arrRelays"]):
                if relay["topic"] == "{topic}".format(
                        **data) and relay["relayN"] == "{relayN}".format(
                            **data):
                    self.mqtt_subscribe(
                        self.generate_mqtt_full_topic(relay, "stat"),
                        self._on_mqtt_subscription,
                        kwargs=dict(top="{topic}".format(**data),
                                    relayN="{relayN}".format(**data)))
                    self._logger.info(
                        "checking {topic} relay {relayN}".format(**data))
                    self.mqtt_publish(
                        self.generate_mqtt_full_topic(relay, "cmnd"), "")

        if command == 'removeRelay':
            for relay in self._settings.get(["arrRelays"]):
                if relay["topic"] == "{topic}".format(
                        **data) and relay["relayN"] == "{relayN}".format(
                            **data):
                    self.mqtt_unsubscribe(self._on_mqtt_subscription,
                                          topic=self.generate_mqtt_full_topic(
                                              relay, "stat"))
Beispiel #15
0
    def on_api_command(self, command, data):
        self._domoticz_logger.debug(data)
        if not user_permission.can():
            from flask import make_response

            return make_response("Insufficient rights", 403)

        if command == "turnOn":
            if "username" in data and data["username"] != "":
                self._domoticz_logger.debug(
                    "Using authentication for %s." % "{ip}".format(**data)
                )
                self.turn_on(
                    "{ip}".format(**data),
                    "{idx}".format(**data),
                    username="******".format(**data),
                    password="******".format(**data),
                )
            else:
                self.turn_on("{ip}".format(**data), "{idx}".format(**data))
        elif command == "turnOff":
            if "username" in data and data["username"] != "":
                self._domoticz_logger.debug(
                    "Using authentication for %s." % "{ip}".format(**data)
                )
                self.turn_off(
                    "{ip}".format(**data),
                    "{idx}".format(**data),
                    username="******".format(**data),
                    password="******".format(**data),
                )
            else:
                self.turn_off("{ip}".format(**data), "{idx}".format(**data))
        elif command == "checkStatus":
            if "username" in data and data["username"] != "":
                self._domoticz_logger.debug(
                    "Using authentication for %s." % "{ip}".format(**data)
                )
                self.check_status(
                    "{ip}".format(**data),
                    "{idx}".format(**data),
                    username="******".format(**data),
                    password="******".format(**data),
                )
            else:
                self.check_status("{ip}".format(**data), "{idx}".format(**data))
        elif command == "connectPrinter":
            self._domoticz_logger.debug("Connecting printer.")
            self._printer.connect()
        elif command == "disconnectPrinter":
            self._domoticz_logger.debug("Disconnecting printer.")
            self._printer.disconnect()
        elif command == "sysCommand":
            self._domoticz_logger.debug(
                "Running system command %s." % "{cmd}".format(**data)
            )
            os.system("{cmd}".format(**data))
Beispiel #16
0
    def on_api_command(self, command, data):
        self._mylogger("called - {}".format(command), forceinfo=True)

        if not user_permission.can():
            self._mylogger("Insufficient rights {}".format(command),
                           forceinfo=True)
            return make_response("Insufficient rights", 403)

        cmd = command.lower()
        if cmd == 'refreshfilamentstatus':
            self._mylogger("Filament status update call")
            self.reportfilamentstate()

        if cmd == 'turnatxpsuoff':
            self._mylogger("Turned Off Supply")
            self.turnoff()

        if cmd == 'turnatxpsuon':
            self._mylogger("Turned On Supply")
            self.turnon()

        if cmd == 'issmartboard':
            smartflag = 'true' if self._smartboard else 'false'
            self._mylogger("sending IsSmartBoard {} ".format(smartflag),
                           forceinfo=True)
            return make_response(smartflag)

        if not self._smartboard:
            return

        if cmd == "toggleextswitch":
            self._mylogger("Toggle External Switch")
            self.toggle_extswitch()

        if cmd == 'updateextswitch':
            self._mylogger("Update External Switch PWM value")
            data.pop('command', 0)
            self._settings.set(['ExternalSwitchValue'],
                               int(data['ExternalSwitchValue']))
            self._settings.save()
            self.initialize_extswitch()

        if cmd == 'updateled' and self._settings.getBoolean(['UseLEDS']):
            if data['LEDRed'] > -1 and data['LEDGreen'] > -1 and data[
                    'LEDBlue'] > -1:
                self._mylogger(
                    "Status Sent - {LEDRed} - {LEDGreen} - {LEDBlue}".format(
                        **data))
                data.pop('command', 0)
                self._settings.set(['LEDRed'], int(data['LEDRed']))
                self._settings.set(['LEDGreen'], int(data['LEDGreen']))
                self._settings.set(['LEDBlue'], int(data['LEDBlue']))
                self._settings.set(['LEDBrightness'],
                                   int(data['LEDBrightness']))
                self._settings.save()
                self.initialize_leds()
	def on_api_command(self, command, data):
		self._logger.debug("received an api_command: " + str(command) +" , "+ str(data["percentage"]))
		if not user_permission.can():
			from flask import make_response
			return make_response("Insufficient rights", 403)

		if command == 'dim':
			call("gpio -g pwm " + str(self.pwmPin) + " " + str(data["percentage"]), shell=True) #pin, duty cycle
			self.current_pwm_value= data["percentage"]
			self._logger.debug("changed current_duty_cycle: " + str(self.current_pwm_value))
Beispiel #18
0
    def on_api_command(self, command, data):
        if not user_permission.can():
            return make_response("Insufficient rights", 403)

        if command == 'turnoffPSU':
            self.turn_psu_off()
        elif command == 'turnPSUOff':
            self.turn_psu_off()
        elif command == 'getPSUState':
            return jsonify(isPSUOn=self.isPSUOn)
Beispiel #19
0
    def on_api_command(self, command, data):
        if not user_permission.can():
            return make_response("Insufficient rights", 403)

        if command == 'turnOn':
            self.turn_on()
        elif command == 'turnOff':
            self.turn_off()
        elif command == 'checkStatus':
            self.check_status()
	def on_api_command(self, command, data):
		if not user_permission.can():
			from flask import make_response
			return make_response("Insufficient rights", 403)
			
		if command == 'publishcommand':
			try:
				self.mqtt_publish("{topic}".format(**data), "{publishcommand}".format(**data))
				self._plugin_manager.send_plugin_message(self._identifier, dict(topic="{topic}".format(**data),publishcommand="{publishcommand}".format(**data)))
			except:
				self._plugin_manager.send_plugin_message(self._identifier, dict(noMQTT=True))
Beispiel #21
0
    def on_api_command(self, command, data):
        if not user_permission.can():
            from flask import make_response
            return make_response("Insufficient rights", 403)

        if command == 'turnOn':
            self.turn_on("{ip}".format(**data))
        elif command == 'turnOff':
            self.turn_off("{ip}".format(**data))
        elif command == 'checkStatus':
            self.check_status("{ip}".format(**data))
    def on_api_command(self, command, data):
        self._logger.debug("received an api_command: " + str(command) + " , " +
                           str(data["percentage"]))
        if not user_permission.can():
            from flask import make_response
            return make_response("Insufficient rights", 403)

        if command == 'dim':
            self.pwm_instance.ChangeDutyCycle(float(data["percentage"]))
            self.current_pwm_value = data["percentage"]
            self._logger.debug("changed current_duty_cycle: " +
                               str(self.current_pwm_value))
Beispiel #23
0
	def on_api_command(self, command, data):
		if command == "select":
			if not user_permission.can():
				return flask.abort(403, "Insufficient permissions")

			if self._active is False:
				return flask.abort(409, "No active prompt")

			choice = data["choice"]
			if not isinstance(choice, int) or not choice < 5 or not choice >= 0:
				return flask.abort(400, "{!r} is not a valid value for filament choice".format(choice+1))

			self._done_prompt("T" + str(choice))
Beispiel #24
0
	def on_api_command(self, command, data):
		if command == "select":
			if not user_permission.can():
				return flask.abort(403, "Insufficient permissions")

			if self._prompt is None:
				return flask.abort(409, "No active prompt")

			choice = data["choice"]
			if not isinstance(choice, int) or not self._prompt.validate_choice(choice):
				return flask.abort(400, "{!r} is not a valid value for choice".format(choice))

			self._answer_prompt(choice)
    def on_api_command(self, command, data):
        if not user_permission.can():
            from flask import make_response
            return make_response("Insufficient rights", 403)

        if command == 'turnOn':
            self.turn_on("{ip}".format(**data))
        elif command == 'turnOff':
            self.turn_off("{ip}".format(**data))
        elif command == 'checkStatus':
            self.check_status("{ip}".format(**data))
        elif command == 'eufyDownload':
            return self.eufy_download(data["username"], data["password"])
Beispiel #26
0
    def on_api_command(self, command, data):
        import flask
        from octoprint.server import user_permission
        if not user_permission.can():
            return flask.make_response("Insufficient rights", 403)

        if command == "crawl_files":
            self._logger.debug("Crawling Files")
            file_list = self._file_manager.list_files(recursive=True)
            local_files = file_list["local"]
            results = {'no_thumbnail': [], 'no_thumbnail_src': []}
            for key, file in local_files.items():
                results = self._process_gcode(local_files[key], results)
            return flask.jsonify(results)
    def on_api_command(self, command, data):
        if not user_permission.can():
            return make_response("Insufficient rights", 403)

        if command == 'turnfanOn':
            self.turn_fan_on()
        elif command == 'turnfanOff':
            self.turn_fan_off()
        elif command == 'togglefan':
            if self.isfanOn:
                self.turn_fan_off()
            else:
                self.turn_fan_on()
        elif command == 'getfanState':
            return jsonify(isfanOn=self.isfanOn)
Beispiel #28
0
    def on_api_command(self, command, data):
        if not user_permission.can():
            return make_response("Insufficient rights", 403)

        if command == 'turnPowerOn':
            if not self.isPowerOn:
                self.turn_power_on()
        elif command == 'turnPowerOff':
            if self.isPowerOn:
                self.turn_power_off()
        elif command == 'togglePower':
            self.toggle_power()
        elif command == 'turnLightOn':
            self.turn_light_on()
        elif command == 'getPowerState':
            return jsonify(isPowerOn=self.isPowerOn)
Beispiel #29
0
    def on_api_command(self, command, data):
        import flask
        import json
        from octoprint.server import user_permission
        if not user_permission.can():
            return flask.make_response("Insufficient rights", 403)

        if command == "crawl_files":
            self._logger.debug("Crawling Files")
            FileList = self._file_manager.list_files(recursive=True)
            self._logger.info(FileList)
            LocalFiles = FileList["local"]
            results = dict(no_thumbnail=[], no_thumbnail_src=[])
            for key, file in LocalFiles.items():
                results = self._process_gcode(LocalFiles[key], results)
            return flask.jsonify(results)
    def on_api_command(self, command, data):
        if not user_permission.can():
            from flask import make_response
            return make_response("Insufficient rights", 403)
        
        if command == 'startStream':
            self._logger.info("Start stream command received.")
            self._start_stream()

        if command == 'stopStream':
            self._logger.info("Stop stream command received.")
            self._stop_stream()

        if command == 'checkStream':
            self._logger.info("Checking stream status.")
            self._check_stream()
Beispiel #31
0
    def on_api_command(self, command, data):
        if not user_permission.can():
            return flask.make_response("Insufficient rights", 403)

        if command == 'turnOn':
            response = self.turn_on("{ip}".format(**data))
            self._plugin_manager.send_plugin_message(self._identifier,
                                                     response)
        elif command == 'turnOff':
            response = self.turn_off("{ip}".format(**data))
            self._plugin_manager.send_plugin_message(self._identifier,
                                                     response)
        elif command == 'checkStatus':
            response = self.check_status("{ip}".format(**data))
        else:
            response = dict(ip=data.ip, currentState="unknown")
        return flask.jsonify(response)
Beispiel #32
0
	def on_api_get(self, request):
		if not user_permission.can():
			return flask.make_response("Insufficient rights", 403)
		return flask.jsonify(self._warnings)