mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
Merge pull request #1540 from Hestia-Homes/fix/sap15-main-building-identifier
Map SAP-Schema-15.0 "Main building" identifier to MAIN
This commit is contained in:
commit
59954db488
2 changed files with 14 additions and 2 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue