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 sensitivities available for the projector
27 * @author Laurent Garnier - Initial contribution
30 public enum SonyProjectorIrisSensitivity {
32 RECOMMEND("Recommend", new byte[] { 0x00, 0x00 }),
33 FAST("Fast", new byte[] { 0x00, 0x01 }),
34 SLOW("Slow", new byte[] { 0x00, 0x02 });
37 private byte[] dataCode;
42 * @param name the name of the iris sensitivity
43 * @param dataCode the data code identifying the iris sensitivity
45 private SonyProjectorIrisSensitivity(String name, byte[] dataCode) {
47 this.dataCode = dataCode;
51 * Get the data code identifying the current iris sensitivity
53 * @return the data code
55 public byte[] getDataCode() {
60 * Get the name of the current iris sensitivity
64 public String getName() {
69 * Get the list of {@link StateOption} associated to the available iris sensitivities
71 * @return the list of {@link StateOption} associated to the available iris sensitivities
73 public static List<StateOption> getStateOptions() {
74 List<StateOption> options = new ArrayList<>();
75 for (SonyProjectorIrisSensitivity value : SonyProjectorIrisSensitivity.values()) {
76 options.add(new StateOption(value.getName(), value.getName()));
82 * Get the iris sensitivity associated to a name
84 * @param name the name used to identify the iris sensitivity
86 * @return the iris sensitivity associated to the searched name
88 * @throws SonyProjectorException - If no iris sensitivity is associated to the searched name
90 public static SonyProjectorIrisSensitivity getFromName(String name) throws SonyProjectorException {
91 for (SonyProjectorIrisSensitivity value : SonyProjectorIrisSensitivity.values()) {
92 if (value.getName().equals(name)) {
96 throw new SonyProjectorException("Invalid name for an iris sensitivity: " + name);
100 * Get the iris sensitivity associated to a data code
102 * @param dataCode the data code used to identify the iris sensitivity
104 * @return the iris sensitivity associated to the searched data code
106 * @throws SonyProjectorException - If no iris sensitivity is associated to the searched data code
108 public static SonyProjectorIrisSensitivity getFromDataCode(byte[] dataCode) throws SonyProjectorException {
109 for (SonyProjectorIrisSensitivity value : SonyProjectorIrisSensitivity.values()) {
110 if (Arrays.equals(dataCode, value.getDataCode())) {
114 throw new SonyProjectorException("Invalid data code for an iris sensitivity: " + HexUtils.bytesToHex(dataCode));