Skip to content

Commit

Permalink
Fix: Set all settings to default when deleting an inverters
Browse files Browse the repository at this point in the history
Previously some old settings from previous inverters could have been shown in a new inverter
  • Loading branch information
tbnobody committed Mar 13, 2024
1 parent 437f572 commit 33bf211
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class ConfigurationClass {

INVERTER_CONFIG_T* getFreeInverterSlot();
INVERTER_CONFIG_T* getInverterConfig(const uint64_t serial);
void deleteInverterById(const uint8_t id);
};

extern ConfigurationClass Configuration;
22 changes: 22 additions & 0 deletions src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,4 +406,26 @@ INVERTER_CONFIG_T* ConfigurationClass::getInverterConfig(const uint64_t serial)
return nullptr;
}

void ConfigurationClass::deleteInverterById(const uint8_t id)
{
config.Inverter[id].Serial = 0ULL;
strlcpy(config.Inverter[id].Name, "", sizeof(config.Inverter[id].Name));
config.Inverter[id].Order = 0;

config.Inverter[id].Poll_Enable = true;
config.Inverter[id].Poll_Enable_Night = true;
config.Inverter[id].Command_Enable = true;
config.Inverter[id].Command_Enable_Night = true;
config.Inverter[id].ReachableThreshold = REACHABLE_THRESHOLD;
config.Inverter[id].ZeroRuntimeDataIfUnrechable = false;
config.Inverter[id].ZeroYieldDayOnMidnight = false;
config.Inverter[id].YieldDayCorrection = false;

for (uint8_t c = 0; c < INV_MAX_CHAN_COUNT; c++) {
config.Inverter[id].channel[c].MaxChannelPower = 0;
config.Inverter[id].channel[c].YieldTotalOffset = 0.0f;
strlcpy(config.Inverter[id].channel[c].Name, "", sizeof(config.Inverter[id].channel[c].Name));
}
}

ConfigurationClass Configuration;
3 changes: 1 addition & 2 deletions src/WebApi_inverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,7 @@ void WebApiInverterClass::onInverterDelete(AsyncWebServerRequest* request)

Hoymiles.removeInverterBySerial(inverter.Serial);

inverter.Serial = 0;
strncpy(inverter.Name, "", sizeof(inverter.Name));
Configuration.deleteInverterById(inverter_id);

WebApi.writeConfig(retMsg, WebApiError::InverterDeleted, "Inverter deleted!");

Expand Down

0 comments on commit 33bf211

Please sign in to comment.