Grotti 2.10.0: Orca-Senden, Slice-Ordner, ED-Strom, Hygiene.

Slice-Watch mit Ordnern/Filtern, Orca-Nachbearbeitung, Cockpit-Verlauf
mit ED, Zeitzone im Browser. Tasten-Grenze und README-API angeglichen,
toter Code entfernt, Requirements gepinnt.
This commit is contained in:
Dominic Gundel committed 2026-10-18 00:41:15 +02:00
1 parent efd0801cd1
commit 9e22cebb81
48 files changed
+2259 -422

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
"""Slice-Ordner (watch_dir) in config."""
from __future__ import annotations
import tempfile
import unittest
from pathlib import Path
from unittest.mock import patch
from grotti import config
from grotti.errors import GrottiError
class WatchDirTest(unittest.TestCase):
def test_empty(self):
path, stored = config.parse_watch_dir("")
self.assertIsNone(path)
self.assertEqual(stored, "")
def test_relative_under_root(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
target = root / "slice"
target.mkdir()
with patch.object(config, "ROOT", root):
path, stored = config.parse_watch_dir("slice", create=False)
self.assertEqual(path, target.resolve())
self.assertEqual(stored, "slice")
def test_create(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
with patch.object(config, "ROOT", root):
path, stored = config.parse_watch_dir("slice", create=True)
self.assertTrue(path.is_dir())
self.assertEqual(stored, "slice")
def test_file_rejected(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
file_path = root / "not-a-dir"
file_path.write_text("x", encoding="utf-8")
with patch.object(config, "ROOT", root):
with self.assertRaises(GrottiError):
config.parse_watch_dir(str(file_path), create=False)
if __name__ == "__main__":
unittest.main()
+51
View File
@@ -0,0 +1,51 @@
"""ED-Stromschätzung."""
import unittest
from datetime import datetime, timezone
from grotti.cost import energy_estimate
def sample_at(offset_s, np=None, bp=None):
base = datetime(2026, 10, 17, 15, 0, tzinfo=timezone.utc).timestamp()
at = datetime.fromtimestamp(base + offset_s, tz=timezone.utc).isoformat()
return {"sampled_at": at, "nozzle_power": np, "bed_power": bp}
class EnergyEdTests(unittest.TestCase):
def test_flat_without_heater_watts(self):
est = energy_estimate(3600, {"watts": 100, "euro_per_kwh": 0.5}, [
sample_at(0, np=1.0, bp=1.0),
sample_at(1800, np=1.0, bp=1.0),
])
self.assertEqual(est["source"], "flat")
self.assertAlmostEqual(est["kwh"], 0.1)
self.assertAlmostEqual(est["cost"], 0.05)
def test_ed_caps_long_gaps(self):
# 60 min Lücke → nur 90 s werden gezählt
samples = [sample_at(0, np=0.5, bp=0.0), sample_at(3600, np=0.5, bp=0.0)]
est = energy_estimate(3600, {
"watts": 0,
"nozzle_watts": 100,
"bed_watts": 0,
"euro_per_kwh": 1,
}, samples)
self.assertEqual(est["source"], "ed")
self.assertAlmostEqual(est["print_kwh"], (100 * 0.5 / 1000) * (90 / 3600), places=6)
def test_ed_dense_samples_full_hour(self):
samples = [sample_at(i * 30, np=1.0, bp=0.0) for i in range(0, 121)]
est = energy_estimate(3600, {
"watts": 0,
"nozzle_watts": 200,
"bed_watts": 0,
"euro_per_kwh": 2,
}, samples)
self.assertEqual(est["source"], "ed")
self.assertAlmostEqual(est["print_kwh"], 0.2, places=3)
self.assertAlmostEqual(est["cost"], 0.4, places=3)
if __name__ == "__main__":
unittest.main()
+4 -1
View File
@@ -61,7 +61,10 @@ class EjectTests(unittest.TestCase):
self.assertFalse(eject.cool_parked({"position": [250, 220, 50]}, before_z=10, lift_mm=40))
def test_sweep_does_not_lower_before_back(self):
script = eject.sweep_probe_height_script(eject.normalize_sweep({}))
sweep = eject.normalize_sweep({})
back = eject.sweep_go_back_high_script(sweep)
lower = eject.sweep_lower_to_push_script(sweep)
script = back + "\n" + lower
# Y hinten (Default 250) vor dem Senken auf z_push
y_idx = script.find("Y250")
z_push_idx = script.find("Z2.00")
+103
View File
@@ -0,0 +1,103 @@
"""Tests für scripts/orca_senden.py ohne laufenden Server."""
from __future__ import annotations
import json
import sys
import tempfile
import unittest
from pathlib import Path
from unittest.mock import patch
ROOT = Path(__file__).resolve().parents[1]
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
from scripts import orca_senden as orca # noqa: E402
class OrcaSendenHelpersTest(unittest.TestCase):
def test_send_page_url(self):
self.assertEqual(
orca.send_page_url("http://127.0.0.1:8770/", 42),
"http://127.0.0.1:8770/dateien?file=42",
)
def test_find_gcode_arg_last_matching(self):
with tempfile.TemporaryDirectory() as tmp:
folder = Path(tmp)
gcode = folder / "teil.gcode"
gcode.write_text("; test\n", encoding="utf-8")
other = folder / "notes.txt"
other.write_text("x", encoding="utf-8")
found = orca.find_gcode_arg(["orca_senden.py", str(other), str(gcode)])
self.assertEqual(found, gcode.resolve())
def test_find_gcode_arg_pp_temp(self):
with tempfile.TemporaryDirectory() as tmp:
pp = Path(tmp) / "platte.gcode.pp"
pp.write_text("; temp\n", encoding="utf-8")
found = orca.find_gcode_arg(["orca_senden.py", str(pp)])
self.assertEqual(found, pp.resolve())
self.assertEqual(orca.upload_name_for(pp), "platte.gcode")
def test_under_watch_subfolder(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp) / "slice"
dest = root / "Gridfinity" / "teil.gcode"
dest.parent.mkdir(parents=True)
dest.write_text("; x\n", encoding="utf-8")
placed = orca.under_watch(root, dest)
self.assertEqual(placed, ("Gridfinity", "teil.gcode"))
def test_under_watch_outside(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp) / "slice"
root.mkdir()
other = Path(tmp) / "elsewhere" / "teil.gcode"
other.parent.mkdir()
other.write_text("; x\n", encoding="utf-8")
self.assertIsNone(orca.under_watch(root, other))
def test_find_gcode_arg_missing(self):
with self.assertRaises(ValueError):
orca.find_gcode_arg(["orca_senden.py"])
def test_find_gcode_arg_file_gone(self):
with self.assertRaises(FileNotFoundError):
orca.find_gcode_arg(["orca_senden.py", r"C:\gibt\es\nicht.gcode"])
def test_load_config_ok(self):
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp) / "orca-senden.json"
path.write_text(
json.dumps({"url": "http://127.0.0.1:8770/", "token": "grt_abc"}),
encoding="utf-8",
)
cfg = orca.load_config(path)
self.assertEqual(cfg["url"], "http://127.0.0.1:8770")
self.assertEqual(cfg["token"], "grt_abc")
def test_load_config_missing(self):
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp) / "fehlt.json"
with self.assertRaises(FileNotFoundError):
orca.load_config(path)
def test_load_config_empty_token(self):
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp) / "orca-senden.json"
path.write_text(json.dumps({"url": "http://x", "token": ""}), encoding="utf-8")
with self.assertRaises(ValueError):
orca.load_config(path)
def test_main_shows_error_without_config(self):
with patch.object(orca, "CONFIG_PATH", Path("/tmp/does-not-exist-orca.json")):
with patch.object(orca, "show_error") as shown:
code = orca.main(["orca_senden.py", "x.gcode"])
self.assertEqual(code, 1)
self.assertTrue(shown.called)
if __name__ == "__main__":
unittest.main()