2 * Copyright (c) 2010-2023 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;
26 * The {@link InverterType} class is enum representing the different inverter types with a simple logic to convert from
27 * int(coming from the JSON) to a more meaningful enum value.
29 * @author Konstantin Polihronov - Initial contribution
32 public enum InverterType {
47 X3_HYBRID_G4(14, new X3HybridG4DataParser()),
48 X1_HYBRID_G4(15, new X1HybridG4DataParser()),
51 X1_BOOST_OR_MINI_G4(18),
59 private int typeIndex;
61 private @Nullable RawDataParser parser;
63 private Set<String> supportedChannels = new HashSet<>();
65 InverterType(int typeIndex) {
66 this(typeIndex, null);
69 InverterType(int typeIndex, @Nullable RawDataParser parser) {
70 this.typeIndex = typeIndex;
73 this.supportedChannels = parser.getSupportedChannels();
77 public static InverterType fromIndex(int index) {
78 InverterType[] values = InverterType.values();
79 return Stream.of(values).filter(value -> value.typeIndex == index).findFirst().orElse(UNKNOWN);
82 public @Nullable RawDataParser getParser() {
86 public Set<String> getSupportedChannels() {
87 return supportedChannels;