From a764b5fa9cb9d781c710252e888d20aeb22fd61d Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Mon, 29 Jun 2026 18:45:27 +0000 Subject: [PATCH] =?UTF-8?q?Translate=20full-SAP=20electricity=20tariff=20i?= =?UTF-8?q?nto=20the=20RdSAP=20meter=20type=20=F0=9F=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- datatypes/epc/domain/mapper.py | 14 +++++++++++++ .../epc/domain/tests/test_from_sap_schema.py | 20 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/datatypes/epc/domain/mapper.py b/datatypes/epc/domain/mapper.py index e0758e3d..ec3b38fc 100644 --- a/datatypes/epc/domain/mapper.py +++ b/datatypes/epc/domain/mapper.py @@ -2932,6 +2932,20 @@ def _sap_dwelling_on_mains_gas(schema: SapSchema17_1) -> bool: ) +def _sap_17_1_meter_type(electricity_tariff: Optional[int]) -> str: + """Translate a full-SAP ``energy_tariff`` code into the RdSAP ``meter_type`` + value the calculator's Table 12a tariff resolver consumes. + + The two code spaces *differ* (epc_codes.csv `energy_tariff` vs + `_METER_INT_TO_TARIFF`): full-SAP 1=standard / 2=off-peak-7hr / 3=off-peak- + 10hr / 4=24-hour, whereas RdSAP meter 1=dual-7hr / 2=single / 3=unknown / + 4=24-hour. Passing the full-SAP code straight through (the prior bug) read a + standard-tariff cert as Economy 7 (over-rated) and an Economy-7 cert as + single (under-rated). Map onto the RdSAP word aliases so the resolved tariff + is correct; absent/ND → "" (the unknown→standard sentinel).""" + raise NotImplementedError(electricity_tariff) + + def _sap_17_1_heating(schema: SapSchema17_1) -> SapHeating: """D6: map full-SAP `sap_heating` onto the domain `SapHeating`. Field names differ from RdSAP — `is_flue_fan_present`→`fan_flue_present`, diff --git a/datatypes/epc/domain/tests/test_from_sap_schema.py b/datatypes/epc/domain/tests/test_from_sap_schema.py index 08bff90a..32656e95 100644 --- a/datatypes/epc/domain/tests/test_from_sap_schema.py +++ b/datatypes/epc/domain/tests/test_from_sap_schema.py @@ -137,6 +137,26 @@ class TestFromSapSchema17_1RebaselineFields: assert result.assessment_type == "SAP" +class TestFullSapElectricityTariffTranslation: + """The full-SAP `energy_tariff` code space differs from the RdSAP + `meter_type` one the calculator reads, so the mapper must translate it.""" + + def test_economy7_tariff_is_not_read_as_single_rate(self) -> None: + # full-SAP energy_tariff 2 = "off-peak 7 hour" (Economy 7). Passing the + # code straight through read it as RdSAP meter 2 = Single → no off-peak + # split (under-rated). It must resolve to the SEVEN_HOUR off-peak tariff. + from domain.sap10_calculator.tables.table_12a import ( + Tariff, + tariff_from_meter_type, + ) + + from datatypes.epc.domain.mapper import _sap_17_1_meter_type + + meter_type = _sap_17_1_meter_type(2) + + assert tariff_from_meter_type(meter_type) is Tariff.SEVEN_HOUR + + class TestFromSapSchema17_1DisplayElements: """Display EnergyElements the WIP mapper dropped, leaving the FE property-details panel "Unknown" for full-SAP certs (ADR-0037). Brings