Esempio n. 1
0
 def pause(printer: Printer):
     """
     Issues pause print command to OctoPrint
     Returns response with 204/No Content
     """
     client = OctoClient(url=printer.url, apikey=printer.apikey)
     return client.pause()
Esempio n. 2
0
 def cancel(printer: Printer):
     """
     Issues cancel print command to OctoPrint
     Returns response with 204/No Content
     """
     client = OctoClient(url=printer.url, apikey=printer.apikey)
     return client.cancel()
Esempio n. 3
0
 def send_file(printer: Printer, filename, contents, print: bool):
     """
     Uploads file to printer and issues print command if argument print is true
     Returns information about file from OctoPrint
     """
     client = OctoClient(url=printer.url, apikey=printer.apikey)
     return client.upload((filename, contents), print=print)
Esempio n. 4
0
 def set_bed_temperature(printer: Printer, temperature):
     """
     Issues bed target temperature command to OctoPrint
     Returns response with 204/No Content
     """
     client = OctoClient(url=printer.url, apikey=printer.apikey)
     return client.bed_target(temperature)
Esempio n. 5
0
 def get_printer_state(printer: Printer):
     """
     Returns information about current state of printer including job info if is OctoPrint printing or paused
     """
     client = OctoClient(url=printer.url, apikey=printer.apikey)
     status = client.printer()
     if status["state"]["text"] == "Printing" or status["state"]["text"] == "Paused":
         job_info = client.job_info()
         status["job"] = job_info["job"]
         status["job"]["progress"] = job_info["progress"]
     return status
Esempio n. 6
0
 def print(printer: Printer, origin, filename):
     """
     Issues print command to OctoPrint on given file
     Returns true if success else false
     """
     try:
         client = OctoClient(url=printer.url, apikey=printer.apikey)
         client.select(location=origin + "/" + filename, print=True)
         return True
     except (RuntimeError, requests.ConnectionError):
         return False
Esempio n. 7
0
 def delete_file(printer: Printer, origin, filename):
     """
     Deletes file on printer
     Returns true if success else false
     """
     try:
         client = OctoClient(url=printer.url, apikey=printer.apikey)
         client.delete(origin + "/" + filename)
         return True
     except (RuntimeError, requests.ConnectionError):
         return False
Esempio n. 8
0
def pause_print():
    try:
        client = OctoClient(url=URL, apikey=API_KEY)
        flags = client.printer()['state']['flags']
        if flags['printing']:
            client.pause()
            print("Print paused.")
            print("Layer: " + str(LAYER))
        elif flags['paused'] or flags['pausing']:
            print("Print already paused.")
        else:
            print("Print cancelled or error occurred.")
    except Exception as e:
        print(e)
Esempio n. 9
0
 def auth(apikey, url):
     """
     Tries to connect to printer and return None on success
     """
     try:
         OctoClient(url=url, apikey=apikey)
     except (RuntimeError, requests.RequestException, ValueError):
         return False
     return None
Esempio n. 10
0
def client(betamax_session):
    return OctoClient(url=URL, apikey=APIKEY, session=betamax_session)
Esempio n. 11
0
 def get_file(printer: Printer, origin, filename):
     """
     Returns data about specific file on printer
     """
     client = OctoClient(url=printer.url, apikey=printer.apikey)
     return client.files(origin + "/" + filename)
Esempio n. 12
0
 def get_connection(printer: Printer):
     """
     Returns connection info about printer
     """
     client = OctoClient(url=printer.url, apikey=printer.apikey)
     return client.connection_info()
Esempio n. 13
0
 def save_settings(printer: Printer, settings):
     """
     Overwrites given OctoPrint settings
     """
     client = OctoClient(url=printer.url, apikey=printer.apikey)
     return client.settings(settings)
Esempio n. 14
0
 def get_settings(printer: Printer):
     """
     Returns OctoPrints settings
     """
     client = OctoClient(url=printer.url, apikey=printer.apikey)
     return client.settings()
Esempio n. 15
0
 def test_init_works_with_good_auth(self, betamax_session):
     # Should not raise anything
     OctoClient(url=URL, apikey=APIKEY, session=betamax_session)
Esempio n. 16
0
 def test_init_raises_with_bad_auth(self, betamax_session):
     with pytest.raises(RuntimeError):
         OctoClient(url=URL, apikey='nope', session=betamax_session)
Esempio n. 17
0
 def get_files(printer: Printer):
     """
     Returns data about files currently present on printer
     """
     client = OctoClient(url=printer.url, apikey=printer.apikey)
     return client.files()