Sud: server always starts empty; sude/*.json is purely a client concern

Several sude/*.json schedules can exist on disk; only one runs at a
time, chosen by a client Load. Sud no longer takes a path at all - it
starts empty (EMPTY_SUD) and the server config no longer names a
specific schedule file, removing the implicit link to sud_0010.json
in particular. Reading/writing sude/*.json is now entirely the
client's job (e.g. the GUI's Load/Save file dialogs); the server's Sud
only ever holds whatever was last Load()ed, in memory, until replaced
or the server restarts.

Updates demo_sud.py/demo_sud_save_load.py to construct an empty Sud()
and load() a schedule explicitly, matching the new constructor.
This commit is contained in:
2026-06-21 10:24:45 +02:00
parent 3ed2961dce
commit 2c25b8be50
7 changed files with 84 additions and 74 deletions
+24 -18
View File
@@ -1,4 +1,3 @@
import json
from enum import Enum
from utils.value import AttributeChange
@@ -46,16 +45,26 @@ def _build_step(number, defaults, raw_step):
return step
EMPTY_SUD = {
'Name': '',
'Description': '',
'pot_mass': 0,
'pot_material': None,
'steps': [],
}
class Sud(AttributeChange):
def __init__(self, path):
def __init__(self):
"""Starts out with no schedule loaded - one of potentially several
sude/*.json files on disk is brought in later via load(), kept
purely in memory (see load()) until replaced or the server
restarts."""
AttributeChange.__init__(self)
self.path = path
with open(path) as f:
data = json.load(f)
self._data = data
self._data = EMPTY_SUD
(self.name, self.description, self.schedule,
self.pot_mass, self.pot_material) = self._parse_data(data)
self.pot_mass, self.pot_material) = self._parse_data(self._data)
self._paused_from = None
self._reset_run_state()
@@ -88,20 +97,17 @@ class Sud(AttributeChange):
self._paused_from = None
def save(self):
"""Returns the currently running sud.json document, for a client to
edit and hand back to load(). Purely in-memory - load() no longer
touches disk, so this is just whatever was last loaded (the file
given to __init__, or a later load()), not necessarily what's on
disk at self.path anymore."""
"""Returns the currently running sud.json document (EMPTY_SUD if
none has been loaded yet), for a client to edit and hand back to
load(). Purely in-memory - never read from or written to disk."""
return self._data
def load(self, data):
"""Replaces the running schedule with a new sud.json document (kept
in memory only - never written to disk, so the file originally
configured via self.path is never touched by this), resetting to
IDLE as if freshly loaded. A client wanting to persist a schedule
does so explicitly itself, e.g. by writing save()'s result wherever
it chooses. Refused while a brew is in progress, or if data is
"""Replaces the running schedule with a new sud.json document, kept
in memory only (never written to disk - a client wanting to persist
a schedule does so explicitly itself, e.g. by writing save()'s
result to one of the sude/*.json files), resetting to IDLE as if
freshly loaded. Refused while a brew is in progress, or if data is
malformed - in either case the current schedule is left untouched."""
if self.state not in (SudState.IDLE, SudState.DONE):
return False