Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: allow management of DPL inverters while DPL is off #1525

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/PowerLimiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ class PowerLimiterClass {
std::pair<bool, uint32_t> _nextInverterRestart = { false, 0 };
bool _fullSolarPassThroughEnabled = false;
bool _verboseLogging = true;
bool _shutdownComplete = false;

frozen::string const& getStatusText(Status status);
void announceStatus(Status status);
bool shutdown(Status status);
bool isDisabled();
void reloadConfig();
std::pair<float, char const*> getInverterDcVoltage();
float getBatteryVoltage(bool log = false);
Expand Down
39 changes: 22 additions & 17 deletions src/PowerLimiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,31 @@ void PowerLimiterClass::announceStatus(PowerLimiterClass::Status status)
_lastStatusPrinted = millis();
}

/**
* returns true if the inverters' state was changed or is about to change, i.e.,
* if any are actually in need of a shutdown. returns false otherwise, i.e., the
* inverters are already shut down.
*/
bool PowerLimiterClass::shutdown(PowerLimiterClass::Status status)
bool PowerLimiterClass::isDisabled()
{
announceStatus(status);
auto const& config = Configuration.get();

if (!config.PowerLimiter.Enabled) {
announceStatus(Status::DisabledByConfig);
}
else if (Mode::Disabled == _mode) {
announceStatus(Status::DisabledByMqtt);
}
else {
_shutdownComplete = false;
return false;
}

// we only shut down governed inverters once when the DPL is disabled by
// configuration or by the MQTT mode setting. afterwards, we leave the
// inverter(s) alone so they can be managed through other means.
if (_shutdownComplete) { return true; }

for (auto& upInv : _inverters) { upInv->standby(); }

return updateInverters();
_shutdownComplete = !updateInverters();

return true;
}

void PowerLimiterClass::reloadConfig()
Expand Down Expand Up @@ -157,15 +170,7 @@ void PowerLimiterClass::loop()
return announceStatus(Status::InverterCmdPending);
}

if (!config.PowerLimiter.Enabled) {
shutdown(Status::DisabledByConfig);
return;
}

if (Mode::Disabled == _mode) {
shutdown(Status::DisabledByMqtt);
return;
}
if (isDisabled()) { return; }

if (_reloadConfigFlag) {
reloadConfig();
Expand Down
Loading