From 29ba010ef3d423f1ebb61f633f2371e6a7596517 Mon Sep 17 00:00:00 2001
From: Oscar Gustafsson <oscar.gustafsson@gmail.com>
Date: Thu, 23 Feb 2023 15:05:41 +0100
Subject: [PATCH] Only save non-zero laps in code generation

---
 b_asic/save_load_structure.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/b_asic/save_load_structure.py b/b_asic/save_load_structure.py
index 2e41999f..57a2792e 100644
--- a/b_asic/save_load_structure.py
+++ b/b_asic/save_load_structure.py
@@ -167,11 +167,16 @@ def schedule_to_python(schedule: Schedule) -> str:
     schedule : Schedule
         The schedule to serialize.
     """
-    sfg_name = schedule.sfg.name.replace(" ", "_").replace("-", "_")
+    sfg_name = (
+        schedule.sfg.name.replace(" ", "_").replace("-", "_")
+        if schedule.sfg.name
+        else "sfg"
+    )
     result = "\n# Schedule:\n"
+    nonzerolaps = {gid: val for gid, val in dict(schedule.laps).items() if val}
     result += (
         f"{sfg_name}_schedule = Schedule({sfg_name}, {schedule.schedule_time},"
         f" {schedule.cyclic}, 'provided', {schedule.start_times},"
-        f" {dict(schedule.laps)})\n"
+        f" {nonzerolaps})\n"
     )
     return sfg_to_python(schedule.sfg, schedule=True) + result
-- 
GitLab