]> git.basschouten.com Git - openhab-addons.git/blob
ea1fab3f2268156ed0fef1052aa772c847b68414
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.sonyprojector.internal.communication;
14
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.List;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.sonyprojector.internal.SonyProjectorException;
22 import org.openhab.core.types.StateOption;
23 import org.openhab.core.util.HexUtils;
24
25 /**
26  * Represents the different color temperatures available for the projector
27  *
28  * @author Laurent Garnier - Initial contribution
29  */
30 @NonNullByDefault
31 public enum SonyProjectorColorTemp {
32
33     // Category 1: VW260, VW270, VW285, VW295, VW300, VW315, VW320, VW328, VW350, VW365, VW385, VW500, VW515, VW520,
34     // VW528, VW550, VW570, VW600, VW665, VW675, VW695, VW760, VW870, VW885, VW995, HW60, HW65, HW68
35     CAT1_D93(1, "D93", null, new byte[] { 0x00, 0x00 }),
36     CAT1_D75(1, "D75", null, new byte[] { 0x00, 0x01 }),
37     CAT1_D65(1, "D65", null, new byte[] { 0x00, 0x02 }),
38     CAT1_D55(1, "D55", null, new byte[] { 0x00, 0x09 }),
39     CAT1_CUSTOM1(1, "Custom1", "Custom 1", new byte[] { 0x00, 0x03 }),
40     CAT1_CUSTOM2(1, "Custom2", "Custom 2", new byte[] { 0x00, 0x04 }),
41     CAT1_CUSTOM3(1, "Custom3", "Custom 3", new byte[] { 0x00, 0x05 }),
42     CAT1_CUSTOM4(1, "Custom4", "Custom 4", new byte[] { 0x00, 0x06 }),
43     CAT1_CUSTOM5(1, "Custom5", "Custom 5", new byte[] { 0x00, 0x08 }),
44
45     // Category 2: VW40, VW50, VW60, VW100, VW200
46     CAT2_HIGH(2, "High", null, new byte[] { 0x00, 0x00 }),
47     CAT2_MIDDLE(2, "Middle", null, new byte[] { 0x00, 0x01 }),
48     CAT2_LOW(2, "Low", null, new byte[] { 0x00, 0x02 }),
49     CAT2_CUSTOM1(2, "Custom1", "Custom 1", new byte[] { 0x00, 0x03 }),
50     CAT2_CUSTOM2(2, "Custom2", "Custom 2", new byte[] { 0x00, 0x04 }),
51     CAT2_CUSTOM3(2, "Custom3", "Custom 3", new byte[] { 0x00, 0x05 }),
52
53     // Category 3: VW70, VW80, HW10, HW15, HW20
54     CAT3_HIGH(3, "High", null, new byte[] { 0x00, 0x00 }),
55     CAT3_MIDDLE(3, "Middle", null, new byte[] { 0x00, 0x01 }),
56     CAT3_LOW(3, "Low", null, new byte[] { 0x00, 0x02 }),
57     CAT3_CUSTOM1(3, "Custom1", "Custom 1", new byte[] { 0x00, 0x03 }),
58     CAT3_CUSTOM2(3, "Custom2", "Custom 2", new byte[] { 0x00, 0x04 }),
59     CAT3_CUSTOM3(3, "Custom3", "Custom 3", new byte[] { 0x00, 0x05 }),
60     CAT3_CUSTOM4(3, "Custom4", "Custom 4", new byte[] { 0x00, 0x06 }),
61
62     // Category 4: VW85, VW90, VW95, HW30
63     CAT4_HIGH(4, "High", null, new byte[] { 0x00, 0x00 }),
64     CAT4_MIDDLE(4, "Middle", null, new byte[] { 0x00, 0x01 }),
65     CAT4_LOW1(4, "Low1", "Low 1", new byte[] { 0x00, 0x02 }),
66     CAT4_LOW2(4, "Low2", "Low 2", new byte[] { 0x00, 0x07 }),
67     CAT4_CUSTOM1(4, "Custom1", "Custom 1", new byte[] { 0x00, 0x03 }),
68     CAT4_CUSTOM2(4, "Custom2", "Custom 2", new byte[] { 0x00, 0x04 }),
69     CAT4_CUSTOM3(4, "Custom3", "Custom 3", new byte[] { 0x00, 0x05 }),
70     CAT4_CUSTOM4(4, "Custom4", "Custom 4", new byte[] { 0x00, 0x06 }),
71     CAT4_CUSTOM5(4, "Custom5", "Custom 5", new byte[] { 0x00, 0x08 }),
72
73     // Category 5: VW1000ES, VW1100ES
74     CAT5_D93(5, "D93", null, new byte[] { 0x00, 0x00 }),
75     CAT5_D75(5, "D75", null, new byte[] { 0x00, 0x01 }),
76     CAT5_D65(5, "D65", null, new byte[] { 0x00, 0x02 }),
77     CAT5_D55(5, "D55", null, new byte[] { 0x00, 0x09 }),
78     CAT5_DCI(5, "DCI", null, new byte[] { 0x00, 0x07 }),
79     CAT5_CUSTOM1(5, "Custom1", "Custom 1", new byte[] { 0x00, 0x03 }),
80     CAT5_CUSTOM2(5, "Custom2", "Custom 2", new byte[] { 0x00, 0x04 }),
81     CAT5_CUSTOM3(5, "Custom3", "Custom 3", new byte[] { 0x00, 0x05 }),
82     CAT5_CUSTOM4(5, "Custom4", "Custom 4", new byte[] { 0x00, 0x06 }),
83     CAT5_CUSTOM5(5, "Custom5", "Custom 5", new byte[] { 0x00, 0x08 }),
84
85     // Category 6: HW35ES, HW40ES, HW45ES, HW58ES
86     CAT6_D93(6, "D93", null, new byte[] { 0x00, 0x00 }),
87     CAT6_D75(6, "D75", null, new byte[] { 0x00, 0x01 }),
88     CAT6_D65(6, "D65", null, new byte[] { 0x00, 0x02 }),
89     CAT6_D55(6, "D55", null, new byte[] { 0x00, 0x07 }),
90     CAT6_CUSTOM(6, "Custom", null, new byte[] { 0x00, 0x08 }),
91
92     // Category 7: HW50ES, HW55ES
93     CAT7_D93(7, "D93", null, new byte[] { 0x00, 0x00 }),
94     CAT7_D75(7, "D75", null, new byte[] { 0x00, 0x01 }),
95     CAT7_D65(7, "D65", null, new byte[] { 0x00, 0x02 }),
96     CAT7_D55(7, "D55", null, new byte[] { 0x00, 0x07 }),
97     CAT7_CUSTOM1(7, "Custom1", "Custom 1", new byte[] { 0x00, 0x03 }),
98     CAT7_CUSTOM2(7, "Custom2", "Custom 2", new byte[] { 0x00, 0x04 }),
99     CAT7_CUSTOM3(7, "Custom3", "Custom 3", new byte[] { 0x00, 0x05 }),
100     CAT7_CUSTOM4(7, "Custom4", "Custom 4", new byte[] { 0x00, 0x06 }),
101     CAT7_CUSTOM5(7, "Custom5", "Custom 5", new byte[] { 0x00, 0x08 });
102
103     private int category;
104     private String name;
105     private @Nullable String label;
106     private byte[] dataCode;
107
108     /**
109      * Constructor
110      *
111      * @param category a category of projector models for which the color temperature is available
112      * @param name the name of the color temperature
113      * @param label the label of the color temperature; can be null when the label is identical to the name
114      * @param dataCode the data code identifying the color temperature
115      */
116     private SonyProjectorColorTemp(int category, String name, @Nullable String label, byte[] dataCode) {
117         this.category = category;
118         this.name = name;
119         this.label = label;
120         this.dataCode = dataCode;
121     }
122
123     /**
124      * Get the category of projector models for the current color temperature
125      *
126      * @return the category of projector models
127      */
128     public int getCategory() {
129         return category;
130     }
131
132     /**
133      * Get the data code identifying the current color temperature
134      *
135      * @return the data code
136      */
137     public byte[] getDataCode() {
138         return dataCode;
139     }
140
141     /**
142      * Get the label of the current color temperature
143      *
144      * @return the label
145      */
146     public @Nullable String getLabel() {
147         return label;
148     }
149
150     /**
151      * Get the name of the current color temperature
152      *
153      * @return the name
154      */
155     public String getName() {
156         return name;
157     }
158
159     /**
160      * Get the list of {@link StateOption} associated to the available color temperatures for a particular category of
161      * projector models
162      *
163      * @param category a category of projector models
164      *
165      * @return the list of {@link StateOption} associated to the available color temperatures for a provided category of
166      *         projector models
167      */
168     public static List<StateOption> getStateOptions(int category) {
169         List<StateOption> options = new ArrayList<>();
170         for (SonyProjectorColorTemp value : SonyProjectorColorTemp.values()) {
171             if (value.getCategory() == category) {
172                 options.add(new StateOption(value.getName(),
173                         value.getLabel() != null ? value.getLabel() : value.getName()));
174             }
175         }
176         return options;
177     }
178
179     /**
180      * Get the color temperature associated to a name for a particular category of projector models
181      *
182      * @param category a category of projector models
183      * @param name the name used to identify the color temperature
184      *
185      * @return the color temperature associated to the searched name for the provided category of projector models
186      *
187      * @throws SonyProjectorException - If no color temperature is associated to the searched name for the provided
188      *             category
189      */
190     public static SonyProjectorColorTemp getFromName(int category, String name) throws SonyProjectorException {
191         for (SonyProjectorColorTemp value : SonyProjectorColorTemp.values()) {
192             if (value.getCategory() == category && value.getName().equals(name)) {
193                 return value;
194             }
195         }
196         throw new SonyProjectorException("Invalid name for a color temperature: " + name);
197     }
198
199     /**
200      * Get the color temperature associated to a data code for a particular category of projector models
201      *
202      * @param category a category of projector models
203      * @param dataCode the data code used to identify the color temperature
204      *
205      * @return the color temperature associated to the searched data code for the provided category of projector models
206      *
207      * @throws SonyProjectorException - If no color temperature is associated to the searched data code for the provided
208      *             category
209      */
210     public static SonyProjectorColorTemp getFromDataCode(int category, byte[] dataCode) throws SonyProjectorException {
211         for (SonyProjectorColorTemp value : SonyProjectorColorTemp.values()) {
212             if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
213                 return value;
214             }
215         }
216         throw new SonyProjectorException("Invalid data code for a color temperature: " + HexUtils.bytesToHex(dataCode));
217     }
218 }