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.model;
15 import java.util.HashSet;
17 import java.util.stream.Stream;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.solax.internal.model.parsers.RawDataParser;
22 import org.openhab.binding.solax.internal.model.parsers.X1HybridG4DataParser;
23 import org.openhab.binding.solax.internal.model.parsers.X3HybridG4DataParser;
24 import org.openhab.binding.solax.internal.model.parsers.X3MicOrProG2DataParser;
27 * The {@link InverterType} class is enum representing the different inverter types with a simple logic to convert from
28 * int(coming from the JSON) to a more meaningful enum value.
30 * @author Konstantin Polihronov - Initial contribution
33 public enum InverterType {
48 X3_HYBRID_G4(14, new X3HybridG4DataParser()),
49 X1_HYBRID_G4(15, new X1HybridG4DataParser()),
50 X3_MIC_OR_PRO_G2(16, new X3MicOrProG2DataParser()),
52 X1_BOOST_OR_MINI_G4(18),
60 private int typeIndex;
62 private @Nullable RawDataParser parser;
64 private Set<String> supportedChannels = new HashSet<>();
66 InverterType(int typeIndex) {
67 this(typeIndex, null);
70 InverterType(int typeIndex, @Nullable RawDataParser parser) {
71 this.typeIndex = typeIndex;
74 this.supportedChannels = parser.getSupportedChannels();
78 public static InverterType fromIndex(int index) {
79 InverterType[] values = InverterType.values();
80 return Stream.of(values).filter(value -> value.typeIndex == index).findFirst().orElse(UNKNOWN);
83 public @Nullable RawDataParser getParser() {
87 public Set<String> getSupportedChannels() {
88 return supportedChannels;