diff --git a/datatypes/epc/domain/epc_property_data.py b/datatypes/epc/domain/epc_property_data.py index 328397e82..d55aa1593 100644 --- a/datatypes/epc/domain/epc_property_data.py +++ b/datatypes/epc/domain/epc_property_data.py @@ -39,12 +39,13 @@ class BuildingPartIdentifier(Enum): cls, api_identifier: Optional[object] ) -> "BuildingPartIdentifier": """Map a gov-EPC API `BuildingPart.identifier` to its canonical - member. "Main Dwelling" → MAIN; "Extension N" → EXTENSION_N + member. "Main Dwelling" / "Main building" (the 2011-era LIG-lodged + SAP-Schema-15.0 wording) → MAIN; "Extension N" → EXTENSION_N (for N in 1..4). `None` (permitted by the 21_0_1 schema), a non-string identifier (some SAP-16.x certs lodge a bare int), and anything else unrecognised fall to OTHER. """ - if api_identifier == "Main Dwelling": + if api_identifier in ("Main Dwelling", "Main building"): return cls.MAIN if isinstance(api_identifier, str): match = _API_EXTENSION.match(api_identifier) diff --git a/tests/datatypes/epc/domain/test_building_part_identifier.py b/tests/datatypes/epc/domain/test_building_part_identifier.py index d792f45a0..e3a725694 100644 --- a/tests/datatypes/epc/domain/test_building_part_identifier.py +++ b/tests/datatypes/epc/domain/test_building_part_identifier.py @@ -9,6 +9,17 @@ def test_main_dwelling_maps_to_main() -> None: ) +def test_main_building_maps_to_main() -> None: + # SAP-Schema-15.0 (2011-era LIG-lodged) certs use "Main building" instead + # of "Main Dwelling" for the main dwelling's building-part identifier. + # Previously this fell to OTHER, leaving the property with no MAIN part + # and crashing every recommendation generator that assumes one exists + # (e.g. `next(...)` with no default in wall_recommendation.py). + assert BuildingPartIdentifier.from_api_string("Main building") == ( + BuildingPartIdentifier.MAIN + ) + + def test_extension_string_maps_to_numbered_extension() -> None: assert BuildingPartIdentifier.from_api_string("Extension 2") == ( BuildingPartIdentifier.EXTENSION_2