diff --git a/include/JkBmsDataPoints.h b/include/JkBmsDataPoints.h index db7cd37ab..bf3a0f9bd 100644 --- a/include/JkBmsDataPoints.h +++ b/include/JkBmsDataPoints.h @@ -185,6 +185,10 @@ class DataPoint { std::string const& getUnitText() const { return _strUnit; } uint32_t getTimestamp() const { return _timestamp; } + bool operator==(DataPoint const& other) const { + return _value == other._value; + } + private: std::string _strLabel; std::string _strValue; diff --git a/src/JkBmsDataPoints.cpp b/src/JkBmsDataPoints.cpp index 471b9daf1..c9377ee06 100644 --- a/src/JkBmsDataPoints.cpp +++ b/src/JkBmsDataPoints.cpp @@ -48,7 +48,14 @@ std::string dataPointValueToStr(tCells const& v) { void DataPointContainer::updateFrom(DataPointContainer const& source) { for (auto iter = source.cbegin(); iter != source.cend(); ++iter) { - _dataPoints.erase(iter->first); + auto pos = _dataPoints.find(iter->first); + + if (pos != _dataPoints.end()) { + // do not update existing data points with the same value + if (pos->second == iter->second) { continue; } + + _dataPoints.erase(pos); + } _dataPoints.insert(*iter); } }