コード例 #1
0
 def modify_current_job(self, action):
     if action not in ("cancel", "start", "toggle", "pause", "resume"):
         raise PrinterClientException("Action %s is not allowed" % (action,))
     body = {"command": action}
     if action in ["toggle", "pause", "resume"]:
         body = {"command": "pause", "action": action}
     request = self._http_post("/api/job", json=body)
     # TODO improve return value
     return bool(request is not None and request.status_code == 204)
コード例 #2
0
 def upload_and_start_job(self, gcode_disk_path, path=None):
     status = self.uncached_status()
     if self.client_info.connected and status["state"] != "Operational":
         raise PrinterClientException(
             "Printer is printing, cannot start another print"
         )
     request = self._http_post(
         "/api/files/local",
         files={"file": open(gcode_disk_path, "rb")},
         data={"path": "karmen" if not path else "karmen/%s" % path, "print": True},
     )
     # TODO improve return value
     return bool(request is not None and request.status_code == 201)
コード例 #3
0
 def test_create_already_printing(self, mock_print_inst):
     mock_print_inst.return_value.upload_and_start_job.side_effect = PrinterClientException(
         "Printer is printing")
     with app.test_client() as c:
         c.set_cookie("localhost", "access_token_cookie", TOKEN_USER)
         response = c.post(
             "/organizations/%s/printjobs" % UUID_ORG,
             headers={"x-csrf-token": TOKEN_USER_CSRF},
             json={
                 "printer": "20e91c14-c3e4-4fe9-a066-e69d53324a20",
                 "gcode": self.gcode_uuid,
             },
         )
         self.assertEqual(response.status_code, 409)
コード例 #4
0
 def are_lights_on(self):
     if "awesome_karmen_led" not in self.client_info.plugins:
         raise PrinterClientException(
             "awesome_karmen_led is not loaded in octoprint")
     request = self._http_get("/api/plugin/awesome_karmen_led", force=True)
     if not request:
         return False
     try:
         data = request.json()
         color = data.get("color", [])
         is_on = False
         for c in color:
             if c > 0:
                 is_on = True
         return is_on
     except json.decoder.JSONDecodeError:
         return False
コード例 #5
0
    def set_lights(self, color=None, heartbeat=None):
        if "awesome_karmen_led" not in self.client_info.plugins:
            raise PrinterClientException(
                "awesome_karmen_led is not loaded in octoprint")
        body = {"command": "set_led"}
        if color is not None:
            body["color"] = color
        else:
            body["color"] = "black"

        if heartbeat is not None:
            body["heartbeat"] = heartbeat
        request = self._http_post("/api/plugin/awesome_karmen_led", json=body)
        if not request:
            return False
        try:
            data = request.json()
            return data.get("status", "NOK") == "OK"
        except json.decoder.JSONDecodeError:
            return False