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 film projection modes available for the projector
28 * @author Laurent Garnier - Initial contribution
31 public enum SonyProjectorFilmProjection {
33 // Category 1: VW80, VW85, VW200
34 CAT1_MODE1(1, "Mode1", "Mode 1", new byte[] { 0x00, 0x01 }),
35 CAT1_MODE2(1, "Mode2", "Mode 2", new byte[] { 0x00, 0x02 }),
36 CAT1_MODE3(1, "Mode3", "Mode 3", new byte[] { 0x00, 0x03 }),
37 CAT1_OFF(1, "Off", null, new byte[] { 0x00, 0x00 }),
39 // Category 2: VW90, VW95
40 CAT2_MODE1(2, "Mode1", "Mode 1", new byte[] { 0x00, 0x01 }),
41 CAT2_MODE2(2, "Mode2", "Mode 2", new byte[] { 0x00, 0x02 }),
42 CAT2_OFF(2, "Off", null, new byte[] { 0x00, 0x00 }),
44 // Category 3: VW1000ES, VW1100ES, HW35ES, HW40ES, HW50ES, HW55ES, HW58ES
45 CAT3_ON(3, "On", null, new byte[] { 0x00, 0x01 }),
46 CAT3_OFF(3, "Off", null, new byte[] { 0x00, 0x00 });
50 private @Nullable String label;
51 private byte[] dataCode;
56 * @param category a category of projector models for which the film projection mode is available
57 * @param name the name of the film projection mode
58 * @param label the label of the film projection mode; can be null when the label is identical to the name
59 * @param dataCode the data code identifying the film projection mode
61 private SonyProjectorFilmProjection(int category, String name, @Nullable String label, byte[] dataCode) {
62 this.category = category;
65 this.dataCode = dataCode;
69 * Get the category of projector models for the current film projection mode
71 * @return the category of projector models
73 public int getCategory() {
78 * Get the data code identifying the current film projection mode
80 * @return the data code
82 public byte[] getDataCode() {
87 * Get the label of the current film projection mode
91 public @Nullable String getLabel() {
96 * Get the name of the current film projection mode
100 public String getName() {
105 * Get the list of {@link StateOption} associated to the available film projection modes for a particular category
106 * of projector models
108 * @param category a category of projector models
110 * @return the list of {@link StateOption} associated to the available film projection modes for a provided category
111 * of projector models
113 public static List<StateOption> getStateOptions(int category) {
114 List<StateOption> options = new ArrayList<>();
115 for (SonyProjectorFilmProjection value : SonyProjectorFilmProjection.values()) {
116 if (value.getCategory() == category) {
117 options.add(new StateOption(value.getName(),
118 value.getLabel() != null ? value.getLabel() : value.getName()));
125 * Get the film projection 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 film projection mode
130 * @return the film projection mode associated to the searched name for the provided category of projector models
132 * @throws SonyProjectorException - If no film projection mode is associated to the searched name for the provided
135 public static SonyProjectorFilmProjection getFromName(int category, String name) throws SonyProjectorException {
136 for (SonyProjectorFilmProjection value : SonyProjectorFilmProjection.values()) {
137 if (value.getCategory() == category && value.getName().equals(name)) {
141 throw new SonyProjectorException("Invalid name for a film projection mode: " + name);
145 * Get the film projection mode associated to a data code for a particular category of projector models
147 * @param category a category of projector models
148 * @param dataCode the data code used to identify the film projection mode
150 * @return the film projection mode associated to the searched data code for the provided category of projector
153 * @throws SonyProjectorException - If no film projection mode is associated to the searched data code for the
156 public static SonyProjectorFilmProjection getFromDataCode(int category, byte[] dataCode)
157 throws SonyProjectorException {
158 for (SonyProjectorFilmProjection value : SonyProjectorFilmProjection.values()) {
159 if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
163 throw new SonyProjectorException(
164 "Invalid data code for a film projection mode: " + HexUtils.bytesToHex(dataCode));