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:
parent
746aa087ac
commit
f42696d14c
@ -50,17 +50,16 @@ std::shared_ptr<InverterAbstract> HoymilesClass::addInverter(const char* name, u
|
|||||||
{
|
{
|
||||||
std::shared_ptr<InverterAbstract> i;
|
std::shared_ptr<InverterAbstract> i;
|
||||||
if (HM_4CH::isValidSerial(serial)) {
|
if (HM_4CH::isValidSerial(serial)) {
|
||||||
i = std::make_shared<HM_4CH>();
|
i = std::make_shared<HM_4CH>(serial);
|
||||||
}
|
}
|
||||||
else if (HM_2CH::isValidSerial(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)) {
|
else if (HM_1CH::isValidSerial(serial)) {
|
||||||
i = std::make_shared<HM_1CH>();
|
i = std::make_shared<HM_1CH>(serial);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i) {
|
if (i) {
|
||||||
i->setSerial(serial);
|
|
||||||
i->setName(name);
|
i->setName(name);
|
||||||
_inverters.push_back(std::move(i));
|
_inverters.push_back(std::move(i));
|
||||||
return _inverters.back();
|
return _inverters.back();
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
#include "HM_1CH.h"
|
#include "HM_1CH.h"
|
||||||
|
|
||||||
|
HM_1CH::HM_1CH(uint64_t serial)
|
||||||
|
: InverterAbstract(serial) {};
|
||||||
|
|
||||||
bool HM_1CH::isValidSerial(uint64_t serial)
|
bool HM_1CH::isValidSerial(uint64_t serial)
|
||||||
{
|
{
|
||||||
return serial >= 0x112100000000 && serial <= 0x112199999999;
|
return serial >= 0x112100000000 && serial <= 0x112199999999;
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
class HM_1CH : public InverterAbstract {
|
class HM_1CH : public InverterAbstract {
|
||||||
public:
|
public:
|
||||||
|
HM_1CH(uint64_t serial);
|
||||||
static bool isValidSerial(uint64_t serial);
|
static bool isValidSerial(uint64_t serial);
|
||||||
String typeName();
|
String typeName();
|
||||||
const byteAssign_t* getByteAssignment();
|
const byteAssign_t* getByteAssignment();
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
#include "HM_2CH.h"
|
#include "HM_2CH.h"
|
||||||
|
|
||||||
|
HM_2CH::HM_2CH(uint64_t serial)
|
||||||
|
: InverterAbstract(serial) {};
|
||||||
|
|
||||||
bool HM_2CH::isValidSerial(uint64_t serial)
|
bool HM_2CH::isValidSerial(uint64_t serial)
|
||||||
{
|
{
|
||||||
return serial >= 0x114100000000 && serial <= 0x114199999999;
|
return serial >= 0x114100000000 && serial <= 0x114199999999;
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
class HM_2CH : public InverterAbstract {
|
class HM_2CH : public InverterAbstract {
|
||||||
public:
|
public:
|
||||||
|
HM_2CH(uint64_t serial);
|
||||||
static bool isValidSerial(uint64_t serial);
|
static bool isValidSerial(uint64_t serial);
|
||||||
String typeName();
|
String typeName();
|
||||||
const byteAssign_t* getByteAssignment();
|
const byteAssign_t* getByteAssignment();
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
#include "HM_4CH.h"
|
#include "HM_4CH.h"
|
||||||
|
|
||||||
|
HM_4CH::HM_4CH(uint64_t serial)
|
||||||
|
: InverterAbstract(serial) {};
|
||||||
|
|
||||||
bool HM_4CH::isValidSerial(uint64_t serial)
|
bool HM_4CH::isValidSerial(uint64_t serial)
|
||||||
{
|
{
|
||||||
return serial >= 0x116100000000 && serial <= 0x116199999999;
|
return serial >= 0x116100000000 && serial <= 0x116199999999;
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
class HM_4CH : public InverterAbstract {
|
class HM_4CH : public InverterAbstract {
|
||||||
public:
|
public:
|
||||||
|
HM_4CH(uint64_t serial);
|
||||||
static bool isValidSerial(uint64_t serial);
|
static bool isValidSerial(uint64_t serial);
|
||||||
String typeName();
|
String typeName();
|
||||||
const byteAssign_t* getByteAssignment();
|
const byteAssign_t* getByteAssignment();
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
#include "crc.h"
|
#include "crc.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
void InverterAbstract::setSerial(uint64_t serial)
|
InverterAbstract::InverterAbstract(uint64_t serial)
|
||||||
{
|
{
|
||||||
_serial.u64 = serial;
|
_serial.u64 = serial;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -90,7 +90,7 @@ const calcFunc_t calcFunctions[] = {
|
|||||||
|
|
||||||
class InverterAbstract {
|
class InverterAbstract {
|
||||||
public:
|
public:
|
||||||
void setSerial(uint64_t serial);
|
InverterAbstract(uint64_t serial);
|
||||||
uint64_t serial();
|
uint64_t serial();
|
||||||
void setName(const char* name);
|
void setName(const char* name);
|
||||||
const char* name();
|
const char* name();
|
||||||
|
|||||||
@ -212,8 +212,12 @@ void WebApiInverterClass::onInverterEdit(AsyncWebServerRequest* request)
|
|||||||
request->send(response);
|
request->send(response);
|
||||||
|
|
||||||
std::shared_ptr<InverterAbstract> inv = Hoymiles.getInverterByPos(root[F("id")].as<uint64_t>());
|
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++) {
|
for (uint8_t c = 0; c < INV_MAX_CHAN_COUNT; c++) {
|
||||||
inv->setChannelMaxPower(c, inverter.MaxChannelPower[c]);
|
inv->setChannelMaxPower(c, inverter.MaxChannelPower[c]);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user