diff --git a/datatypes/epc/domain/mapper.py b/datatypes/epc/domain/mapper.py index 2a61bebb..caf09b6f 100644 --- a/datatypes/epc/domain/mapper.py +++ b/datatypes/epc/domain/mapper.py @@ -2433,11 +2433,28 @@ _API_FLOOR_CONSTRUCTION_TO_STR: Dict[int, Optional[str]] = { # are observed on cert 001479; the wider RdSAP10 roof-construction # enum (1=Flat, 3=Pitched no-access, 5=Vaulted, etc.) is mapped as # best-effort against SAP10 nomenclature. -_API_ROOF_CONSTRUCTION_TO_STR: Dict[int, str] = { +# +# Codes 6 and 7 → None. This field is read ONLY for the sloping-ceiling +# inclined factor; the base roof U-value comes from the global +# roofs[].description, so a non-sloping code carries no information the +# cascade consumes here, and None correctly avoids the cos(30°) false- +# trigger: +# 6 = "Thatched, with additional insulation" — its U is set by the +# global description; not a sloping ceiling. +# 7 = "(same dwelling above)" / "(another dwelling above)" — an +# internal ceiling with no roof heat loss (the roof-side analogue +# of floor_construction code 0). Heat loss is governed by the +# roof_heat_loss / description path, not this field. +# Empirically inert: roof W/K is identical whether 6/7 map to None or to +# an explicit pitched string across all code-6/7 certs in the 2026 +# sample (were raising UnmappedApiCode, blocking the cert). +_API_ROOF_CONSTRUCTION_TO_STR: Dict[int, Optional[str]] = { 1: "Flat", 3: "Pitched (slates/tiles), no access to loft", 4: "Pitched (slates/tiles), access to loft", 5: "Pitched (vaulted ceiling)", + 6: None, + 7: None, 8: "Pitched, sloping ceiling", } diff --git a/datatypes/epc/domain/tests/test_from_rdsap_schema.py b/datatypes/epc/domain/tests/test_from_rdsap_schema.py index b0711d9f..5a4796a5 100644 --- a/datatypes/epc/domain/tests/test_from_rdsap_schema.py +++ b/datatypes/epc/domain/tests/test_from_rdsap_schema.py @@ -879,3 +879,49 @@ class TestDefaultMissingPostTown: # Assert assert result["post_town"] == "BARNSTAPLE" + + +class TestApiRoofConstructionCode: + """`_api_roof_construction_str` maps the GOV.UK API integer + roof_construction code to the string the cascade reads ONLY for the + "sloping ceiling" cos(30°) inclined-surface factor (Slice 89). Codes + 6 and 7 are neither sloping ceilings nor base-U drivers (the roof + U-value comes from the global roofs[].description), so both map to + None: code 6 = "Thatched" (its U is set by the description, not this + field) and code 7 = "(same/another dwelling above)" — an internal + ceiling with no roof heat loss, the roof-side analogue of + floor_construction code 0. Empirically inert: roof W/K is identical + whether 6/7 map to None or to an explicit pitched string across all + code-6/7 certs in the 2026 sample.""" + + def test_code_7_same_dwelling_above_maps_to_none(self) -> None: + # Arrange + from datatypes.epc.domain.mapper import _api_roof_construction_str # pyright: ignore[reportPrivateUsage] + + # Act + result = _api_roof_construction_str(7) + + # Assert — None: no sloping-ceiling signal (avoids the cos(30°) + # false-trigger); the internal ceiling has no roof heat loss. + assert result is None + + def test_code_6_thatched_maps_to_none(self) -> None: + # Arrange + from datatypes.epc.domain.mapper import _api_roof_construction_str # pyright: ignore[reportPrivateUsage] + + # Act + result = _api_roof_construction_str(6) + + # Assert — None: thatched is not a sloping ceiling; its U-value is + # carried by the global roof description, not roof_construction_type. + assert result is None + + def test_code_8_still_maps_to_sloping_ceiling(self) -> None: + # Arrange — regression guard: the sloping-ceiling code is unchanged. + from datatypes.epc.domain.mapper import _api_roof_construction_str # pyright: ignore[reportPrivateUsage] + + # Act + result = _api_roof_construction_str(8) + + # Assert + assert result == "Pitched, sloping ceiling"