Skip to content

Commit 05bdc95

Browse files
committed
Fix InfluxDB v2 catch-all writes and clean up EG4 A5 BMS output formatting
1 parent e5a3ef9 commit 05bdc95

2 files changed

Lines changed: 10 additions & 24 deletions

File tree

‎collector/outputs.py‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -537,16 +537,13 @@ def _write_influxdb(self, decoded: dict) -> None:
537537
payload = "\n".join(lines)
538538
if self._influx_client:
539539
try:
540-
from influxdb_client import Point
541-
points = []
542-
for measurement, fields in measurements.items():
543-
point = Point(measurement)
544-
for field, val in fields.items():
545-
point = point.field(field, float(val))
546-
points.append(point)
547-
write_api = self._influx_client.write_api()
548-
write_api.write(bucket=self.cfg.influx_bucket, record=points)
549-
logger.info("Wrote %d InfluxDB v2 points", len(points))
540+
self._influx_client.write_api().write(
541+
bucket=self.cfg.influx_bucket,
542+
org=self.cfg.influx_org,
543+
record=payload,
544+
write_precision="ns",
545+
)
546+
logger.info("Wrote %d InfluxDB v2 lines", len(lines))
550547
except Exception:
551548
logger.exception("InfluxDB v2 write failed; falling back to line protocol")
552549
self._post_influx_v1(payload)

‎collector/rs485/eg4_a5_bms.py‎

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ def _parse_cells(self, payload: bytes) -> Optional[Dict[str, Any]]:
258258
result: Dict[str, Any] = {}
259259
result["cell_count"] = 16
260260
for i, mv in enumerate(cell_voltages, start=1):
261-
result[f"cell_{i}_voltage"] = mv * 0.001
262-
result["cell_min_voltage"] = min_v * 0.001
263-
result["cell_max_voltage"] = max_v * 0.001
261+
result[f"cell_{i}_voltage"] = round(mv * 0.001, 3)
262+
result["cell_min_voltage"] = round(min_v * 0.001, 3)
263+
result["cell_max_voltage"] = round(max_v * 0.001, 3)
264264
result["cell_avg_voltage"] = round(sum_v / 16.0 * 0.001, 3)
265265
result["cell_delta_voltage"] = round((max_v - min_v) * 0.001, 3)
266266
result["cell_min_index"] = float(min_idx)
@@ -298,15 +298,4 @@ def _build_result(self) -> Dict[str, Dict[str, Any]]:
298298
if key in self._latest:
299299
out[key] = {"value": float(self._latest[key]), "unit": "V"}
300300

301-
# Expose raw status/protection words as booleans for easy dashboards.
302-
if "status_word" in self._latest:
303-
word = int(self._latest["status_word"])
304-
out["charging"] = {"value": float(bool(word & 0x0001)), "unit": ""}
305-
out["discharging"] = {"value": float(bool(word & 0x0002)), "unit": ""}
306-
out["heating"] = {"value": float(bool(word & 0x8000)), "unit": ""}
307-
308-
if "protection_word" in self._latest:
309-
word = int(self._latest["protection_word"])
310-
out["protection_active"] = {"value": float(bool(word)), "unit": ""}
311-
312301
return out

0 commit comments

Comments
 (0)