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 lamp control modes available for the projector
27 * @author Laurent Garnier - Initial contribution
30 public enum SonyProjectorLampControl {
32 HIGH("High", new byte[] { 0x00, 0x01 }),
33 LOW("Low", new byte[] { 0x00, 0x00 });
36 private byte[] dataCode;
41 * @param name the name of the lamp control mode
42 * @param dataCode the data code identifying the lamp control mode
44 private SonyProjectorLampControl(String name, byte[] dataCode) {
46 this.dataCode = dataCode;
50 * Get the data code identifying the current lamp control mode
52 * @return the data code
54 public byte[] getDataCode() {
59 * Get the name of the current lamp control mode
63 public String getName() {
68 * Get the list of {@link StateOption} associated to the available lamp control modes
70 * @return the list of {@link StateOption} associated to the available lamp control modes
72 public static List<StateOption> getStateOptions() {
73 List<StateOption> options = new ArrayList<>();
74 for (SonyProjectorLampControl value : SonyProjectorLampControl.values()) {
75 options.add(new StateOption(value.getName(), value.getName()));
81 * Get the lamp control mode associated to a name
83 * @param name the name used to identify the lamp control mode
85 * @return the lamp control mode associated to the searched name
87 * @throws SonyProjectorException - If no lamp control mode is associated to the searched name
89 public static SonyProjectorLampControl getFromName(String name) throws SonyProjectorException {
90 for (SonyProjectorLampControl value : SonyProjectorLampControl.values()) {
91 if (value.getName().equals(name)) {
95 throw new SonyProjectorException("Invalid name for a lamp control mode: " + name);
99 * Get the lamp control mode associated to a data code
101 * @param dataCode the data code used to identify the lamp control mode
103 * @return the lamp control mode associated to the searched data code
105 * @throws SonyProjectorException - If no lamp control mode is associated to the searched data code
107 public static SonyProjectorLampControl getFromDataCode(byte[] dataCode) throws SonyProjectorException {
108 for (SonyProjectorLampControl value : SonyProjectorLampControl.values()) {
109 if (Arrays.equals(dataCode, value.getDataCode())) {
113 throw new SonyProjectorException("Invalid data code for a lamp control mode: " + HexUtils.bytesToHex(dataCode));