From 314e38a2023b3afa0d95a79790e515abac289e50 Mon Sep 17 00:00:00 2001 From: Bernhard Kirchen Date: Wed, 13 Sep 2023 20:48:38 +0200 Subject: [PATCH] JK BMS: fix SoC last update timestamp for the MQTT integration, JkBms::DataPointContainer::updateFrom() was changed such that the data points timestamp reflects the last change of the data point value. that timestamp was used to set the SoC last update timestamp. however, that timestampt must reflect the last time the SoC was successfully received from the JK BMS so we could make sure the value was up to date. --- src/BatteryStats.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/BatteryStats.cpp b/src/BatteryStats.cpp index fb1d2f2de..81939e7f7 100644 --- a/src/BatteryStats.cpp +++ b/src/BatteryStats.cpp @@ -180,12 +180,10 @@ void JkBmsBatteryStats::mqttPublish() const void JkBmsBatteryStats::updateFrom(JkBms::DataPointContainer const& dp) { - _dataPoints.updateFrom(dp); - using Label = JkBms::DataPointLabel; _manufacturer = "JKBMS"; - auto oProductId = _dataPoints.get(); + auto oProductId = dp.get(); if (oProductId.has_value()) { _manufacturer = oProductId->c_str(); auto pos = oProductId->rfind("JK"); @@ -194,12 +192,14 @@ void JkBmsBatteryStats::updateFrom(JkBms::DataPointContainer const& dp) } } - auto oSoCValue = _dataPoints.get(); + auto oSoCValue = dp.get(); if (oSoCValue.has_value()) { _SoC = *oSoCValue; - auto oSoCDataPoint = _dataPoints.getDataPointFor(); + auto oSoCDataPoint = dp.getDataPointFor(); _lastUpdateSoC = oSoCDataPoint->getTimestamp(); } + _dataPoints.updateFrom(dp); + _lastUpdate = millis(); }