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 iris modes available for the projector
27 * @author Laurent Garnier - Initial contribution
30 public enum SonyProjectorIrisMode {
32 // Category 1: VW385, VW500, VW515, VW520, VW528, VW550, VW570, VW600, VW665, VW675, VW695, VW760, VW870, VW885,
33 // VW995, HW60, HW65, HW68
34 CAT1_FULL(1, "Full", new byte[] { 0x00, 0x02 }),
35 CAT1_LIMITED(1, "Limited", new byte[] { 0x00, 0x03 }),
36 CAT1_OFF(1, "Off", new byte[] { 0x00, 0x00 }),
38 // Category 2: VW40, VW50, VW60
39 CAT2_ON(2, "On", new byte[] { 0x00, 0x01 }),
40 CAT2_AUTO1(2, "Auto1", new byte[] { 0x00, 0x02 }),
41 CAT2_AUTO2(2, "Auto2", new byte[] { 0x00, 0x03 }),
42 CAT2_OFF(2, "Off", new byte[] { 0x00, 0x00 }),
44 // Category 3: VW70, VW80, VW85, VW90, VW95, VW200, HW10, HW15, HW20, HW30ES
45 CAT3_AUTO1(3, "Auto1", new byte[] { 0x00, 0x02 }),
46 CAT3_AUTO2(3, "Auto2", new byte[] { 0x00, 0x03 }),
47 CAT3_MANUAL(3, "Manual", new byte[] { 0x00, 0x01 }),
48 CAT3_OFF(3, "Off", new byte[] { 0x00, 0x00 }),
51 CAT4_ON(4, "On", new byte[] { 0x00, 0x01 }),
52 CAT4_AUTO(4, "Auto", new byte[] { 0x00, 0x02 }),
53 CAT4_OFF(4, "Off", new byte[] { 0x00, 0x00 }),
55 // Category 5: VW1000ES, VW1100ES, HW50ES, HW55ES
56 CAT5_AUTO_FULL(5, "AutoFull", new byte[] { 0x00, 0x02 }),
57 CAT5_AUTO_LIMITED(5, "AutoLimited", new byte[] { 0x00, 0x03 }),
58 CAT5_MANUAL(5, "Manual", new byte[] { 0x00, 0x01 }),
59 CAT5_OFF(5, "Off", new byte[] { 0x00, 0x00 });
63 private byte[] dataCode;
68 * @param category a category of projector models for which the iris mode is available
69 * @param name the name of the iris mode
70 * @param dataCode the data code identifying the iris mode
72 private SonyProjectorIrisMode(int category, String name, byte[] dataCode) {
73 this.category = category;
75 this.dataCode = dataCode;
79 * Get the category of projector models for the current iris mode
81 * @return the category of projector models
83 public int getCategory() {
88 * Get the data code identifying the current iris mode
90 * @return the data code
92 public byte[] getDataCode() {
97 * Get the name of the current iris mode
101 public String getName() {
106 * Get the list of {@link StateOption} associated to the available iris modes for a particular category of projector
109 * @param category a category of projector models
111 * @return the list of {@link StateOption} associated to the available iris modes for a provided category of
114 public static List<StateOption> getStateOptions(int category) {
115 List<StateOption> options = new ArrayList<>();
116 for (SonyProjectorIrisMode value : SonyProjectorIrisMode.values()) {
117 if (value.getCategory() == category) {
118 options.add(new StateOption(value.getName(), value.getName()));
125 * Get the iris mode associated to a name for a particular category of projector models
127 * @param category a category of projector models
128 * @param name the name used to identify the iris mode
130 * @return the iris mode associated to the searched name for the provided category of projector models
132 * @throws SonyProjectorException - If no iris mode is associated to the searched name for the provided category
134 public static SonyProjectorIrisMode getFromName(int category, String name) throws SonyProjectorException {
135 for (SonyProjectorIrisMode value : SonyProjectorIrisMode.values()) {
136 if (value.getCategory() == category && value.getName().equals(name)) {
140 throw new SonyProjectorException("Invalid name for an iris mode: " + name);
144 * Get the iris mode associated to a data code for a particular category of projector models
146 * @param category a category of projector models
147 * @param dataCode the data code used to identify the iris mode
149 * @return the iris mode associated to the searched data code for the provided category of projector models
151 * @throws SonyProjectorException - If no iris mode is associated to the searched data code for the provided
154 public static SonyProjectorIrisMode getFromDataCode(int category, byte[] dataCode) throws SonyProjectorException {
155 for (SonyProjectorIrisMode value : SonyProjectorIrisMode.values()) {
156 if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
160 throw new SonyProjectorException("Invalid data code for an iris mode: " + HexUtils.bytesToHex(dataCode));