mabuseif commited on
Commit
68d8f87
·
verified ·
1 Parent(s): acf1324

Update app/internal_loads.py

Browse files
Files changed (1) hide show
  1. app/internal_loads.py +95 -105
app/internal_loads.py CHANGED
@@ -49,13 +49,13 @@ def display_internal_loads_page():
49
  with st.expander("Help & Information"):
50
  display_internal_loads_help()
51
 
52
- # Initialize rerun flags if not present
53
- if "module_rerun_flags" not in st.session_state:
54
- st.session_state.module_rerun_flags = {}
55
 
56
  # Check if rerun is pending
57
- if st.session_state.module_rerun_flags.get("internal_loads", False):
58
- st.session_state.module_rerun_flags["internal_loads"] = False
59
  st.rerun()
60
 
61
  # Create tabs for different load types
@@ -240,21 +240,21 @@ def display_people_tab():
240
  if is_edit:
241
  index = editor_state.get("index", 0)
242
  st.session_state.project_data["internal_loads"]["people"][index] = people_data
243
- st.success(f"People group '{name}' updated!")
244
  else:
245
  st.session_state.project_data["internal_loads"]["people"].append(people_data)
246
- st.success(f"People group '{name}' added!")
247
 
248
  # Clear editor state
249
  st.session_state.people_editor = {}
250
  st.session_state.people_action = {"action": "save", "id": str(uuid.uuid4())}
251
- st.session_state.module_rerun_flags["internal_loads"] = True
252
 
253
  elif refresh:
254
  # Clear editor state
255
  st.session_state.people_editor = {}
256
  st.session_state.people_action = {"action": "refresh", "id": str(uuid.uuid4())}
257
- st.session_state.module_rerun_flags["internal_loads"] = True
258
 
259
  def display_lighting_tab():
260
  """Display the lighting tab content with a two-column layout similar to components.py."""
@@ -397,21 +397,21 @@ def display_lighting_tab():
397
  if is_edit:
398
  index = editor_state.get("index", 0)
399
  st.session_state.project_data["internal_loads"]["lighting"][index] = lighting_data
400
- st.success(f"Lighting system '{name}' updated!")
401
  else:
402
  st.session_state.project_data["internal_loads"]["lighting"].append(lighting_data)
403
- st.success(f"Lighting system '{name}' added!")
404
 
405
  # Clear editor state
406
  st.session_state.lighting_editor = {}
407
  st.session_state.lighting_action = {"action": "save", "id": str(uuid.uuid4())}
408
- st.session_state.module_rerun_flags["internal_loads"] = True
409
 
410
  elif refresh:
411
  # Clear editor state
412
  st.session_state.lighting_editor = {}
413
  st.session_state.lighting_action = {"action": "refresh", "id": str(uuid.uuid4())}
414
- st.session_state.module_rerun_flags["internal_loads"] = True
415
 
416
  def display_equipment_tab():
417
  """Display the equipment tab content with a two-column layout similar to components.py."""
@@ -578,13 +578,13 @@ def display_equipment_tab():
578
  # Clear editor state
579
  st.session_state.equipment_editor = {}
580
  st.session_state.equipment_action = {"action": "save", "id": str(uuid.uuid4())}
581
- st.session_state.module_rerun_flags["internal_loads"] = True
582
 
583
  elif refresh:
584
  # Clear editor state
585
  st.session_state.equipment_editor = {}
586
  st.session_state.equipment_action = {"action": "refresh", "id": str(uuid.uuid4())}
587
- st.session_state.module_rerun_flags["internal_loads"] = True
588
 
589
  def display_ventilation_infiltration_tab():
590
  """Display the ventilation/infiltration tab content with a two-column layout similar to components.py."""
@@ -720,21 +720,21 @@ def display_ventilation_infiltration_tab():
720
  if is_edit:
721
  index = editor_state.get("index", 0)
722
  st.session_state.project_data["internal_loads"]["ventilation_infiltration"][index] = vent_inf_data
723
- st.success(f"{system_type} system '{name}' updated!")
724
  else:
725
  st.session_state.project_data["internal_loads"]["ventilation_infiltration"].append(vent_inf_data)
726
- st.success(f"{system_type} system '{name}' added!")
727
 
728
  # Clear editor state
729
  st.session_state.vent_inf_editor = {}
730
  st.session_state.vent_inf_action = {"action": "save", "id": str(uuid.uuid4())}
731
- st.session_state.module_rerun_flags["internal_loads"] = True
732
 
733
  elif refresh:
734
  # Clear editor state
735
  st.session_state.vent_inf_editor = {}
736
  st.session_state.vent_inf_action = {"action": "refresh", "id": str(uuid.uuid4())}
737
- st.session_state.module_rerun_flags["internal_loads"] = True
738
 
739
  def display_schedules_tab():
740
  import streamlit as st
@@ -785,7 +785,7 @@ def display_schedules_tab():
785
  for hour in range(24):
786
  st.session_state[f"weekday_slider_{hour}_value"] = 0.0
787
  st.session_state[f"weekend_slider_{hour}_value"] = 0.0
788
- st.session_state.module_rerun_flags["internal_loads"] = True
789
  st.rerun()
790
 
791
  # UI FORM for name/description and actions
@@ -866,75 +866,65 @@ def display_schedules_tab():
866
 
867
  # Save logic
868
  if submitted:
869
- action_id = str(uuid.uuid4())
870
- if st.session_state.schedule_action.get("id") != action_id:
871
- st.session_state.schedule_action = {"action": "save", "id": action_id}
872
- if not name.strip():
873
- st.error("Schedule name is required.")
874
- elif name in schedules and not editor_state.get("is_edit"):
875
- st.error("A schedule with this name already exists.")
876
- else:
877
- schedules[name] = {
878
- "description": description,
879
- "weekday": weekday_values,
880
- "weekend": weekend_values
881
- }
882
- if editor_state.get("is_edit") and editor_state.get("original_name") and editor_state.get("original_name") != name:
883
- if editor_state["original_name"] in schedules:
884
- del schedules[editor_state["original_name"]]
885
- st.session_state.schedule_editor = DEFAULT_STATE.copy()
886
- for hour in range(24):
887
- st.session_state[f"weekday_slider_{hour}_value"] = 0.0
888
- st.session_state[f"weekend_slider_{hour}_value"] = 0.0
889
- st.success(f"Schedule '{name}' saved successfully.")
890
- st.session_state.schedule_action = {"action": None, "id": None}
891
- st.session_state.module_rerun_flags["internal_loads"] = True
892
- st.rerun()
893
 
894
  # Edit logic
895
  if edit_submitted and saved_schedule:
896
- action_id = str(uuid.uuid4())
897
- if st.session_state.schedule_action.get("id") != action_id:
898
- st.session_state.schedule_action = {"action": "edit", "id": action_id}
899
- if saved_schedule in DEFAULT_SCHEDULE_TEMPLATES:
900
- st.error("Default schedules cannot be edited.")
901
- else:
902
- schedule_data = schedules[saved_schedule]
903
- st.session_state.schedule_editor = {
904
- "is_edit": True,
905
- "original_name": saved_schedule,
906
- "name": saved_schedule,
907
- "description": schedule_data.get("description", ""),
908
- "weekday": schedule_data.get("weekday", [0.0] * 24),
909
- "weekend": schedule_data.get("weekend", [0.0] * 24),
910
- "template": "None"
911
- }
912
- for hour in range(24):
913
- st.session_state[f"weekday_slider_{hour}_value"] = schedule_data.get("weekday", [0.0] * 24)[hour]
914
- st.session_state[f"weekend_slider_{hour}_value"] = schedule_data.get("weekend", [0.0] * 24)[hour]
915
- st.session_state.schedule_action = {"action": None, "id": None}
916
- st.session_state.module_rerun_flags["internal_loads"] = True
917
- st.rerun()
918
 
919
  # Delete logic
920
  if delete_submitted and saved_schedule:
921
- action_id = str(uuid.uuid4())
922
- if st.session_state.schedule_action.get("id") != action_id:
923
- st.session_state.schedule_action = {"action": "delete", "id": action_id}
924
- if saved_schedule in DEFAULT_SCHEDULE_TEMPLATES:
925
- st.error("Default schedules cannot be deleted.")
926
- elif is_schedule_in_use(saved_schedule):
927
- st.error(f"Schedule '{saved_schedule}' is in use and cannot be deleted.")
928
- else:
929
- del schedules[saved_schedule]
930
- st.session_state.schedule_editor = DEFAULT_STATE.copy()
931
- for hour in range(24):
932
- st.session_state[f"weekday_slider_{hour}_value"] = 0.0
933
- st.session_state[f"weekend_slider_{hour}_value"] = 0.0
934
- st.success(f"Schedule '{saved_schedule}' deleted!")
935
- st.session_state.schedule_action = {"action": None, "id": None}
936
- st.session_state.module_rerun_flags["internal_loads"] = True
937
- st.rerun()
938
 
939
  def is_schedule_in_use(schedule_name: str) -> bool:
940
  """
@@ -983,7 +973,7 @@ def display_people_table(people_groups: List[Dict[str, Any]]):
983
  cols[4].write(group.get("zone", "Unknown"))
984
 
985
  # Edit button
986
- edit_key = f"edit_people_{group['id']}_{idx}"
987
  with cols[5].container():
988
  if st.button("Edit", key=edit_key):
989
  st.session_state.people_editor = {
@@ -998,16 +988,16 @@ def display_people_table(people_groups: List[Dict[str, Any]]):
998
  "is_edit": True
999
  }
1000
  st.session_state.people_action = {"action": "edit", "id": str(uuid.uuid4())}
1001
- st.session_state.module_rerun_flags["internal_loads"] = True
1002
 
1003
  # Delete button
1004
- delete_key = f"delete_people_{group['id']}_{idx}"
1005
  with cols[6].container():
1006
  if st.button("Delete", key=delete_key):
1007
  st.session_state.project_data["internal_loads"]["people"].pop(idx)
1008
- st.success(f"People group '{group['name']}' deleted!")
1009
  st.session_state.people_action = {"action": "delete", "id": str(uuid.uuid4())}
1010
- st.session_state.module_rerun_flags["internal_loads"] = True
1011
 
1012
  def display_lighting_table(lighting_systems: List[Dict[str, Any]]):
1013
  """Display lighting systems in a table format with edit/delete buttons."""
@@ -1031,7 +1021,7 @@ def display_lighting_table(lighting_systems: List[Dict[str, Any]]):
1031
  cols[4].write(system.get("zone", "Unknown"))
1032
 
1033
  # Edit button
1034
- edit_key = f"edit_lighting_{system['id']}_{idx}"
1035
  with cols[5].container():
1036
  if st.button("Edit", key=edit_key):
1037
  st.session_state.lighting_editor = {
@@ -1046,16 +1036,16 @@ def display_lighting_table(lighting_systems: List[Dict[str, Any]]):
1046
  "is_edit": True
1047
  }
1048
  st.session_state.lighting_action = {"action": "edit", "id": str(uuid.uuid4())}
1049
- st.session_state.module_rerun_flags["internal_loads"] = True
1050
 
1051
  # Delete button
1052
- delete_key = f"delete_lighting_{system['id']}_{idx}"
1053
  with cols[6].container():
1054
  if st.button("Delete", key=delete_key):
1055
  st.session_state.project_data["internal_loads"]["lighting"].pop(idx)
1056
- st.success(f"Lighting system '{system['name']}' deleted!")
1057
  st.session_state.lighting_action = {"action": "delete", "id": str(uuid.uuid4())}
1058
- st.session_state.module_rerun_flags["internal_loads"] = True
1059
 
1060
  def display_equipment_table(equipment_systems: List[Dict[str, Any]]):
1061
  """Display equipment systems in a table format with edit/delete buttons."""
@@ -1079,7 +1069,7 @@ def display_equipment_table(equipment_systems: List[Dict[str, Any]]):
1079
  cols[4].write(system.get("zone", "Unknown"))
1080
 
1081
  # Edit button
1082
- edit_key = f"edit_equipment_{system['id']}_{idx}"
1083
  with cols[5].container():
1084
  if st.button("Edit", key=edit_key):
1085
  st.session_state.equipment_editor = {
@@ -1095,16 +1085,16 @@ def display_equipment_table(equipment_systems: List[Dict[str, Any]]):
1095
  "is_edit": True
1096
  }
1097
  st.session_state.equipment_action = {"action": "edit", "id": str(uuid.uuid4())}
1098
- st.session_state.module_rerun_flags["internal_loads"] = True
1099
 
1100
  # Delete button
1101
- delete_key = f"delete_equipment_{system['id']}_{idx}"
1102
  with cols[6].container():
1103
  if st.button("Delete", key=delete_key):
1104
  st.session_state.project_data["internal_loads"]["equipment"].pop(idx)
1105
  st.success(f"Equipment '{system['name']}' deleted!")
1106
  st.session_state.equipment_action = {"action": "delete", "id": str(uuid.uuid4())}
1107
- st.session_state.module_rerun_flags["internal_loads"] = True
1108
 
1109
  def display_ventilation_infiltration_table(vent_inf_systems: List[Dict[str, Any]]):
1110
  """Display ventilation/infiltration systems in a table format with edit/delete buttons."""
@@ -1129,7 +1119,7 @@ def display_ventilation_infiltration_table(vent_inf_systems: List[Dict[str, Any]
1129
  cols[4].write(system.get("zone", "Unknown"))
1130
 
1131
  # Edit button
1132
- edit_key = f"edit_vent_inf_{system['id']}_{idx}"
1133
  with cols[5].container():
1134
  if st.button("Edit", key=edit_key):
1135
  st.session_state.vent_inf_editor = {
@@ -1144,16 +1134,16 @@ def display_ventilation_infiltration_table(vent_inf_systems: List[Dict[str, Any]
1144
  "is_edit": True
1145
  }
1146
  st.session_state.vent_inf_action = {"action": "edit", "id": str(uuid.uuid4())}
1147
- st.session_state.module_rerun_flags["internal_loads"] = True
1148
 
1149
  # Delete button
1150
- delete_key = f"delete_vent_inf_{system['id']}_{idx}"
1151
  with cols[6].container():
1152
  if st.button("Delete", key=delete_key):
1153
  st.session_state.project_data["internal_loads"]["ventilation_infiltration"].pop(idx)
1154
  st.success(f"{system.get('system_type', 'System')} '{system['name']}' deleted!")
1155
  st.session_state.vent_inf_action = {"action": "delete", "id": str(uuid.uuid4())}
1156
- st.session_state.module_rerun_flags["internal_loads"] = True
1157
 
1158
  def display_schedules_table(schedules: Dict[str, Any]):
1159
  """Display schedules in a table format with edit/delete buttons."""
@@ -1206,8 +1196,8 @@ def display_schedules_table(schedules: Dict[str, Any]):
1206
  "weekday": schedule_data.get("weekday", [0.0] * 24),
1207
  "weekend": schedule_data.get("weekend", [0.0] * 24)
1208
  }
1209
- st.session_state.module_rerun_flags["internal_loads"] = True
1210
- st.rerun()
1211
 
1212
  with col4:
1213
  if schedule_name not in DEFAULT_SCHEDULE_TEMPLATES:
@@ -1217,7 +1207,7 @@ def display_schedules_table(schedules: Dict[str, Any]):
1217
  if st.button("Delete", key=f"delete_schedule_{schedule_name}_{i}"):
1218
  del schedules[schedule_name]
1219
  st.success(f"Schedule '{schedule_name}' deleted!")
1220
- st.session_state.module_rerun_flags["internal_loads"] = True
1221
- st.rerun()
1222
  else:
1223
  st.write("(Default)")
 
49
  with st.expander("Help & Information"):
50
  display_internal_loads_help()
51
 
52
+ # Initialize rerun flag if not present
53
+ if "internal_loads_rerun_pending" not in st.session_state:
54
+ st.session_state.internal_loads_rerun_pending = False
55
 
56
  # Check if rerun is pending
57
+ if st.session_state.internal_loads_rerun_pending:
58
+ st.session_state.internal_loads_rerun_pending = False
59
  st.rerun()
60
 
61
  # Create tabs for different load types
 
240
  if is_edit:
241
  index = editor_state.get("index", 0)
242
  st.session_state.project_data["internal_loads"]["people"][index] = people_data
243
+ st.success(f"People Group '{name}' updated!")
244
  else:
245
  st.session_state.project_data["internal_loads"]["people"].append(people_data)
246
+ st.success(f"People Group '{name}' added!")
247
 
248
  # Clear editor state
249
  st.session_state.people_editor = {}
250
  st.session_state.people_action = {"action": "save", "id": str(uuid.uuid4())}
251
+ st.session_state.internal_loads_rerun_pending = True
252
 
253
  elif refresh:
254
  # Clear editor state
255
  st.session_state.people_editor = {}
256
  st.session_state.people_action = {"action": "refresh", "id": str(uuid.uuid4())}
257
+ st.session_state.internal_loads_rerun_pending = True
258
 
259
  def display_lighting_tab():
260
  """Display the lighting tab content with a two-column layout similar to components.py."""
 
397
  if is_edit:
398
  index = editor_state.get("index", 0)
399
  st.session_state.project_data["internal_loads"]["lighting"][index] = lighting_data
400
+ st.success(f"Lighting System '{name}' updated!")
401
  else:
402
  st.session_state.project_data["internal_loads"]["lighting"].append(lighting_data)
403
+ st.success(f"Lighting System '{name}' added!")
404
 
405
  # Clear editor state
406
  st.session_state.lighting_editor = {}
407
  st.session_state.lighting_action = {"action": "save", "id": str(uuid.uuid4())}
408
+ st.session_state.internal_loads_rerun_pending = True
409
 
410
  elif refresh:
411
  # Clear editor state
412
  st.session_state.lighting_editor = {}
413
  st.session_state.lighting_action = {"action": "refresh", "id": str(uuid.uuid4())}
414
+ st.session_state.internal_loads_rerun_pending = True
415
 
416
  def display_equipment_tab():
417
  """Display the equipment tab content with a two-column layout similar to components.py."""
 
578
  # Clear editor state
579
  st.session_state.equipment_editor = {}
580
  st.session_state.equipment_action = {"action": "save", "id": str(uuid.uuid4())}
581
+ st.session_state.internal_loads_rerun_pending = True
582
 
583
  elif refresh:
584
  # Clear editor state
585
  st.session_state.equipment_editor = {}
586
  st.session_state.equipment_action = {"action": "refresh", "id": str(uuid.uuid4())}
587
+ st.session_state.internal_loads_rerun_pending = True
588
 
589
  def display_ventilation_infiltration_tab():
590
  """Display the ventilation/infiltration tab content with a two-column layout similar to components.py."""
 
720
  if is_edit:
721
  index = editor_state.get("index", 0)
722
  st.session_state.project_data["internal_loads"]["ventilation_infiltration"][index] = vent_inf_data
723
+ st.success(f"{system_type} System '{name}' updated!")
724
  else:
725
  st.session_state.project_data["internal_loads"]["ventilation_infiltration"].append(vent_inf_data)
726
+ st.success(f"{system_type} System '{name}' added!")
727
 
728
  # Clear editor state
729
  st.session_state.vent_inf_editor = {}
730
  st.session_state.vent_inf_action = {"action": "save", "id": str(uuid.uuid4())}
731
+ st.session_state.internal_loads_rerun_pending = True
732
 
733
  elif refresh:
734
  # Clear editor state
735
  st.session_state.vent_inf_editor = {}
736
  st.session_state.vent_inf_action = {"action": "refresh", "id": str(uuid.uuid4())}
737
+ st.session_state.internal_loads_rerun_pending = True
738
 
739
  def display_schedules_tab():
740
  import streamlit as st
 
785
  for hour in range(24):
786
  st.session_state[f"weekday_slider_{hour}_value"] = 0.0
787
  st.session_state[f"weekend_slider_{hour}_value"] = 0.0
788
+ st.session_state.internal_loads_rerun_pending = True
789
  st.rerun()
790
 
791
  # UI FORM for name/description and actions
 
866
 
867
  # Save logic
868
  if submitted:
869
+ if not name.strip():
870
+ st.error("Schedule name is required.")
871
+ return
872
+ if name in schedules and not editor_state.get("is_edit"):
873
+ st.error("A schedule with this name already exists.")
874
+ return
875
+ schedules[name] = {
876
+ "description": description,
877
+ "weekday": weekday_values,
878
+ "weekend": weekend_values
879
+ }
880
+ if editor_state.get("is_edit") and editor_state.get("original_name") and editor_state.get("original_name") != name:
881
+ if editor_state["original_name"] in schedules:
882
+ del schedules[editor_state["original_name"]]
883
+ st.session_state.schedule_editor = DEFAULT_STATE.copy()
884
+ for hour in range(24):
885
+ st.session_state[f"weekday_slider_{hour}_value"] = 0.0
886
+ st.session_state[f"weekend_slider_{hour}_value"] = 0.0
887
+ st.success(f"Schedule '{name}' saved successfully.")
888
+ st.session_state.schedule_action = {"action": "save", "id": str(uuid.uuid4())}
889
+ st.session_state.internal_loads_rerun_pending = True
 
 
 
890
 
891
  # Edit logic
892
  if edit_submitted and saved_schedule:
893
+ if saved_schedule in DEFAULT_SCHEDULE_TEMPLATES:
894
+ st.error("Default schedules cannot be edited.")
895
+ return
896
+ schedule_data = schedules[saved_schedule]
897
+ st.session_state.schedule_editor = {
898
+ "is_edit": True,
899
+ "original_name": saved_schedule,
900
+ "name": saved_schedule,
901
+ "description": schedule_data.get("description", ""),
902
+ "weekday": schedule_data.get("weekday", [0.0] * 24),
903
+ "weekend": schedule_data.get("weekend", [0.0] * 24),
904
+ "template": "None"
905
+ }
906
+ for hour in range(24):
907
+ st.session_state[f"weekday_slider_{hour}_value"] = schedule_data.get("weekday", [0.0] * 24)[hour]
908
+ st.session_state[f"weekend_slider_{hour}_value"] = schedule_data.get("weekend", [0.0] * 24)[hour]
909
+ st.session_state.schedule_action = {"action": "edit", "id": str(uuid.uuid4())}
910
+ st.session_state.internal_loads_rerun_pending = True
 
 
 
 
911
 
912
  # Delete logic
913
  if delete_submitted and saved_schedule:
914
+ if saved_schedule in DEFAULT_SCHEDULE_TEMPLATES:
915
+ st.error("Default schedules cannot be deleted.")
916
+ return
917
+ if is_schedule_in_use(saved_schedule):
918
+ st.error(f"Schedule '{saved_schedule}' is in use and cannot be deleted.")
919
+ return
920
+ del schedules[saved_schedule]
921
+ st.session_state.schedule_editor = DEFAULT_STATE.copy()
922
+ for hour in range(24):
923
+ st.session_state[f"weekday_slider_{hour}_value"] = 0.0
924
+ st.session_state[f"weekend_slider_{hour}_value"] = 0.0
925
+ st.success(f"Schedule '{saved_schedule}' deleted!")
926
+ st.session_state.schedule_action = {"action": "delete", "id": str(uuid.uuid4())}
927
+ st.session_state.internal_loads_rerun_pending = True
 
 
 
928
 
929
  def is_schedule_in_use(schedule_name: str) -> bool:
930
  """
 
973
  cols[4].write(group.get("zone", "Unknown"))
974
 
975
  # Edit button
976
+ edit_key = f"edit_people_{group['name']}_{idx}"
977
  with cols[5].container():
978
  if st.button("Edit", key=edit_key):
979
  st.session_state.people_editor = {
 
988
  "is_edit": True
989
  }
990
  st.session_state.people_action = {"action": "edit", "id": str(uuid.uuid4())}
991
+ st.session_state.internal_loads_rerun_pending = True
992
 
993
  # Delete button
994
+ delete_key = f"delete_people_{group['name']}_{idx}"
995
  with cols[6].container():
996
  if st.button("Delete", key=delete_key):
997
  st.session_state.project_data["internal_loads"]["people"].pop(idx)
998
+ st.success(f"People Group '{group['name']}' deleted!")
999
  st.session_state.people_action = {"action": "delete", "id": str(uuid.uuid4())}
1000
+ st.session_state.internal_loads_rerun_pending = True
1001
 
1002
  def display_lighting_table(lighting_systems: List[Dict[str, Any]]):
1003
  """Display lighting systems in a table format with edit/delete buttons."""
 
1021
  cols[4].write(system.get("zone", "Unknown"))
1022
 
1023
  # Edit button
1024
+ edit_key = f"edit_lighting_{system['name']}_{idx}"
1025
  with cols[5].container():
1026
  if st.button("Edit", key=edit_key):
1027
  st.session_state.lighting_editor = {
 
1036
  "is_edit": True
1037
  }
1038
  st.session_state.lighting_action = {"action": "edit", "id": str(uuid.uuid4())}
1039
+ st.session_state.internal_loads_rerun_pending = True
1040
 
1041
  # Delete button
1042
+ delete_key = f"delete_lighting_{system['name']}_{idx}"
1043
  with cols[6].container():
1044
  if st.button("Delete", key=delete_key):
1045
  st.session_state.project_data["internal_loads"]["lighting"].pop(idx)
1046
+ st.success(f"Lighting System '{system['name']}' deleted!")
1047
  st.session_state.lighting_action = {"action": "delete", "id": str(uuid.uuid4())}
1048
+ st.session_state.internal_loads_rerun_pending = True
1049
 
1050
  def display_equipment_table(equipment_systems: List[Dict[str, Any]]):
1051
  """Display equipment systems in a table format with edit/delete buttons."""
 
1069
  cols[4].write(system.get("zone", "Unknown"))
1070
 
1071
  # Edit button
1072
+ edit_key = f"edit_equipment_{system['name']}_{idx}"
1073
  with cols[5].container():
1074
  if st.button("Edit", key=edit_key):
1075
  st.session_state.equipment_editor = {
 
1085
  "is_edit": True
1086
  }
1087
  st.session_state.equipment_action = {"action": "edit", "id": str(uuid.uuid4())}
1088
+ st.session_state.internal_loads_rerun_pending = True
1089
 
1090
  # Delete button
1091
+ delete_key = f"delete_equipment_{system['name']}_{idx}"
1092
  with cols[6].container():
1093
  if st.button("Delete", key=delete_key):
1094
  st.session_state.project_data["internal_loads"]["equipment"].pop(idx)
1095
  st.success(f"Equipment '{system['name']}' deleted!")
1096
  st.session_state.equipment_action = {"action": "delete", "id": str(uuid.uuid4())}
1097
+ st.session_state.internal_loads_rerun_pending = True
1098
 
1099
  def display_ventilation_infiltration_table(vent_inf_systems: List[Dict[str, Any]]):
1100
  """Display ventilation/infiltration systems in a table format with edit/delete buttons."""
 
1119
  cols[4].write(system.get("zone", "Unknown"))
1120
 
1121
  # Edit button
1122
+ edit_key = f"edit_vent_inf_{system['name']}_{idx}"
1123
  with cols[5].container():
1124
  if st.button("Edit", key=edit_key):
1125
  st.session_state.vent_inf_editor = {
 
1134
  "is_edit": True
1135
  }
1136
  st.session_state.vent_inf_action = {"action": "edit", "id": str(uuid.uuid4())}
1137
+ st.session_state.internal_loads_rerun_pending = True
1138
 
1139
  # Delete button
1140
+ delete_key = f"delete_vent_inf_{system['name']}_{idx}"
1141
  with cols[6].container():
1142
  if st.button("Delete", key=delete_key):
1143
  st.session_state.project_data["internal_loads"]["ventilation_infiltration"].pop(idx)
1144
  st.success(f"{system.get('system_type', 'System')} '{system['name']}' deleted!")
1145
  st.session_state.vent_inf_action = {"action": "delete", "id": str(uuid.uuid4())}
1146
+ st.session_state.internal_loads_rerun_pending = True
1147
 
1148
  def display_schedules_table(schedules: Dict[str, Any]):
1149
  """Display schedules in a table format with edit/delete buttons."""
 
1196
  "weekday": schedule_data.get("weekday", [0.0] * 24),
1197
  "weekend": schedule_data.get("weekend", [0.0] * 24)
1198
  }
1199
+ st.session_state.schedule_action = {"action": "edit", "id": str(uuid.uuid4())}
1200
+ st.session_state.internal_loads_rerun_pending = True
1201
 
1202
  with col4:
1203
  if schedule_name not in DEFAULT_SCHEDULE_TEMPLATES:
 
1207
  if st.button("Delete", key=f"delete_schedule_{schedule_name}_{i}"):
1208
  del schedules[schedule_name]
1209
  st.success(f"Schedule '{schedule_name}' deleted!")
1210
+ st.session_state.schedule_action = {"action": "delete", "id": str(uuid.uuid4())}
1211
+ st.session_state.internal_loads_rerun_pending = True
1212
  else:
1213
  st.write("(Default)")