replace BatteryStats::isValid() method

in the respective context, the DPL only needs to be sure that the SoC
value is not outdated. it should not even care about other values
reported by the battery interface. hence, the isValid() method shall be
concerned with the SoC value timestamp only. the method is renamed for
clarity.
This commit is contained in:
Bernhard Kirchen 2024-02-17 12:44:51 +01:00
parent 3595725f8a
commit 7c069b1cc4
2 changed files with 5 additions and 4 deletions

View File

@ -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;

View File

@ -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