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;
16 import java.util.Objects;
18 import java.util.stream.Stream;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.binding.solax.internal.model.local.parsers.RawDataParser;
23 import org.openhab.binding.solax.internal.model.local.parsers.X1BoostAirMiniDataParser;
24 import org.openhab.binding.solax.internal.model.local.parsers.X1HybridG4DataParser;
25 import org.openhab.binding.solax.internal.model.local.parsers.X3HybridG4DataParser;
26 import org.openhab.binding.solax.internal.model.local.parsers.X3MicOrProG2DataParser;
29 * The {@link InverterType} class is enum representing the different inverter types with a simple logic to convert from
30 * int(coming from the JSON) to a more meaningful enum value.
32 * @author Konstantin Polihronov - Initial contribution
35 public enum InverterType {
40 X1_BOOST_AIR_MINI(4, new X1BoostAirMiniDataParser()),
50 X3_HYBRID_G4(14, new X3HybridG4DataParser()),
51 X1_HYBRID_G4(15, new X1HybridG4DataParser()),
52 X3_MIC_OR_PRO_G2(16, new X3MicOrProG2DataParser()),
54 X1_BOOST_OR_MINI_G4(18),
62 private int typeIndex;
64 private @Nullable RawDataParser parser;
66 private Set<String> supportedChannels = new HashSet<>();
68 InverterType(int typeIndex) {
69 this(typeIndex, null);
72 InverterType(int typeIndex, @Nullable RawDataParser parser) {
73 this.typeIndex = typeIndex;
76 this.supportedChannels = parser.getSupportedChannels();
80 public static InverterType fromIndex(int index) {
81 InverterType[] values = InverterType.values();
82 return Objects.requireNonNull(
83 Stream.of(values).filter(value -> value.typeIndex == index).findFirst().orElse(UNKNOWN));
86 public @Nullable RawDataParser getParser() {
90 public Set<String> getSupportedChannels() {
91 return supportedChannels;