"""Elmhurst build for UPRN 100021924710 (RdSAP-21.0.1, MID-TERRACE HOUSE, band B, SOLID BRICK 250 mm uninsulated, pitched insulated (assumed) loft, floor to UNHEATED space, mains-gas COMBI (PCDB 19008) + gas room-heater SECONDARY, DUAL meter, 11 DG windows ~18.32 m², TFA 116. Lodged SAP 63; engine 65.0 (Δ +2.0). Per-cert Elmhurst validation. Uses set_single_window (deletes the shared assessment's carried-over window rows) + reset_transient_state at the end so the assessment is left neutral. Run: DISPLAY=:99 python scripts/hyde/build_100021924710.py """ from __future__ import annotations import sys from pathlib import Path import elmhurst_lib as E DIM = "TabContainer_TabPanelMain_WebUserControlDimensionsMain_" WALL = ("TabContainer_TabPanelMain_InnerTabContainerMain_" "TabPanelExternalWallMain_WebUserControlWallMain_") PWALL = ("TabContainer_TabPanelMain_InnerTabContainerMain_" "TabPanelPartyWallMain_WebUserControlPartyWallMain_") ROOF = "TabContainer_TabPanelMain_WebUserControlRoofMain_" FLOOR = "TabContainer_TabPanelMain_WebUserControlFloorsMain_" DP = "TabContainer_TabPanelDoorsPanel_" VP = "TabContainer_TabPanelVentilationPanel_" APT = "TabContainer_TabPanelAirPressureTest_" LP = "TabContainer_TabPanelLighting_" MV = "TabContainer_TabPanelMechVent_" WH = "TabContainer_TabPanelWaterHeating_" MH1B = "TabContainer_TabPanelMainHeating1_WebUserControlMainHeating1_" _SAMPLE_DIR = (Path(__file__).parent.parent.parent / "backend/epc_api/json_samples/real_life_examples" / "RdSAP-Schema-21.0.1/uprn_100021924710") def _pick(page, suffix, contains): val = page.evaluate( """(a)=>{const s=document.getElementById(a[0]);if(!s)return null; for(const o of s.options){if(o.text.toLowerCase().includes(a[1].toLowerCase()))return o.value;}return null;}""", [f"{E.FP}{suffix}", contains]) if val is not None: E.set_select(page, suffix, val) return val def property_description(page): E.goto(page, "PropertyDescription", "WebFormPropertyDescription.aspx") E.set_select(page, "DropDownListPropertyType1", "H House") _pick(page, "DropDownListPropertyType2", "mid-terrace") or \ _pick(page, "DropDownListPropertyType2", "mid terrace") E.set_text(page, "TextBoxStoreys", "2") E.set_text(page, "TextBoxHabitableRooms", "5") E.set_text(page, "TextBoxHeatedHabitableRooms", "5") print("date ->", _pick(page, "DropDownListDateBuiltMain", "1900-1929")) E.set_select(page, "DropDownListDateBuiltFirst", "") E.set_select(page, "DropDownListRoomInRoofMain", "") E.save_close(page) def dimensions(page): E.goto(page, "Dimensions", "WebFormDimensions.aspx") E.set_text(page, f"{DIM}TextBoxFloorAreaLowestFloor", "59.20") E.set_text(page, f"{DIM}TextBoxRoomHeightLowestFloor", "2.74") E.set_text(page, f"{DIM}TextBoxWallPerimeterLowestFloor", "16.0") E.set_text(page, f"{DIM}TextBoxPartyWallLengthLowestFloor", "21.1") E.set_text(page, f"{DIM}TextBoxFloorArea1stFloor", "57.10") E.set_text(page, f"{DIM}TextBoxRoomHeight1stFloor", "2.74") E.set_text(page, f"{DIM}TextBoxWallPerimeter1stFloor", "15.7") E.set_text(page, f"{DIM}TextBoxPartyWallLength1stFloor", "21.7") E.save_close(page) def walls(page): E.goto(page, "Walls", "WebFormWalls.aspx") _pick(page, f"{WALL}DropDownListType", "solid brick") page.wait_for_timeout(500) print("insulation ->", _pick(page, f"{WALL}DropDownListInsulation", "as built")) print("party ->", _pick(page, f"{PWALL}DropDownListPartyWallType", "determine") or _pick(page, f"{PWALL}DropDownListPartyWallType", "masonry")) E.save_close(page) def roofs(page): E.goto(page, "Roofs", "WebFormRoofs.aspx") _pick(page, f"{ROOF}DropDownListType", "access to loft") or \ _pick(page, f"{ROOF}DropDownListType", "loft") _pick(page, f"{ROOF}DropDownListInsulationAt", "joists") _pick(page, f"{ROOF}DropDownListThickness", "unknown") or \ _pick(page, f"{ROOF}DropDownListThickness", "assumed") E.save_close(page) def floors(page): E.goto(page, "Floors", "WebFormFloors.aspx") _pick(page, f"{FLOOR}DropDownListLocation", "unheated") page.wait_for_timeout(400) _pick(page, f"{FLOOR}DropDownListType", "solid") ins = page.locator(f"#{E.FP}{FLOOR}DropDownListInsulation") if ins.count(): E.set_select(page, f"{FLOOR}DropDownListInsulation", "A As built") E.save_close(page) def openings(page): E.goto(page, "Openings", "WebFormOpenings.aspx") E.click_tab(page, "TabContainer_TabPanelWindowsPanel") page.wait_for_timeout(500) E.set_single_window(page, 18.32, "North", _glazing(page) if False else "Double post or during 2022") E.click_tab(page, "TabContainer_TabPanelDoorsPanel") E.set_text(page, f"{DP}TextBoxDoors", "1") E.set_text(page, f"{DP}TextBoxDoorsInsulated", "0") E.set_text(page, f"{DP}TextBoxDraughtProofedDoors", "0") E.save_close(page) def _glazing(page): return "Double with unknown install date" def ventilation(page): E.goto(page, "VentilationAndCooling", "WebFormVentilationAndCooling.aspx") E.click_tab(page, "TabContainer_TabPanelVentilationPanel") E.set_text(page, f"{VP}TextBoxIntermittentFans", "1") cool = page.locator(f"#{E.FP}{VP}CheckBoxFixedSpaceCooling") if cool.count() and cool.is_checked(): E.commit(page, cool.uncheck) E.click_tab(page, "TabContainer_TabPanelMechVent") mv = page.locator(f"#{E.FP}{MV}CheckBoxMechanicalVentilation") if mv.count() and mv.is_checked(): E.commit(page, mv.uncheck) E.click_tab(page, "TabContainer_TabPanelAirPressureTest") E.set_select(page, f"{APT}DropDownListTestMethod", "Not available") E.click_tab(page, "TabContainer_TabPanelLighting") E.set_text(page, f"{LP}TextBoxLightsTotal", "8") E.set_text(page, f"{LP}TextBoxLedLightsTotal", "0") E.set_text(page, f"{LP}TextBoxCflLightsTotal", "0") E.save_close(page) def space_heating(page): E.goto(page, "SpaceHeating", "WebFormSpaceHeating.aspx") page.wait_for_timeout(1000) mhc = page.locator(f"#{E.MH1}TextBoxMainHeatingCode") code = mhc.input_value() if mhc.count() else "" if code and code not in ("0",): print(f"clearing leftover MainHeatingCode {code}") page.evaluate("""(id)=>{const e=document.getElementById(id);if(e){e.value=''; e.dispatchEvent(new Event('change',{bubbles:true}));}}""", f"{E.MH1}TextBoxMainHeatingCode") page.wait_for_timeout(400) E.save_close(page) return E.set_heating_dialog(page, f"{MH1B}ButtonMainHeatingCode", "^Gas", "Mains gas", "Boilers", "Post 1998", "Condensing", "Combi condens") print("code:", page.locator(f"#{E.MH1}TextBoxMainHeatingCode").input_value()) E.set_heating_dialog(page, f"{MH1B}ButtonMainHeatingControls", "^Boilers", "^Standard", "CBE Programmer, room thermostat and TRVs") print("control:", page.locator(f"#{E.MH1}TextBoxMainHeatingControls").input_value()) # dual meter (cert meter_type 1) E.click_tab(page, "TabContainer_TabPanelMeters") try: E.set_select(page, "TabContainer_TabPanelMeters_RadioButtonListElectricityType", "Dual") except Exception: pass E.save_close(page) def secondary(page): E.goto(page, "SpaceHeating", "WebFormSpaceHeating.aspx") page.wait_for_timeout(600) E.set_select(page, "DropDownListSecondaryHeatingPresent", "Yes") page.wait_for_timeout(900) E.set_heating_dialog(page, "ButtonSecondaryHeatingCode", "^Gas", "Mains gas", "Room Heater") tb = page.locator(f"#{E.FP}TextBoxSecondaryHeatingCode") print("secondary code:", tb.input_value() if tb.count() else "?") E.save_close(page) def water_heating(page): E.goto(page, "WaterHeating", "WebFormWaterHeating.aspx") E.click_tab(page, "TabContainer_TabPanelWaterHeating") page.wait_for_timeout(400) E.clear_hot_water_cylinder(page) E.set_heating_dialog(page, f"{WH}ButtonWaterHeatingCode", "From Space Heating", "From the primary heating system") print("water code:", page.locator(f"#{E.FP}{WH}TextBoxWaterHeatingCode").input_value()) E.save_close(page) def download(page): _SAMPLE_DIR.mkdir(parents=True, exist_ok=True) E.goto(page, "Recommendations", "WebFormRecommendations.aspx") page.wait_for_timeout(1500) with page.expect_navigation(wait_until="networkidle", timeout=40000): page.click("#ContentBody_buttonActionSummary_Link", timeout=15000) page.wait_for_timeout(2000) for btn, fname in (("ContentBody_ContentPlaceHolder1_LinkButtonSummary", "elmhurst_summary.pdf"), ("ContentBody_ContentPlaceHolder1_ButtonDebugInforPdf", "elmhurst_worksheet.pdf")): try: with page.expect_download(timeout=60000) as dl: page.click(f"#{btn}", timeout=15000) dl.value.save_as(str(_SAMPLE_DIR / fname)) print("saved", fname) except Exception as e: print("!! download failed", fname, type(e).__name__, str(e)[:120]) def cleanup(page): """Leave the shared assessment neutral for the next build.""" E.reset_transient_state(page) print("reset transient state (RR/secondary/meter)") _ORDER = ["property_description", "dimensions", "walls", "roofs", "floors", "openings", "ventilation", "space_heating", "secondary", "water_heating", "download", "cleanup"] def main(): if len(sys.argv) < 2 or sys.argv[1] not in _ORDER: print("usage: build_100021924710.py <" + "|".join(_ORDER) + ">") return 2 with E.session() as (ctx, page): globals()[sys.argv[1]](page) print("done:", sys.argv[1], "->", page.url) return 0 if __name__ == "__main__": raise SystemExit(main())