Fix #76: Null Pointer exception when adding a inverter with unkonwn serial number
This commit is contained in:
parent
6d9d5a0747
commit
1456974616
@ -49,7 +49,7 @@ void HoymilesClass::loop()
|
||||
|
||||
std::shared_ptr<InverterAbstract> HoymilesClass::addInverter(const char* name, uint64_t serial)
|
||||
{
|
||||
std::shared_ptr<InverterAbstract> i;
|
||||
std::shared_ptr<InverterAbstract> i = nullptr;
|
||||
if (HM_4CH::isValidSerial(serial)) {
|
||||
i = std::make_shared<HM_4CH>(serial);
|
||||
} else if (HM_2CH::isValidSerial(serial)) {
|
||||
|
||||
@ -141,9 +141,11 @@ void WebApiInverterClass::onInverterAdd(AsyncWebServerRequest* request)
|
||||
|
||||
auto inv = Hoymiles.addInverter(inverter->Name, inverter->Serial);
|
||||
|
||||
if (inv != nullptr) {
|
||||
for (uint8_t c = 0; c < INV_MAX_CHAN_COUNT; c++) {
|
||||
inv->Statistics()->setChannelMaxPower(c, inverter->MaxChannelPower[c]);
|
||||
}
|
||||
}
|
||||
|
||||
MqttHassPublishing.forceUpdate();
|
||||
}
|
||||
@ -243,15 +245,19 @@ void WebApiInverterClass::onInverterEdit(AsyncWebServerRequest* request)
|
||||
|
||||
std::shared_ptr<InverterAbstract> inv = Hoymiles.getInverterByPos(root[F("id")].as<uint64_t>());
|
||||
|
||||
if (inv->serial() != inverter.Serial) {
|
||||
if (inv != nullptr && inv->serial() != inverter.Serial) {
|
||||
// Serial was changed
|
||||
Hoymiles.removeInverterByPos(root[F("id")].as<uint64_t>());
|
||||
inv = Hoymiles.addInverter(inverter.Name, inverter.Serial);
|
||||
} else if (inv == nullptr) {
|
||||
inv = Hoymiles.addInverter(inverter.Name, inverter.Serial);
|
||||
}
|
||||
|
||||
if (inv != nullptr) {
|
||||
for (uint8_t c = 0; c < INV_MAX_CHAN_COUNT; c++) {
|
||||
inv->Statistics()->setChannelMaxPower(c, inverter.MaxChannelPower[c]);
|
||||
}
|
||||
}
|
||||
|
||||
MqttHassPublishing.forceUpdate();
|
||||
}
|
||||
|
||||
@ -100,9 +100,11 @@ void setup()
|
||||
config.Inverter[i].Name,
|
||||
config.Inverter[i].Serial);
|
||||
|
||||
if (inv != nullptr) {
|
||||
for (uint8_t c = 0; c < INV_MAX_CHAN_COUNT; c++) {
|
||||
inv->Statistics()->setChannelMaxPower(c, config.Inverter[i].MaxChannelPower[c]);
|
||||
}
|
||||
}
|
||||
Serial.println(F(" done"));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user