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