Skip to content

Commit 40edd7c

Browse files
committed
Fixed another Pro3Em index out of bounds exception
1 parent 569e4c8 commit 40edd7c

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

ShellyPro3EmExporter/ShellyPro3EmConnection.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,26 @@ bool UpdateRegularMetrics(string requestResponse)
210210
JsonDocument json = JsonDocument.Parse(requestResponse);
211211

212212
JsonElement paramsElement = json.RootElement.GetProperty("result");
213-
213+
214+
if (meterReadings.Length < 1)
215+
{
216+
return false;
217+
}
218+
219+
bool startingFromZero = meterReadings[0].meterIndex == 0;
220+
214221
foreach (MeterReading meterReading in meterReadings)
215222
{
216-
string phase = indexToPhaseMap[meterReading.meterIndex - 1];
223+
string phase;
224+
225+
if (startingFromZero)
226+
{
227+
phase = indexToPhaseMap[meterReading.meterIndex];
228+
}
229+
else
230+
{
231+
phase = indexToPhaseMap[meterReading.meterIndex - 1];
232+
}
217233

218234
if (!meterReading.currentIgnored)
219235
{

0 commit comments

Comments
 (0)