()
| 30 | @api.route("/connection", methods=["POST"]) |
| 31 | @restricted_access |
| 32 | def connectionCommand(): |
| 33 | valid_commands = { |
| 34 | "connect": ["autoconnect"], |
| 35 | "disconnect": [], |
| 36 | "reconnect": [] |
| 37 | } |
| 38 | |
| 39 | command, data, response = util.getJsonCommandFromRequest(request, valid_commands) |
| 40 | if response is not None: |
| 41 | return response |
| 42 | |
| 43 | pm = printerManager() |
| 44 | |
| 45 | if command in ["connect", "reconnect"]: |
| 46 | s = settings() |
| 47 | |
| 48 | driver = None |
| 49 | port = None |
| 50 | baudrate = None |
| 51 | |
| 52 | options = pm.getConnectionOptions() |
| 53 | |
| 54 | if "port" in data: |
| 55 | port = data["port"] |
| 56 | if port not in options["ports"]: |
| 57 | return make_response("Invalid port: %s" % port, 400) |
| 58 | |
| 59 | if "baudrate" in data and data['baudrate']: |
| 60 | baudrate = int(data["baudrate"]) |
| 61 | if baudrate: |
| 62 | baudrates = options["baudrates"] |
| 63 | if baudrates and baudrate not in baudrates: |
| 64 | return make_response("Invalid baudrate: %d" % baudrate, 400) |
| 65 | |
| 66 | else: |
| 67 | return make_response("Baudrate is null", 400) |
| 68 | |
| 69 | if "save" in data and data["save"]: |
| 70 | s.set(["serial", "port"], port) |
| 71 | s.setInt(["serial", "baudrate"], baudrate) |
| 72 | |
| 73 | if "autoconnect" in data: |
| 74 | s.setBoolean(["serial", "autoconnect"], data["autoconnect"]) |
| 75 | |
| 76 | s.save() |
| 77 | |
| 78 | if command == "connect": |
| 79 | pm.connect(port, baudrate) |
| 80 | elif command == "reconnect": |
| 81 | pm.reConnect(port, baudrate) |
| 82 | |
| 83 | elif command == "disconnect": |
| 84 | pm.disconnect() |
| 85 | |
| 86 | return NO_CONTENT |
| 87 | |
| 88 |
nothing calls this directly
no test coverage detected