From 6333c36a298b4bb156bfc1c56d97fb5995e565e1 Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Wed, 15 Apr 2026 14:59:43 +0000 Subject: [PATCH] =?UTF-8?q?insulation=20location=20can=20be=20string=20?= =?UTF-8?q?=F0=9F=9F=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ecmk_fetcher/tests/test_xml_processor.py | 50 +++++++++++++++++++ backend/ecmk_fetcher/xml_processor.py | 11 ++-- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/backend/ecmk_fetcher/tests/test_xml_processor.py b/backend/ecmk_fetcher/tests/test_xml_processor.py index 3fd9e45e..3695b09d 100644 --- a/backend/ecmk_fetcher/tests/test_xml_processor.py +++ b/backend/ecmk_fetcher/tests/test_xml_processor.py @@ -207,6 +207,41 @@ ND_THICKNESS_XML = """ + + +
+ 1 + Somewhere + AB1 2CD +
+
+
+ + + 0 + + + Main Dwelling + 4 + ND + 250 + + + 10.0 + 2.5 + 50.0 + 0 + 0 + + + + + + +
+""" + def test_parse_rdsap_nd_thickness(): # 'ND' (not determined) is a valid value in the wild for Roof-Insulation-Thickness @@ -223,6 +258,21 @@ def test_parse_rdsap_nd_thickness(): } +def test_parse_rdsap_nd_location(): + # 'ND' (not determined) is a valid value in the wild for Roof-Insulation-Location + # — it should be retained as-is rather than raising + + # arrange + act + result: SapPropertyDetails = parse_rdsap(ND_INSULATION_LOCATION_XML) + + # assert + assert result["building_parts"][0]["roof"] == { + "construction": 4, + "insulation_location": "ND", + "insulation_thickness_mm": 250, + } + + def test_flatten_full(): # Two building parts; Main Dwelling has two floors + full roof, # Extension has one floor + partial roof (no thickness) diff --git a/backend/ecmk_fetcher/xml_processor.py b/backend/ecmk_fetcher/xml_processor.py index aff284ef..f993038b 100644 --- a/backend/ecmk_fetcher/xml_processor.py +++ b/backend/ecmk_fetcher/xml_processor.py @@ -16,7 +16,7 @@ class Floor(TypedDict): class Roof(TypedDict, total=False): construction: int # TODO: map to str - insulation_location: int # TODO: map to str + insulation_location: int | str # TODO: map to str insulation_thickness_mm: float | str @@ -158,9 +158,12 @@ def parse_rdsap(xml_string: str) -> SapPropertyDetails: ) if roof_ins_loc_text is not None: - roof_dict["insulation_location"] = _parse_int( - roof_ins_loc_text, "Roof-Insulation-Location" - ) + try: + roof_dict["insulation_location"] = _parse_int( + roof_ins_loc_text, "Roof-Insulation-Location" + ) + except ValueError: + roof_dict["insulation_location"] = roof_ins_loc_text thickness = _parse_thickness_mm(roof_thickness_text) if thickness is not None: