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