]> git.basschouten.com Git - openhab-addons.git/blob
17a88adecbbab6f911c2ae67c95e47c8358a899b
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.solax.internal.model;
14
15 import java.util.HashSet;
16 import java.util.Objects;
17 import java.util.Set;
18 import java.util.stream.Stream;
19
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;
27
28 /**
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.
31  *
32  * @author Konstantin Polihronov - Initial contribution
33  */
34 @NonNullByDefault
35 public enum InverterType {
36
37     X1_LX(1),
38     X_HYBRID(2),
39     X1_HYBRID_FIT(3),
40     X1_BOOST_AIR_MINI(4, new X1BoostAirMiniDataParser()),
41     X3_HYBRID_FIT(5),
42     X3_20K_30K(6),
43     X3_MIC_PRO(7),
44     X1_SMART(8),
45     X1_AC(9),
46     A1_HYBRID(10),
47     A1_FIT(11),
48     A1_GRID(12),
49     J1_ESS(13),
50     X3_HYBRID_G4(14, new X3HybridG4DataParser()),
51     X1_HYBRID_G4(15, new X1HybridG4DataParser()),
52     X3_MIC_OR_PRO_G2(16, new X3MicOrProG2DataParser()),
53     X1_SPT(17),
54     X1_BOOST_OR_MINI_G4(18),
55     A1_HYB_G2(19),
56     A1_AC_G2(20),
57     A1_SMT_G2(21),
58     X3_FTH(22),
59     X3_MGA_G2(23),
60     UNKNOWN(-1);
61
62     private int typeIndex;
63
64     private @Nullable RawDataParser parser;
65
66     private Set<String> supportedChannels = new HashSet<>();
67
68     InverterType(int typeIndex) {
69         this(typeIndex, null);
70     }
71
72     InverterType(int typeIndex, @Nullable RawDataParser parser) {
73         this.typeIndex = typeIndex;
74         this.parser = parser;
75         if (parser != null) {
76             this.supportedChannels = parser.getSupportedChannels();
77         }
78     }
79
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));
84     }
85
86     public @Nullable RawDataParser getParser() {
87         return parser;
88     }
89
90     public Set<String> getSupportedChannels() {
91         return supportedChannels;
92     }
93 }