diff --git a/include/Configuration.h b/include/Configuration.h index 4ae77a55f..8ae3826a3 100644 --- a/include/Configuration.h +++ b/include/Configuration.h @@ -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; diff --git a/src/Configuration.cpp b/src/Configuration.cpp index 5181ebe4c..de4efa34b 100644 --- a/src/Configuration.cpp +++ b/src/Configuration.cpp @@ -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; diff --git a/src/WebApi_inverter.cpp b/src/WebApi_inverter.cpp index 68983ab9c..5f5e41016 100644 --- a/src/WebApi_inverter.cpp +++ b/src/WebApi_inverter.cpp @@ -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!");