Skip to content

Commit 0ca1cd7

Browse files
fix constant type
1 parent 9fc4292 commit 0ca1cd7

2 files changed

Lines changed: 83 additions & 30 deletions

File tree

comcheck_api/project_operations/project_envelope_operations.py

Lines changed: 79 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
# *********** Roof, agWall, bgWall and floor add/update operations ***********
2323

24+
2425
def add_roof_to_project(
2526
project: ComBuilding, building_area_key: str, new_roof: Roof
2627
) -> ComBuilding:
@@ -63,10 +64,15 @@ def update_roof_in_project(
6364
"""
6465
updated_project = project.model_copy(deep=True)
6566

66-
updated_project.envelope.update_subcomponent_list(subcomponent_updates=updates, subcomponent_id=roof_assembly_type, subcomponent_name="roof")
67+
updated_project.envelope.update_subcomponent_list(
68+
subcomponent_updates=updates,
69+
subcomponent_id=roof_assembly_type,
70+
subcomponent_name="roof",
71+
)
6772

6873
return updated_project
6974

75+
7076
def remove_roof_from_project(
7177
project: ComBuilding, roof_assembly_type: str
7278
) -> ComBuilding:
@@ -84,10 +90,13 @@ def remove_roof_from_project(
8490
"""
8591
updated_project = project.model_copy(deep=True)
8692

87-
updated_project.envelope.remove_from_subcomponent_list(subcomponent_id=roof_assembly_type, subcomponent_name="roof")
93+
updated_project.envelope.remove_from_subcomponent_list(
94+
subcomponent_id=roof_assembly_type, subcomponent_name="roof"
95+
)
8896

8997
return updated_project
9098

99+
91100
def add_ag_wall_to_project(
92101
project: ComBuilding, building_area_key: str, new_ag_wall: AgWall
93102
) -> ComBuilding:
@@ -130,10 +139,15 @@ def update_ag_wall_in_project(
130139
"""
131140
updated_project = project.model_copy(deep=True)
132141

133-
updated_project.envelope.update_subcomponent_list(subcomponent_updates=updates, subcomponent_id=ag_wall_assembly_type, subcomponent_name="agWall")
142+
updated_project.envelope.update_subcomponent_list(
143+
subcomponent_updates=updates,
144+
subcomponent_id=ag_wall_assembly_type,
145+
subcomponent_name="agWall",
146+
)
134147

135148
return updated_project
136149

150+
137151
def remove_ag_wall_from_project(
138152
project: ComBuilding, ag_wall_assembly_type: str
139153
) -> ComBuilding:
@@ -151,7 +165,9 @@ def remove_ag_wall_from_project(
151165
"""
152166
updated_project = project.model_copy(deep=True)
153167

154-
updated_project.envelope.remove_from_subcomponent_list(subcomponent_id=ag_wall_assembly_type, subcomponent_name="agWall")
168+
updated_project.envelope.remove_from_subcomponent_list(
169+
subcomponent_id=ag_wall_assembly_type, subcomponent_name="agWall"
170+
)
155171

156172
return updated_project
157173

@@ -197,7 +213,11 @@ def update_bg_wall_in_project(
197213
"""
198214
updated_project = project.model_copy(deep=True)
199215

200-
updated_project.envelope.update_subcomponent_list(subcomponent_updates=updates, subcomponent_id=bg_wall_assembly_type, subcomponent_name="bgWall")
216+
updated_project.envelope.update_subcomponent_list(
217+
subcomponent_updates=updates,
218+
subcomponent_id=bg_wall_assembly_type,
219+
subcomponent_name="bgWall",
220+
)
201221

202222
return updated_project
203223

@@ -219,12 +239,13 @@ def remove_bg_wall_from_project(
219239
"""
220240
updated_project = project.model_copy(deep=True)
221241

222-
updated_project.envelope.remove_from_subcomponent_list(subcomponent_id=bg_wall_assembly_type, subcomponent_name="bgWall")
242+
updated_project.envelope.remove_from_subcomponent_list(
243+
subcomponent_id=bg_wall_assembly_type, subcomponent_name="bgWall"
244+
)
223245

224246
return updated_project
225247

226248

227-
228249
def add_floor_to_project(
229250
project: ComBuilding, building_area_key: str, new_floor: Floor
230251
) -> ComBuilding:
@@ -266,10 +287,15 @@ def update_floor_in_project(
266287
"""
267288
updated_project = project.model_copy(deep=True)
268289

269-
updated_project.envelope.update_subcomponent_list(subcomponent_updates=updates, subcomponent_id=floor_assembly_type, subcomponent_name="floor")
290+
updated_project.envelope.update_subcomponent_list(
291+
subcomponent_updates=updates,
292+
subcomponent_id=floor_assembly_type,
293+
subcomponent_name="floor",
294+
)
270295

271296
return updated_project
272297

298+
273299
def remove_floor_from_project(
274300
project: ComBuilding, floor_assembly_type: str
275301
) -> ComBuilding:
@@ -287,7 +313,9 @@ def remove_floor_from_project(
287313
"""
288314
updated_project = project.model_copy(deep=True)
289315

290-
updated_project.envelope.remove_from_subcomponent_list(subcomponent_id=floor_assembly_type, subcomponent_name="floor")
316+
updated_project.envelope.remove_from_subcomponent_list(
317+
subcomponent_id=floor_assembly_type, subcomponent_name="floor"
318+
)
291319

292320
return updated_project
293321

@@ -345,6 +373,7 @@ def add_skylight_to_project(
345373
updated_project.envelope.append_subcomponent(new_skylight, "skylight")
346374
return updated_project
347375

376+
348377
def remove_skylight_from_project(
349378
project: ComBuilding,
350379
skylight_assembly_type: str,
@@ -372,11 +401,14 @@ def remove_skylight_from_project(
372401
if location_type == "orphaned":
373402
parent_obj = updated_project.envelope
374403
elif location_type == "roof":
375-
parent_obj = updated_project.envelope.roof[roof_index]
376-
parent_obj.remove_from_subcomponent_list(subcomponent_id=skylight_assembly_type, subcomponent_name="skylight")
404+
parent_obj = updated_project.envelope.roof[roof_index] # type: ignore[index]
405+
parent_obj.remove_from_subcomponent_list(
406+
subcomponent_id=skylight_assembly_type, subcomponent_name="skylight"
407+
)
377408

378409
return updated_project
379410

411+
380412
def update_skylight_in_project(
381413
project: ComBuilding,
382414
skylight_assembly_type: str,
@@ -410,8 +442,12 @@ def update_skylight_in_project(
410442
if location_type == "orphaned":
411443
parent_obj = updated_project.envelope
412444
elif location_type == "roof":
413-
parent_obj = updated_project.envelope.roof[roof_index]
414-
parent_obj.update_subcomponent_list(subcomponent_updates=updates, subcomponent_id=skylight_assembly_type, subcomponent_name="skylight")
445+
parent_obj = updated_project.envelope.roof[roof_index] # type: ignore[index]
446+
parent_obj.update_subcomponent_list(
447+
subcomponent_updates=updates,
448+
subcomponent_id=skylight_assembly_type,
449+
subcomponent_name="skylight",
450+
)
415451

416452
return updated_project
417453

@@ -465,7 +501,8 @@ def add_window_to_project(
465501
# Alteration projects: orphaned windows
466502
updated_project.envelope.append_subcomponent(new_window, "window")
467503
return updated_project
468-
504+
505+
469506
def remove_window_from_project(
470507
project: ComBuilding,
471508
window_assembly_type: str,
@@ -490,8 +527,10 @@ def remove_window_from_project(
490527
if location_type == "orphaned":
491528
parent_obj = updated_project.envelope
492529
elif location_type in ["agWall", "bgWall"]:
493-
parent_obj = updated_project.envelope.get_by_path(f"{location_type}[{wall_index}]")
494-
parent_obj.remove_from_subcomponent_list(subcomponent_id=window_assembly_type, subcomponent_name="window")
530+
parent_obj = updated_project.envelope.get_by_path(f"{location_type}[{wall_index}]") # type: ignore[assignment]
531+
parent_obj.remove_from_subcomponent_list(
532+
subcomponent_id=window_assembly_type, subcomponent_name="window"
533+
)
495534

496535
return updated_project
497536

@@ -528,8 +567,12 @@ def update_window_in_project(
528567
if location_type == "orphaned":
529568
parent_obj = updated_project.envelope
530569
elif location_type in ["agWall", "bgWall"]:
531-
parent_obj = updated_project.envelope.get_by_path(f"{location_type}[{wall_index}]")
532-
parent_obj.update_subcomponent_list(subcomponent_updates=updates, subcomponent_id=window_assembly_type, subcomponent_name="window")
570+
parent_obj = updated_project.envelope.get_by_path(f"{location_type}[{wall_index}]") # type: ignore[assignment]
571+
parent_obj.update_subcomponent_list(
572+
subcomponent_updates=updates,
573+
subcomponent_id=window_assembly_type,
574+
subcomponent_name="window",
575+
)
533576

534577
return updated_project
535578

@@ -574,7 +617,11 @@ def add_door_to_project(
574617
f"Wall's bldgUseKey '{wall_use_key}' does not match buildingAreaKey '{building_area_key}'."
575618
)
576619
wall.append_subcomponent(new_door, "door")
577-
updated_project.envelope.update_subcomponent_list(subcomponent_updates=wall, subcomponent_id=getattr(wall, "assemblyType"), subcomponent_name=wall.json_key())
620+
updated_project.envelope.update_subcomponent_list(
621+
subcomponent_updates=wall,
622+
subcomponent_id=getattr(wall, "assemblyType"),
623+
subcomponent_name=wall.json_key(),
624+
)
578625
return updated_project
579626
else:
580627
updated_project.envelope.append_subcomponent(new_door)
@@ -606,11 +653,14 @@ def remove_door_from_project(
606653
if location_type == "orphaned":
607654
parent_obj = updated_project.envelope
608655
elif location_type in ["agWall", "bgWall"]:
609-
parent_obj = updated_project.envelope.get_by_path(f"{location_type}[{wall_index}]")
610-
parent_obj.remove_from_subcomponent_list(subcomponent_id=door_assembly_type, subcomponent_name="door")
656+
parent_obj = updated_project.envelope.get_by_path(f"{location_type}[{wall_index}]") # type: ignore[assignment]
657+
parent_obj.remove_from_subcomponent_list(
658+
subcomponent_id=door_assembly_type, subcomponent_name="door"
659+
)
611660

612661
return updated_project
613662

663+
614664
def update_door_in_project(
615665
project: ComBuilding, door_assembly_type: str, updates: dict[str, Any] | Door
616666
) -> ComBuilding:
@@ -643,8 +693,12 @@ def update_door_in_project(
643693
if location_type == "orphaned":
644694
parent_obj = updated_project.envelope
645695
elif location_type in ["agWall", "bgWall"]:
646-
parent_obj = updated_project.envelope.get_by_path(f"{location_type}[{wall_index}]")
647-
parent_obj.update_subcomponent_list(subcomponent_updates=updates, subcomponent_id=door_assembly_type, subcomponent_name="door")
696+
parent_obj = updated_project.envelope.get_by_path(f"{location_type}[{wall_index}]") # type: ignore[assignment]
697+
parent_obj.update_subcomponent_list(
698+
subcomponent_updates=updates,
699+
subcomponent_id=door_assembly_type,
700+
subcomponent_name="door",
701+
)
648702

649703
return updated_project
650704

@@ -753,6 +807,7 @@ def add_thermal_bridge_to_project(
753807

754808
# *********** Helper Functions ***********
755809

810+
756811
def _find_component_location(
757812
project: ComBuilding, component_type: str, assembly_type: str
758813
) -> tuple[str, int | None, int | None]:
@@ -777,7 +832,7 @@ def _find_component_location(
777832
ValueError: If component is not found anywhere
778833
"""
779834
# Check orphaned components first
780-
835+
781836
if project.projectType == ProjectTypeOptions.ALTERATION:
782837
orphaned_list = getattr(project.envelope, component_type, [])
783838
component_index = next(
@@ -807,7 +862,6 @@ def _find_component_location(
807862
if component_index != -1:
808863
return ("agWall", ag_wall_index, component_index)
809864

810-
811865
# Check bgWall components
812866
for bg_wall_index, bg_wall in enumerate(project.envelope.bgWall):
813867
wall_components = getattr(bg_wall, component_type, [])
@@ -822,7 +876,6 @@ def _find_component_location(
822876
if component_index != -1:
823877
return ("bgWall", bg_wall_index, component_index)
824878

825-
826879
# For skylights: check roof components
827880
elif component_type == "skylight":
828881
for roof_index, roof in enumerate(project.envelope.roof or []):

pytest_fixtures/components.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from comcheck_api.types.core_types import *
22

3-
SAMPLE_PROJECT_ENVELOPE = Envelope(
4-
**{
3+
SAMPLE_PROJECT_ENVELOPE = Envelope.model_validate(
4+
{
55
"id": 13943,
66
"useVltDetails": True,
77
"useCoolRoofPerformanceDetails": False,
@@ -295,8 +295,8 @@
295295
)
296296

297297
SAMPLE_BUILDING_AREA = [
298-
WholeBldgUse(
299-
**{
298+
WholeBldgUse.model_validate(
299+
{
300300
"id": 45738,
301301
"lightingId": 13940,
302302
"key": "70084399",

0 commit comments

Comments
 (0)