Fix change of inverter serial

Because of the inverter type depends on the serial number it's a must to remove and add the inverter of the serial was changed. setSerial doesn't make sense anymore. Move the serial to the constructor
This commit is contained in:
Thomas Basler 2022-06-22 21:32:37 +02:00
parent 746aa087ac
commit f42696d14c
10 changed files with 23 additions and 8 deletions

View File

@ -50,17 +50,16 @@ std::shared_ptr<InverterAbstract> HoymilesClass::addInverter(const char* name, u
{
std::shared_ptr<InverterAbstract> i;
if (HM_4CH::isValidSerial(serial)) {
i = std::make_shared<HM_4CH>();
i = std::make_shared<HM_4CH>(serial);
}
else if (HM_2CH::isValidSerial(serial)) {
i = std::make_shared<HM_2CH>();
i = std::make_shared<HM_2CH>(serial);
}
else if (HM_1CH::isValidSerial(serial)) {
i = std::make_shared<HM_1CH>();
i = std::make_shared<HM_1CH>(serial);
}
if (i) {
i->setSerial(serial);
i->setName(name);
_inverters.push_back(std::move(i));
return _inverters.back();

View File

@ -1,5 +1,8 @@
#include "HM_1CH.h"
HM_1CH::HM_1CH(uint64_t serial)
: InverterAbstract(serial) {};
bool HM_1CH::isValidSerial(uint64_t serial)
{
return serial >= 0x112100000000 && serial <= 0x112199999999;

View File

@ -4,6 +4,7 @@
class HM_1CH : public InverterAbstract {
public:
HM_1CH(uint64_t serial);
static bool isValidSerial(uint64_t serial);
String typeName();
const byteAssign_t* getByteAssignment();

View File

@ -1,5 +1,8 @@
#include "HM_2CH.h"
HM_2CH::HM_2CH(uint64_t serial)
: InverterAbstract(serial) {};
bool HM_2CH::isValidSerial(uint64_t serial)
{
return serial >= 0x114100000000 && serial <= 0x114199999999;

View File

@ -4,6 +4,7 @@
class HM_2CH : public InverterAbstract {
public:
HM_2CH(uint64_t serial);
static bool isValidSerial(uint64_t serial);
String typeName();
const byteAssign_t* getByteAssignment();

View File

@ -1,5 +1,8 @@
#include "HM_4CH.h"
HM_4CH::HM_4CH(uint64_t serial)
: InverterAbstract(serial) {};
bool HM_4CH::isValidSerial(uint64_t serial)
{
return serial >= 0x116100000000 && serial <= 0x116199999999;

View File

@ -4,6 +4,7 @@
class HM_4CH : public InverterAbstract {
public:
HM_4CH(uint64_t serial);
static bool isValidSerial(uint64_t serial);
String typeName();
const byteAssign_t* getByteAssignment();

View File

@ -2,7 +2,7 @@
#include "crc.h"
#include <cstring>
void InverterAbstract::setSerial(uint64_t serial)
InverterAbstract::InverterAbstract(uint64_t serial)
{
_serial.u64 = serial;
}

View File

@ -90,7 +90,7 @@ const calcFunc_t calcFunctions[] = {
class InverterAbstract {
public:
void setSerial(uint64_t serial);
InverterAbstract(uint64_t serial);
uint64_t serial();
void setName(const char* name);
const char* name();

View File

@ -212,8 +212,12 @@ void WebApiInverterClass::onInverterEdit(AsyncWebServerRequest* request)
request->send(response);
std::shared_ptr<InverterAbstract> inv = Hoymiles.getInverterByPos(root[F("id")].as<uint64_t>());
inv->setName(inverter.Name);
inv->setSerial(inverter.Serial);
if (inv->serial() != inverter.Serial) {
// Serial was changed
Hoymiles.removeInverterByPos(root[F("id")].as<uint64_t>());
inv = Hoymiles.addInverter(inverter.Name, inverter.Serial);
}
for (uint8_t c = 0; c < INV_MAX_CHAN_COUNT; c++) {
inv->setChannelMaxPower(c, inverter.MaxChannelPower[c]);