2 * Copyright (c) 2010-2020 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.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;
26 * Represents the different iris modes available for the projector
28 * @author Laurent Garnier - Initial contribution
31 public enum SonyProjectorIrisMode {
33 // Category 1: VW385, VW500, VW515, VW520, VW528, VW550, VW570, VW600, VW665, VW675, VW695, VW760, VW870, VW885,
34 // VW995, HW60, HW65, HW68
35 CAT1_FULL(1, "Full", null, new byte[] { 0x00, 0x02 }),
36 CAT1_LIMITED(1, "Limited", null, new byte[] { 0x00, 0x03 }),
37 CAT1_OFF(1, "Off", null, new byte[] { 0x00, 0x00 }),
39 // Category 2: VW40, VW50, VW60
40 CAT2_ON(2, "On", null, new byte[] { 0x00, 0x01 }),
41 CAT2_AUTO1(2, "Auto1", "Auto 1", new byte[] { 0x00, 0x02 }),
42 CAT2_AUTO2(2, "Auto2", "Auto 2", new byte[] { 0x00, 0x03 }),
43 CAT2_OFF(2, "Off", null, new byte[] { 0x00, 0x00 }),
45 // Category 3: VW70, VW80, VW85, VW90, VW95, VW200, HW10, HW15, HW20, HW30ES
46 CAT3_AUTO1(3, "Auto1", "Auto 1", new byte[] { 0x00, 0x02 }),
47 CAT3_AUTO2(3, "Auto2", "Auto 2", new byte[] { 0x00, 0x03 }),
48 CAT3_MANUAL(3, "Manual", null, new byte[] { 0x00, 0x01 }),
49 CAT3_OFF(3, "Off", null, new byte[] { 0x00, 0x00 }),
52 CAT4_ON(4, "On", null, new byte[] { 0x00, 0x01 }),
53 CAT4_AUTO(4, "Auto", null, new byte[] { 0x00, 0x02 }),
54 CAT4_OFF(4, "Off", null, new byte[] { 0x00, 0x00 }),
56 // Category 5: VW1000ES, VW1100ES, HW50ES, HW55ES
57 CAT5_AUTO_FULL(5, "AutoFull", "Auto Full", new byte[] { 0x00, 0x02 }),
58 CAT5_AUTO_LIMITED(5, "AutoLimited", "Auto Limited", new byte[] { 0x00, 0x03 }),
59 CAT5_MANUAL(5, "Manual", null, new byte[] { 0x00, 0x01 }),
60 CAT5_OFF(5, "Off", null, new byte[] { 0x00, 0x00 });
64 private @Nullable String label;
65 private byte[] dataCode;
70 * @param category a category of projector models for which the iris mode is available
71 * @param name the name of the iris mode
72 * @param label the label of the iris mode; can be null when the label is identical to the name
73 * @param dataCode the data code identifying the iris mode
75 private SonyProjectorIrisMode(int category, String name, @Nullable String label, byte[] dataCode) {
76 this.category = category;
79 this.dataCode = dataCode;
83 * Get the category of projector models for the current iris mode
85 * @return the category of projector models
87 public int getCategory() {
92 * Get the data code identifying the current iris mode
94 * @return the data code
96 public byte[] getDataCode() {
101 * Get the label of the current iris mode
105 public @Nullable String getLabel() {
110 * Get the name of the current iris mode
114 public String getName() {
119 * Get the list of {@link StateOption} associated to the available iris modes for a particular category of projector
122 * @param category a category of projector models
124 * @return the list of {@link StateOption} associated to the available iris modes for a provided category of
127 public static List<StateOption> getStateOptions(int category) {
128 List<StateOption> options = new ArrayList<>();
129 for (SonyProjectorIrisMode value : SonyProjectorIrisMode.values()) {
130 if (value.getCategory() == category) {
131 options.add(new StateOption(value.getName(),
132 value.getLabel() != null ? value.getLabel() : value.getName()));
139 * Get the iris mode associated to a name for a particular category of projector models
141 * @param category a category of projector models
142 * @param name the name used to identify the iris mode
144 * @return the iris mode associated to the searched name for the provided category of projector models
146 * @throws SonyProjectorException - If no iris mode is associated to the searched name for the provided category
148 public static SonyProjectorIrisMode getFromName(int category, String name) throws SonyProjectorException {
149 for (SonyProjectorIrisMode value : SonyProjectorIrisMode.values()) {
150 if (value.getCategory() == category && value.getName().equals(name)) {
154 throw new SonyProjectorException("Invalid name for an iris mode: " + name);
158 * Get the iris mode associated to a data code for a particular category of projector models
160 * @param category a category of projector models
161 * @param dataCode the data code used to identify the iris mode
163 * @return the iris mode associated to the searched data code for the provided category of projector models
165 * @throws SonyProjectorException - If no iris mode is associated to the searched data code for the provided
168 public static SonyProjectorIrisMode getFromDataCode(int category, byte[] dataCode) throws SonyProjectorException {
169 for (SonyProjectorIrisMode value : SonyProjectorIrisMode.values()) {
170 if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
174 throw new SonyProjectorException("Invalid data code for an iris mode: " + HexUtils.bytesToHex(dataCode));