Business operations API: get_battery_soc/get_household_wattage/get_device_inventory

This commit is contained in:
kfj001 committed 2026-10-16 04:58:33 +00:00
1 parent 363c7cc6a2
commit b79adc5d54
7 files changed
+307 -112

No files matched your search

+11 -27
View File
@@ -119,33 +119,17 @@ def get_power(
sn=sn, host=host, socket_port=port,
key_radix=key_radix, timeout=timeout,
)
for name, call in (
("detail", client.query_detail_info),
("load", client.query_load_status),
("ems", client.query_ems_info),
):
try:
reply = call()
except (ConnectionError, socket.error, TimeoutError) as exc:
last_err = exc
log.debug("port %d %s failed: %s", port, name, exc)
break
except Exception as exc:
last_err = exc
log.debug("port %d %s error: %s", port, name, exc)
continue
result = extract_power(reply)
if result["value"] is None and name == "ems":
watts = ems_load_watts(reply)
if watts is not None:
result = {"value": watts, "source": "ems(loadCurr*V)",
"detail": _power_detail(
reply.get("dataArea", reply))}
result.update({"cmd": name, "port": port, "reply": reply})
if result["value"] is not None:
return result
last_err = ValueError(
f"reply on port {port} {name} has no power field")
try:
result = client.get_household_wattage()
except (ConnectionError, socket.error, TimeoutError) as exc:
last_err = exc
log.debug("port %d failed: %s", port, exc)
continue # port unreachable — try next port
if result["value"] is not None:
result.update({"port": port})
return result
last_err = ValueError(
f"no power field in replies via {host}:{port}")
raise ConnectionError(f"no power reply via {host}:{list(ports)}") from last_err