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()
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()
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)
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)
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
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
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
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)
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
def client(betamax_session): return OctoClient(url=URL, apikey=APIKEY, session=betamax_session)
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)
def get_connection(printer: Printer): """ Returns connection info about printer """ client = OctoClient(url=printer.url, apikey=printer.apikey) return client.connection_info()
def save_settings(printer: Printer, settings): """ Overwrites given OctoPrint settings """ client = OctoClient(url=printer.url, apikey=printer.apikey) return client.settings(settings)
def get_settings(printer: Printer): """ Returns OctoPrints settings """ client = OctoClient(url=printer.url, apikey=printer.apikey) return client.settings()
def test_init_works_with_good_auth(self, betamax_session): # Should not raise anything OctoClient(url=URL, apikey=APIKEY, session=betamax_session)
def test_init_raises_with_bad_auth(self, betamax_session): with pytest.raises(RuntimeError): OctoClient(url=URL, apikey='nope', session=betamax_session)
def get_files(printer: Printer): """ Returns data about files currently present on printer """ client = OctoClient(url=printer.url, apikey=printer.apikey) return client.files()