diff --git a/include/BatteryStats.h b/include/BatteryStats.h index 12d6330d2..287f0d1b1 100644 --- a/include/BatteryStats.h +++ b/include/BatteryStats.h @@ -32,7 +32,7 @@ class BatteryStats { // if they did not change. used to calculate Home Assistent expiration. virtual uint32_t getMqttFullPublishIntervalMs() const; - bool isValid() const { return _lastUpdateSoC > 0 && _lastUpdate > 0; } + bool isSoCValid() const { return _lastUpdateSoC > 0; } protected: virtual void mqttPublish() const; diff --git a/src/PowerLimiter.cpp b/src/PowerLimiter.cpp index 56dc11e4b..68564e37a 100644 --- a/src/PowerLimiter.cpp +++ b/src/PowerLimiter.cpp @@ -610,12 +610,13 @@ bool PowerLimiterClass::testThreshold(float socThreshold, float voltThreshold, CONFIG_T& config = Configuration.get(); // prefer SoC provided through battery interface, unless disabled by user + auto stats = Battery.getStats(); if (!config.PowerLimiter.IgnoreSoc && config.Battery.Enabled && socThreshold > 0.0 - && Battery.getStats()->isValid() - && Battery.getStats()->getSoCAgeSeconds() < 60) { - return compare(Battery.getStats()->getSoC(), socThreshold); + && stats->isSoCValid() + && stats->getSoCAgeSeconds() < 60) { + return compare(stats->getSoC(), socThreshold); } // use voltage threshold as fallback