Skip to content

Commit

Permalink
add option to hide issues section from battery live view, show live…
Browse files Browse the repository at this point in the history
… for mqtt battery
  • Loading branch information
AndreasBoehm committed Sep 10, 2024
1 parent e9435d7 commit 0fc6f37
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
16 changes: 11 additions & 5 deletions include/BatteryStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class BatteryStats {

virtual float getChargeCurrentLimitation() const { return FLT_MAX; };

virtual bool supportsAlarmsAndWarnings() const { return false; };

protected:
virtual void mqttPublish() const;

Expand Down Expand Up @@ -110,6 +112,7 @@ class PylontechBatteryStats : public BatteryStats {
void mqttPublish() const final;
bool getImmediateChargingRequest() const { return _chargeImmediately; } ;
float getChargeCurrentLimitation() const { return _chargeCurrentLimitation; } ;
bool supportsAlarmsAndWarnings() const final { return true; }

private:
void setLastUpdate(uint32_t ts) { _lastUpdate = ts; }
Expand Down Expand Up @@ -146,7 +149,8 @@ class PytesBatteryStats : public BatteryStats {
public:
void getLiveViewData(JsonVariant& root) const final;
void mqttPublish() const final;
float getChargeCurrentLimitation() const { return _chargeCurrentLimit; } ;
float getChargeCurrentLimitation() const { return _chargeCurrentLimit; };
bool supportsAlarmsAndWarnings() const final { return true; }

private:
void setLastUpdate(uint32_t ts) { _lastUpdate = ts; }
Expand Down Expand Up @@ -228,6 +232,8 @@ class JkBmsBatteryStats : public BatteryStats {

void updateFrom(JkBms::DataPointContainer const& dp);

bool supportsAlarmsAndWarnings() const final { return true; }

private:
void getJsonData(JsonVariant& root, bool verbose) const;

Expand All @@ -247,6 +253,7 @@ class VictronSmartShuntStats : public BatteryStats {
void mqttPublish() const final;

void updateFrom(VeDirectShuntController::data_t const& shuntData);
bool supportsAlarmsAndWarnings() const final { return true; }

private:
float _temperature;
Expand Down Expand Up @@ -276,8 +283,7 @@ class MqttBatteryStats : public BatteryStats {
// we do NOT publish the same data under a different topic.
void mqttPublish() const final { }

// we don't need a card in the liveview, since the SoC and
// voltage (if available) is already displayed at the top.
void getLiveViewData(JsonVariant& root) const final { }
// TODO(AndreasBoehm): we could show the discharge current limit if available
void getLiveViewData(JsonVariant& root) const final;

bool supportsAlarmsAndWarnings() const final { return false; }
};
23 changes: 20 additions & 3 deletions src/BatteryStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,30 @@ void BatteryStats::getLiveViewData(JsonVariant& root) const
}
root["data_age"] = getAgeSeconds();

addLiveViewValue(root, "SoC", _soc, "%", _socPrecision);
addLiveViewValue(root, "voltage", _voltage, "V", 2);
addLiveViewValue(root, "current", _current, "A", _currentPrecision);
if (isSoCValid()) {
addLiveViewValue(root, "SoC", _soc, "%", _socPrecision);
}

if (isVoltageValid()) {
addLiveViewValue(root, "voltage", _voltage, "V", 2);
}

if (isCurrentValid()) {
addLiveViewValue(root, "current", _current, "A", _currentPrecision);
}

if (isDischargeCurrentLimitValid()) {
addLiveViewValue(root, "dischargeCurrentLimitation", _dischargeCurrentLimit, "A", 1);
}

root["showIssues"] = supportsAlarmsAndWarnings();
}

void MqttBatteryStats::getLiveViewData(JsonVariant& root) const
{
if (isDischargeCurrentLimitValid()) {
BatteryStats::getLiveViewData(root);
}
}

void PylontechBatteryStats::getLiveViewData(JsonVariant& root) const
Expand Down
1 change: 1 addition & 0 deletions src/MqttBattery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
bool MqttBattery::init(bool verboseLogging)
{
_verboseLogging = verboseLogging;
_stats->setManufacturer("MQTT");

auto const& config = Configuration.get();

Expand Down
3 changes: 1 addition & 2 deletions webapp/src/components/BatteryView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
</div>

<div v-else-if="'values' in batteryData">
<!-- suppress the card for MQTT battery provider -->
<div class="row gy-3 mt-0">
<div class="tab-content col-sm-12 col-md-12" id="v-pills-tabContent">
<div class="card">
Expand Down Expand Up @@ -89,7 +88,7 @@
</div>
</div>
</div>
<div class="col order-1">
<div class="col order-1" v-show="batteryData.showIssues">
<div class="card">
<div :class="{ 'card-header': true, 'border-bottom-0': maxIssueValue === 0 }">
<div class="d-flex flex-row justify-content-between align-items-baseline">
Expand Down
1 change: 1 addition & 0 deletions webapp/src/types/BatteryDataStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ export interface Battery {
hwversion: string;
data_age: number;
values: BatteryData[];
showIssues: boolean;
issues: number[];
}

0 comments on commit 0fc6f37

Please sign in to comment.