22import yaml
33import requests
44
5+
56class Prusa :
67 """
78 This is not a game, but a demo that shows the status of a Prusa printer
@@ -35,11 +36,11 @@ def __init__(self, input_queue, output_queue, screen):
3536 self .screen = screen
3637
3738 # init demo/game specific variables here
38- config_path = os .path .join (os .path .dirname (__file__ ), ' config.yaml' )
39- with open (config_path , 'r' ) as f :
39+ config_path = os .path .join (os .path .dirname (__file__ ), " config.yaml" )
40+ with open (config_path , "r" ) as f :
4041 config = yaml .safe_load (f )
41- self .prusalink_ip = config .get (' prusalink_ip' )
42- self .api_key = config .get (' api_key' )
42+ self .prusalink_ip = config .get (" prusalink_ip" )
43+ self .api_key = config .get (" api_key" )
4344 self .URL = f"http://{ self .prusalink_ip } /api/v1/job"
4445 self .HEADERS = {
4546 "X-Api-Key" : self .api_key ,
@@ -58,7 +59,6 @@ def __init__(self, input_queue, output_queue, screen):
5859 self .display_time_left = "0"
5960 self .display_progress = 0
6061
61-
6262 def get_stats (self ):
6363 """
6464 Returns static information.
@@ -73,8 +73,8 @@ def get_stats(self):
7373 return self ._get_default_stats ()
7474
7575 # Check content type
76- content_type = self .response .headers .get (' content-type' , '' )
77- if ' application/json' not in content_type :
76+ content_type = self .response .headers .get (" content-type" , "" )
77+ if " application/json" not in content_type :
7878 print (f"Unexpected content type: { content_type } " )
7979 print (f"Response body: { self .response .text [:200 ]} " ) # First 200 chars
8080 return self ._get_default_stats ()
@@ -86,7 +86,9 @@ def get_stats(self):
8686 self .progress = self .data .get ("progress" , 0 )
8787 self .time_elapsed = self .data .get ("time_printing" , "N/A" )
8888 self .time_left = self .data .get ("time_remaining" , "N/A" )
89- self .minutes_left = self .time_left // 60 if isinstance (self .time_left , int ) else "N/A"
89+ self .minutes_left = (
90+ self .time_left // 60 if isinstance (self .time_left , int ) else "N/A"
91+ )
9092
9193 except requests .RequestException as e :
9294 # print(f"Request failed: {e}")
@@ -123,34 +125,36 @@ def run(self):
123125 # Create generator here
124126 while True :
125127 self .stats = self .get_stats ()
126-
128+
127129 # print("=== Printer Status ===")
128130 # print(f"time left: {self.stats['time_left']}")
129131 # print(f"Stats: {self.stats}")
130132 # draw the filename
131- self .display_status = self .stats [' state' ]
133+ self .display_status = self .stats [" state" ]
132134 # print(f"Status: {self.display_status}")
133- if self .stats ['state' ] == "IDLE" and int (self .display_time_elapsed [0 :8 ].strip ()) > 0 :
135+ if (
136+ self .stats ["state" ] == "IDLE"
137+ and int (self .display_time_elapsed [0 :8 ].strip ()) > 0
138+ ):
134139 self .display_progress = 0
135140 self .display_time_elapsed = "0"
136141 self .display_time_left = "0"
137142 self .display_filename = "N/A"
138143 self .screen .clear ()
139144 print ("hit" )
140-
141145
142146 self .screen .draw_text (
143147 self .screen .x_width // 2 - 8 ,
144148 self .screen .y_height // 2 - 6 ,
145149 self .display_status ,
146150 push = True ,
147151 )
148-
149- if self .stats [' state' ] == "IDLE" :
152+
153+ if self .stats [" state" ] == "IDLE" :
150154 yield
151155 continue
152156
153- self .display_filename = self .stats [' filename' ][:16 ].upper ()
157+ self .display_filename = self .stats [" filename" ][:16 ].upper ()
154158 # print(f"Filename: {self.display_filename}")
155159 self .screen .draw_text (
156160 self .screen .x_width // 2 - 8 ,
@@ -159,9 +163,10 @@ def run(self):
159163 push = True ,
160164 )
161165
162-
163166 # print(f"Time left: {self.stats['minutes_left']} minutes")
164- self .display_time_elapsed = f"{ str (self .stats ['time_elapsed' ]):>5} ELAPSED"
167+ self .display_time_elapsed = (
168+ f"{ str (self .stats ['time_elapsed' ]):>5} ELAPSED"
169+ )
165170 self .screen .draw_text (
166171 self .screen .x_width // 2 - 8 ,
167172 self .screen .y_height // 2 - 2 ,
@@ -179,7 +184,7 @@ def run(self):
179184 )
180185
181186 # Map progress (0-100) to a value between 0 and 16
182- percentage_complete = int ((self .stats [' progress' ] / 100 ) * 16 )
187+ percentage_complete = int ((self .stats [" progress" ] / 100 ) * 16 )
183188 percentage_complete = max (0 , min (percentage_complete , 16 ))
184189 # print(f"Progress: {self.stats['progress']}%, (mapped to {percentage_complete})")
185190 self .display_progress = f"{ int (self .stats ['progress' ]):>5} PROGRESS"
0 commit comments