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.local.parsers.RawDataParser;
22 import org.openhab.binding.solax.internal.model.local.parsers.X1BoostAirMiniDataParser;
23 import org.openhab.binding.solax.internal.model.local.parsers.X1HybridG4DataParser;
24 import org.openhab.binding.solax.internal.model.local.parsers.X3HybridG4DataParser;
25 import org.openhab.binding.solax.internal.model.local.parsers.X3MicOrProG2DataParser;
28 * The {@link InverterType} class is enum representing the different inverter types with a simple logic to convert from
29 * int(coming from the JSON) to a more meaningful enum value.
31 * @author Konstantin Polihronov - Initial contribution
34 public enum InverterType {
39 X1_BOOST_AIR_MINI(4, new X1BoostAirMiniDataParser()),
49 X3_HYBRID_G4(14, new X3HybridG4DataParser()),
50 X1_HYBRID_G4(15, new X1HybridG4DataParser()),
51 X3_MIC_OR_PRO_G2(16, new X3MicOrProG2DataParser()),
53 X1_BOOST_OR_MINI_G4(18),
61 private int typeIndex;
63 private @Nullable RawDataParser parser;
65 private Set<String> supportedChannels = new HashSet<>();
67 InverterType(int typeIndex) {
68 this(typeIndex, null);
71 InverterType(int typeIndex, @Nullable RawDataParser parser) {
72 this.typeIndex = typeIndex;
75 this.supportedChannels = parser.getSupportedChannels();
79 public static InverterType fromIndex(int index) {
80 InverterType[] values = InverterType.values();
81 return Stream.of(values).filter(value -> value.typeIndex == index).findFirst().orElse(UNKNOWN);
84 public @Nullable RawDataParser getParser() {
88 public Set<String> getSupportedChannels() {
89 return supportedChannels;