From ab0029d9fd1e4cf6ecd807654d240b791b55aa35 Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Mon, 7 Nov 2022 22:38:53 +0100 Subject: [PATCH] Show the correct amount of string input fields in inverter config --- src/WebApi_inverter.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/WebApi_inverter.cpp b/src/WebApi_inverter.cpp index f467fd5..2fb254f 100644 --- a/src/WebApi_inverter.cpp +++ b/src/WebApi_inverter.cpp @@ -53,13 +53,16 @@ void WebApiInverterClass::onInverterList(AsyncWebServerRequest* request) obj[F("serial")] = buffer; auto inv = Hoymiles.getInverterBySerial(config.Inverter[i].Serial); + uint8_t max_channels; if (inv == nullptr) { obj[F("type")] = F("Unknown"); + max_channels = INV_MAX_CHAN_COUNT; } else { obj[F("type")] = inv->typeName(); + max_channels = inv->Statistics()->getChannelCount(); } - for (uint8_t c = 0; c < INV_MAX_CHAN_COUNT; c++) { + for (uint8_t c = 0; c < max_channels; c++) { obj[F("max_power")][c] = config.Inverter[i].MaxChannelPower[c]; } } @@ -223,7 +226,7 @@ void WebApiInverterClass::onInverterEdit(AsyncWebServerRequest* request) } JsonArray maxPowerArray = root[F("max_power")].as(); - if (maxPowerArray.size() != INV_MAX_CHAN_COUNT) { + if (maxPowerArray.size() == 0 || maxPowerArray.size() > INV_MAX_CHAN_COUNT) { retMsg[F("message")] = F("Invalid amount of max channel setting given!"); response->setLength(); request->send(response);