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 film projection modes available for the projector
27 * @author Laurent Garnier - Initial contribution
30 public enum SonyProjectorFilmProjection {
32 // Category 1: VW80, VW85, VW200
33 CAT1_MODE1(1, "Mode1", new byte[] { 0x00, 0x01 }),
34 CAT1_MODE2(1, "Mode2", new byte[] { 0x00, 0x02 }),
35 CAT1_MODE3(1, "Mode3", new byte[] { 0x00, 0x03 }),
36 CAT1_OFF(1, "Off", new byte[] { 0x00, 0x00 }),
38 // Category 2: VW90, VW95
39 CAT2_MODE1(2, "Mode1", new byte[] { 0x00, 0x01 }),
40 CAT2_MODE2(2, "Mode2", new byte[] { 0x00, 0x02 }),
41 CAT2_OFF(2, "Off", new byte[] { 0x00, 0x00 }),
43 // Category 3: VW1000ES, VW1100ES, HW35ES, HW40ES, HW50ES, HW55ES, HW58ES
44 CAT3_ON(3, "On", new byte[] { 0x00, 0x01 }),
45 CAT3_OFF(3, "Off", new byte[] { 0x00, 0x00 });
49 private byte[] dataCode;
54 * @param category a category of projector models for which the film projection mode is available
55 * @param name the name of the film projection mode
56 * @param dataCode the data code identifying the film projection mode
58 private SonyProjectorFilmProjection(int category, String name, byte[] dataCode) {
59 this.category = category;
61 this.dataCode = dataCode;
65 * Get the category of projector models for the current film projection mode
67 * @return the category of projector models
69 public int getCategory() {
74 * Get the data code identifying the current film projection mode
76 * @return the data code
78 public byte[] getDataCode() {
83 * Get the name of the current film projection mode
87 public String getName() {
92 * Get the list of {@link StateOption} associated to the available film projection modes for a particular category
95 * @param category a category of projector models
97 * @return the list of {@link StateOption} associated to the available film projection modes for a provided category
100 public static List<StateOption> getStateOptions(int category) {
101 List<StateOption> options = new ArrayList<>();
102 for (SonyProjectorFilmProjection value : SonyProjectorFilmProjection.values()) {
103 if (value.getCategory() == category) {
104 options.add(new StateOption(value.getName(), value.getName()));
111 * Get the film projection mode associated to a name for a particular category of projector models
113 * @param category a category of projector models
114 * @param name the name used to identify the film projection mode
116 * @return the film projection mode associated to the searched name for the provided category of projector models
118 * @throws SonyProjectorException - If no film projection mode is associated to the searched name for the provided
121 public static SonyProjectorFilmProjection getFromName(int category, String name) throws SonyProjectorException {
122 for (SonyProjectorFilmProjection value : SonyProjectorFilmProjection.values()) {
123 if (value.getCategory() == category && value.getName().equals(name)) {
127 throw new SonyProjectorException("Invalid name for a film projection mode: " + name);
131 * Get the film projection mode associated to a data code for a particular category of projector models
133 * @param category a category of projector models
134 * @param dataCode the data code used to identify the film projection mode
136 * @return the film projection mode associated to the searched data code for the provided category of projector
139 * @throws SonyProjectorException - If no film projection mode is associated to the searched data code for the
142 public static SonyProjectorFilmProjection getFromDataCode(int category, byte[] dataCode)
143 throws SonyProjectorException {
144 for (SonyProjectorFilmProjection value : SonyProjectorFilmProjection.values()) {
145 if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
149 throw new SonyProjectorException(
150 "Invalid data code for a film projection mode: " + HexUtils.bytesToHex(dataCode));