Skip to content

Commit

Permalink
Odyssey api changes (#14)
Browse files Browse the repository at this point in the history
* odyssey: update odyssey module to use new API responses and params
  • Loading branch information
ada-phillips authored May 22, 2024
1 parent d306024 commit d4a8a73
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions klippy/extras/odyssey.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, config):

self.printing = False

self.status = self.load_status()
self.status = {}


self.gcode = self.printer.lookup_object('gcode')
Expand Down Expand Up @@ -96,66 +96,66 @@ def get_status(self, eventtime):
}

def location_category(self):
return self.status_details().get('print_data',{}).get('file_data',{}).get("location_category")
return self.print_data().get('file_data',{}).get("location_category")

def file_name(self):
return self.status_details().get('print_data',{}).get('file_data',{}).get("name")
return self.print_data().get('file_data',{}).get("name")

def file_path(self):
return f"{self.location_category()}/{self.file_name()}"
return self.print_data().get('file_data',{}).get("path")

def layer(self):
return self.status_details().get('layer', 0)
return self.status.get('layer')

def layer_count(self):
return self.status_details().get('print_data',{}).get('layer_count', 1)
return self.print_data().get('layer_count', 1)

def progress(self):
return self.layer()/self.layer_count()
return (self.layer() or 0)/self.layer_count()

def file_position(self):
return self.status_details().get('layer', 0)
return self.layer()

def is_active(self):
return self.print_status() == "Printing" and not self.is_paused()

def is_paused(self):
return self.status_details().get('paused', False)
return self.status.get('paused', False)

def print_status(self):
for print_status in self.status:
return print_status
self.status.get('status', 'Shutdown')

def status_details(self):
return self.status.get(self.print_status(), {})
def print_data(self):
return self.status.get('print_data') or {}

cmd_SDCARD_PRINT_FILE_help = "Mock SD card functionality for Moonraker's sake"
def cmd_SDCARD_PRINT_FILE(self, gcmd):
location = gcmd.get("LOCATION", default="Local")
filename = gcmd.get("FILENAME")
if filename[0] == '/':
filename = filename[1:]
filename = filename.rsplit('.', 1)[0]
self._START(gcmd, location, filename)
filepath = gcmd.get("FILENAME").rsplit('.', 1)[0]
self._START(gcmd, location, filepath)

cmd_START_help = "Starts a new print with Odyssey"
def cmd_START(self, gcmd):
location = gcmd.get("LOCATION", default="Local")
filename = gcmd.get("FILENAME")
self._START(gcmd, location, filename)
filepath = gcmd.get("PATH").rsplit('.', 1)[0]
self._START(gcmd, location, filepath)

def _START(self, gcmd, location, filename):
def _START(self, gcmd, location, filepath):
if self.printing:
raise gcmd.error("Odyssey Busy")
try:
response = requests.post(f"{self.url}/print/start/{location}/{filename}")
params = {
"file_path": filepath,
"location": location
}
response = requests.post(f"{self.url}/print/start", params=params)

if response.status_code == requests.codes.not_found:
raise gcmd.error("Odyssey could not find the requested file")
elif response.status_code != requests.codes.ok:
raise gcmd.error(f"Odyssey Error Encountered: {response.status_code}: {response.reason}")

self.print_stats.set_current_file(f"{location}/{filename}")
self.print_stats.set_current_file(filepath)
self.print_stats.note_start()
self.reactor.update_timer(self.work_timer, self.reactor.NOW+1)
except Exception as e:
Expand Down

0 comments on commit d4a8a73

Please sign in to comment.