Translate full-SAP electricity tariff into the RdSAP meter type 🟥

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Khalim Conn-Kowlessar 2026-06-29 18:45:27 +00:00
parent 4e96ea91a5
commit a764b5fa9c
2 changed files with 34 additions and 0 deletions

View file

@ -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 unknownstandard 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`,

View file

@ -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