|
41 | 41 | import aiohttp |
42 | 42 | from datetime import datetime |
43 | 43 | from component_base import ComponentBase |
| 44 | +from coordinator import inverter_record |
44 | 45 | from alphaess_const import ( |
45 | 46 | ALPHAESS_BASE_URL, |
46 | 47 | ALPHAESS_ENDPOINTS, |
@@ -865,6 +866,91 @@ async def automatic_config(self): |
865 | 866 |
|
866 | 867 | await self.apply_hybrid_verdict() |
867 | 868 |
|
| 869 | + def build_discovery(self): |
| 870 | + """ |
| 871 | + Describe the discovered AlphaESS systems for the discovery catalogue. |
| 872 | +
|
| 873 | + Reads only what get_device_list() already holds - self.device_list and self.device_detail - |
| 874 | + plus the EV-charger verdict _apply_live_payload() records, so this adds no API calls and |
| 875 | + cannot change what AlphaESS does. Reporting is independent of self.automatic: the catalogue |
| 876 | + records the hardware, and the report's own "automatic" flag says whether Predbat wired |
| 877 | + apps.yaml to it. |
| 878 | +
|
| 879 | + self.device_list holds serial strings (sysSn), and only systems that passed has_battery() |
| 880 | + at discovery: a battery-less system (the VT1000 family, cobat 0 or missing) is dropped in |
| 881 | + get_device_list() and never reaches device_detail. automatic_config() applies no further |
| 882 | + test - it registers every serial in device_list as "AlphaESSCloud" - so inverter_type is set |
| 883 | + on every record, mirroring automatic_config() as the source of truth. |
| 884 | +
|
| 885 | + Ratings are getEssList's own figures: poinv (kW) as inverter_w via inverter_limit(), popv |
| 886 | + (kW) as pv_w, cobat (kWh) as battery_kwh via battery_capacity(). cobat is one scalar per |
| 887 | + system, so there is no list of entries to mis-sum. A system reports "solar" only when popv |
| 888 | + says PV is attached. |
| 889 | +
|
| 890 | + Deliberately not reported: |
| 891 | + - emsStatus: a status that changes. refresh_discovery() compares whole reports, so a |
| 892 | + changing value would re-file the report every time it moved. |
| 893 | + - usCapacity and surplusCobat: they fit "current SoC" and "configured usable depth" equally |
| 894 | + well, which is why publish_data() never maps them to SoC; reporting either as a rating |
| 895 | + would assert a meaning nobody knows. |
| 896 | + - firmware: the AlphaESS Open API exposes none. |
| 897 | + - account_ids: the API has no station, plant or site identifier; every endpoint is keyed by |
| 898 | + sysSn alone. |
| 899 | + - an AC-coupled verdict: detect_ac_coupled() infers it from live telemetry and |
| 900 | + ALPHAESS_AC_COUPLED_MODELS ships empty on purpose, so there is no held fact to report. |
| 901 | +
|
| 902 | + An EV charger is reported as a flag only when _ev_present says True. That verdict comes from |
| 903 | + live telemetry alone, so a charger not yet seen reports nothing either way rather than a |
| 904 | + guess. No chargers record is invented for it: AlphaESS reports a charger's power, not its |
| 905 | + identity. |
| 906 | +
|
| 907 | + Returns None when no system has been discovered yet, which refresh_discovery() treats as |
| 908 | + "nothing to report, ask again next cycle". |
| 909 | + """ |
| 910 | + if not self.device_list: |
| 911 | + return None |
| 912 | + |
| 913 | + inverters = [] |
| 914 | + for sn in self.device_list: |
| 915 | + detail = self.device_detail.get(sn, {}) or {} |
| 916 | + pv_kw = self._as_float(detail.get("popv"), 0.0) |
| 917 | + |
| 918 | + functions = ["solar", "battery"] if pv_kw > 0 else ["battery"] |
| 919 | + |
| 920 | + info = {} |
| 921 | + if detail.get("minv"): |
| 922 | + info["model"] = str(detail["minv"]) |
| 923 | + if detail.get("mbat"): |
| 924 | + info["battery_model"] = str(detail["mbat"]) |
| 925 | + |
| 926 | + ratings = {} |
| 927 | + inverter_w = self.inverter_limit(sn) |
| 928 | + if inverter_w > 0: |
| 929 | + ratings["inverter_w"] = inverter_w |
| 930 | + if pv_kw > 0: |
| 931 | + ratings["pv_w"] = pv_kw * 1000.0 |
| 932 | + battery_kwh = self.battery_capacity(sn) |
| 933 | + if battery_kwh > 0: |
| 934 | + ratings["battery_kwh"] = battery_kwh |
| 935 | + |
| 936 | + flags = ["ev_charger"] if self._ev_present.get(sn) is True else [] |
| 937 | + |
| 938 | + inverters.append( |
| 939 | + inverter_record( |
| 940 | + "alphaess:{}".format(sn), |
| 941 | + inverter_type="AlphaESSCloud", |
| 942 | + composition="direct", |
| 943 | + functions=functions, |
| 944 | + capabilities=["schedule", "target_soc", "discharge_target", "charge_rate_power"], |
| 945 | + flags=flags, |
| 946 | + hardware_ids={"serial": sn}, |
| 947 | + info=info, |
| 948 | + ratings=ratings, |
| 949 | + ) |
| 950 | + ) |
| 951 | + |
| 952 | + return {"automatic": self.automatic, "inverters": inverters} |
| 953 | + |
868 | 954 | @staticmethod |
869 | 955 | def _empty_schedule(): |
870 | 956 | """Return a fresh, disabled schedule shape - the single source of truth for its defaults. |
@@ -2000,6 +2086,14 @@ async def run(self, seconds, first): |
2000 | 2086 |
|
2001 | 2087 | await self.publish_data() |
2002 | 2088 |
|
| 2089 | + # Filed right after this cycle's publish and BEFORE `if first and not live_ok:` below: |
| 2090 | + # that branch returns False to defer startup when the first telemetry poll fails, and |
| 2091 | + # automatic_config() follows it, so a report filed any later would never be filed on |
| 2092 | + # exactly the installs whose dump most needs to say what hardware was found. (AlphaESS's |
| 2093 | + # automatic_config() does not raise - the early return is the reason.) refresh_discovery() |
| 2094 | + # owns the compare/retry/guard loop and never raises. |
| 2095 | + self.refresh_discovery() |
| 2096 | + |
2003 | 2097 | if first and not live_ok: |
2004 | 2098 | # Startup has not really succeeded without telemetry: automatic_config() runs |
2005 | 2099 | # on the first cycle ALONE, so it would map only the args backed by cached |
|
0 commit comments