Skip to content

Commit

Permalink
replace BatteryStats::isValid() method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
schlimmchen committed Feb 18, 2024
1 parent 14389d9 commit 7394275
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/BatteryStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/PowerLimiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7394275

Please sign in to comment.