spoolman: minor fixes

Set the minimum value for the sync_rate to 1 second, rather
than above 1 second.  When transitioning from a null spool
to a named spool clear tracked extrusion.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2023-06-26 16:38:19 -04:00
parent 09c29eab23
commit 5d54a10177
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
1 changed files with 4 additions and 1 deletions

View File

@ -31,7 +31,7 @@ class SpoolManager:
def __init__(self, config: ConfigHelper): def __init__(self, config: ConfigHelper):
self.server = config.get_server() self.server = config.get_server()
self.sync_rate_seconds = config.getint("sync_rate", default=5, above=1) self.sync_rate_seconds = config.getint("sync_rate", default=5, minval=1)
self.last_sync_time = datetime.datetime.now() self.last_sync_time = datetime.datetime.now()
self.extruded_lock = asyncio.Lock() self.extruded_lock = asyncio.Lock()
self.spoolman_url = f"{config.get('server').rstrip('/')}/api" self.spoolman_url = f"{config.get('server').rstrip('/')}/api"
@ -112,6 +112,9 @@ class SpoolManager:
# Store the current spool usage before switching # Store the current spool usage before switching
if self.spool_id is not None: if self.spool_id is not None:
await self.track_filament_usage() await self.track_filament_usage()
elif spool_id is not None:
async with self.extruded_lock:
self.extruded = 0
self.spool_id = spool_id self.spool_id = spool_id
self.database.insert_item(DB_NAMESPACE, ACTIVE_SPOOL_KEY, spool_id) self.database.insert_item(DB_NAMESPACE, ACTIVE_SPOOL_KEY, spool_id)
self.server.send_event( self.server.send_event(