]> git.basschouten.com Git - openhab-addons.git/blob
9d87543dfe7213de2f1730b9ca9df8d5b3251511
[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.Set;
17 import java.util.stream.Stream;
18
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;
25
26 /**
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.
29  *
30  * @author Konstantin Polihronov - Initial contribution
31  */
32 @NonNullByDefault
33 public enum InverterType {
34
35     X1_LX(1),
36     X_HYBRID(2),
37     X1_HYBRID_FIT(3),
38     X1_BOOST_AIR_MINI(4),
39     X3_HYBRID_FIT(5),
40     X3_20K_30K(6),
41     X3_MIC_PRO(7),
42     X1_SMART(8),
43     X1_AC(9),
44     A1_HYBRID(10),
45     A1_FIT(11),
46     A1_GRID(12),
47     J1_ESS(13),
48     X3_HYBRID_G4(14, new X3HybridG4DataParser()),
49     X1_HYBRID_G4(15, new X1HybridG4DataParser()),
50     X3_MIC_OR_PRO_G2(16, new X3MicOrProG2DataParser()),
51     X1_SPT(17),
52     X1_BOOST_OR_MINI_G4(18),
53     A1_HYB_G2(19),
54     A1_AC_G2(20),
55     A1_SMT_G2(21),
56     X3_FTH(22),
57     X3_MGA_G2(23),
58     UNKNOWN(-1);
59
60     private int typeIndex;
61
62     private @Nullable RawDataParser parser;
63
64     private Set<String> supportedChannels = new HashSet<>();
65
66     InverterType(int typeIndex) {
67         this(typeIndex, null);
68     }
69
70     InverterType(int typeIndex, @Nullable RawDataParser parser) {
71         this.typeIndex = typeIndex;
72         this.parser = parser;
73         if (parser != null) {
74             this.supportedChannels = parser.getSupportedChannels();
75         }
76     }
77
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);
81     }
82
83     public @Nullable RawDataParser getParser() {
84         return parser;
85     }
86
87     public Set<String> getSupportedChannels() {
88         return supportedChannels;
89     }
90 }