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