2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.solax.internal;
15 import static org.junit.jupiter.api.Assertions.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.Test;
19 import org.openhab.binding.solax.internal.connectivity.rawdata.LocalConnectRawDataBean;
20 import org.openhab.binding.solax.internal.model.InverterData;
21 import org.openhab.binding.solax.internal.model.InverterType;
22 import org.openhab.binding.solax.internal.model.parsers.RawDataParser;
25 * The {@link TestX1HybridG4Parser} Simple test that tests for proper parsing against a real data from the inverter
27 * @author Konstantin Polihronov - Initial contribution
30 public class TestX1HybridG4Parser {
32 private static final String RAW_DATA = """
34 sn:SOME_SERIAL_NUMBER,
38 2388,21,460,4998,4483,4483,10,1,487,65,
39 2,59781,0,70,12180,500,605,33,99,12000,
40 0,23159,0,57,100,0,39,4501,0,0,
41 0,0,12,0,13240,0,63348,2,448,43,
42 256,1314,900,0,350,311,279,33,33,279,1,1,652,0,708,1,65077,65535,65386,65535,0,0,0,0,0,0,0,0,0,0,0,0,65068,65535,4500,0,61036,65535,10,0,90,0,0,12,0,116,7,57,0,0,2320,0,110,0,0,0,0,0,0,12544,7440,5896,594,521,9252,0,0,0,0,0,1,1201,0,0,3342,3336,7296,54,21302,14389,18753,12852,16692,12355,13618,21302,14389,18753,12852,16692,12355,13618,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1025,4609,1026,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
43 Information:[7.500,15,H4752TI1063020,8,1.24,0.00,1.21,1.03,0.00,1]}
47 public void testParser() {
48 LocalConnectRawDataBean bean = LocalConnectRawDataBean.fromJson(RAW_DATA);
49 int type = bean.getType();
50 InverterType inverterType = InverterType.fromIndex(type);
51 assertEquals(InverterType.X1_HYBRID_G4, inverterType, "Inverter type not recognized properly");
53 RawDataParser parser = inverterType.getParser();
54 assertNotNull(parser);
56 InverterData data = parser.getData(bean);
57 assertEquals("SOME_SERIAL_NUMBER", data.getWifiSerial());
58 assertEquals("3.008.10", data.getWifiVersion());
60 assertEquals(238.8, data.getInverterVoltage()); // [0]
61 assertEquals(2.1, data.getInverterCurrent()); // [1]
62 assertEquals(460, data.getInverterOutputPower()); // [2]
63 assertEquals(49.98, data.getInverterFrequency()); // [3]
65 assertEquals(448.3, data.getPV1Voltage()); // [4]
66 assertEquals(448.3, data.getPV2Voltage()); // [5]
67 assertEquals(1, data.getPV1Current()); // [6]
68 assertEquals(0.1, data.getPV2Current()); // [7]
69 assertEquals(487, data.getPV1Power()); // [8]
70 assertEquals(65, data.getPV2Power()); // [9]
72 assertEquals(121.8, data.getBatteryVoltage()); // [14]
73 assertEquals(5, data.getBatteryCurrent()); // [15]
74 assertEquals(605, data.getBatteryPower()); // [16]
75 assertEquals(33, data.getBatteryTemperature()); // [17]
76 assertEquals(99, data.getBatteryLevel()); // [18]
78 assertEquals(12, data.getFeedInPower()); // [32]
81 // Yield_Today: Data[13] / 10,
82 // Yield_Total: read32BitUnsigned(Data[11], Data[12]) / 10,
85 // BAT_Power: read16BitSigned(Data[16]),
86 // feedInPower: read32BitSigned(Data[32], Data[33]),
87 // GridAPower: read16BitSigned(Data[2]),
88 // FeedInEnergy: read32BitUnsigned(Data[34], Data[35]) / 100,
89 // ConsumeEnergy: read32BitUnsigned(Data[36], Data[37]) / 100,
91 // EPSAPower: read16BitSigned(Data[28]),
92 // Vdc1: Data[4] / 10,
93 // Vdc2: Data[5] / 10,
94 // Idc1: Data[6] / 10,
95 // Idc2: Data[7] / 10,
96 // EPSAVoltage: Data[29] / 10,
97 // EPSACurrent: read16BitSigned(Data[30]) / 10,
98 // BatteryCapacity: Data[18],
99 // BatteryVoltage: Data[14] / 100,
100 // BatteryTemperature: read16BitSigned(Data[17]),
101 // GridAVoltage: Data[0] / 10,
102 // GridACurrent: read16BitSigned(Data[1]) / 10,
103 // FreqacA: Data[3] / 100,