2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.sonyprojector.internal.communication;
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.List;
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;
25 * Represents the different color temperatures available for the projector
27 * @author Laurent Garnier - Initial contribution
30 public enum SonyProjectorColorTemp {
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 }),
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 }),
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 }),
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 }),
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 }),
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 }),
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 });
102 private int category;
104 private byte[] dataCode;
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
113 private SonyProjectorColorTemp(int category, String name, byte[] dataCode) {
114 this.category = category;
116 this.dataCode = dataCode;
120 * Get the category of projector models for the current color temperature
122 * @return the category of projector models
124 public int getCategory() {
129 * Get the data code identifying the current color temperature
131 * @return the data code
133 public byte[] getDataCode() {
138 * Get the name of the current color temperature
142 public String getName() {
147 * Get the list of {@link StateOption} associated to the available color temperatures for a particular category of
150 * @param category a category of projector models
152 * @return the list of {@link StateOption} associated to the available color temperatures for a provided category of
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()));
166 * Get the color temperature associated to a name for a particular category of projector models
168 * @param category a category of projector models
169 * @param name the name used to identify the color temperature
171 * @return the color temperature associated to the searched name for the provided category of projector models
173 * @throws SonyProjectorException - If no color temperature is associated to the searched name for the provided
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)) {
182 throw new SonyProjectorException("Invalid name for a color temperature: " + name);
186 * Get the color temperature associated to a data code for a particular category of projector models
188 * @param category a category of projector models
189 * @param dataCode the data code used to identify the color temperature
191 * @return the color temperature associated to the searched data code for the provided category of projector models
193 * @throws SonyProjectorException - If no color temperature is associated to the searched data code for the provided
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())) {
202 throw new SonyProjectorException("Invalid data code for a color temperature: " + HexUtils.bytesToHex(dataCode));