fix(16d): predicted_lighting_kwh handles None bulb counts

EPC bulb-count fields are Optional[int]; 1k-cert sanity-check from slice 16h
hit None + None TypeError. Coerce to 0 before sum.
This commit is contained in:
Khalim Conn-Kowlessar 2026-05-17 12:25:59 +00:00
parent 700ff4640c
commit e8b6f19a3a

View file

@ -120,19 +120,23 @@ def predicted_hot_water_kwh(
def predicted_lighting_kwh(
total_floor_area_m2: Optional[float],
cfl_count: int,
led_count: int,
incandescent_count: int,
cfl_count: Optional[int],
led_count: Optional[int],
incandescent_count: Optional[int],
) -> float:
"""Annual lighting kWh (SAP10.2 Section L simplified).
Base demand ~ 9.3 * TFA kWh/yr; reduced by low-energy bulb share. LED
bulbs cut consumption by ~50%, CFL by ~40%, incandescent by 0%.
Missing counts treated as zero.
"""
if total_floor_area_m2 is None or total_floor_area_m2 <= 0:
return 0.0
total_bulbs = max(1, cfl_count + led_count + incandescent_count)
led_share = led_count / total_bulbs
cfl_share = cfl_count / total_bulbs
cfl = cfl_count or 0
led = led_count or 0
inc = incandescent_count or 0
total_bulbs = max(1, cfl + led + inc)
led_share = led / total_bulbs
cfl_share = cfl / total_bulbs
reduction = 0.5 * led_share + 0.4 * cfl_share
return 9.3 * total_floor_area_m2 * (1.0 - reduction)