2 * Copyright (c) 2010-2022 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 block noise reduction modes available for the projector
27 * @author Laurent Garnier - Initial contribution
30 public enum SonyProjectorBlockNr {
32 HIGH("High", new byte[] { 0x00, 0x03 }),
33 MIDDLE("Middle", new byte[] { 0x00, 0x02 }),
34 LOW("Low", new byte[] { 0x00, 0x01 }),
35 OFF("Off", new byte[] { 0x00, 0x00 });
38 private byte[] dataCode;
43 * @param name the name of the block noise reduction mode
44 * @param dataCode the data code identifying the block noise reduction mode
46 private SonyProjectorBlockNr(String name, byte[] dataCode) {
48 this.dataCode = dataCode;
52 * Get the data code identifying the current block noise reduction mode
54 * @return the data code
56 public byte[] getDataCode() {
61 * Get the name of the current block noise reduction mode
65 public String getName() {
70 * Get the list of {@link StateOption} associated to the available block noise reduction modes
72 * @return the list of {@link StateOption} associated to the available block noise reduction modes
74 public static List<StateOption> getStateOptions() {
75 List<StateOption> options = new ArrayList<>();
76 for (SonyProjectorBlockNr value : SonyProjectorBlockNr.values()) {
77 options.add(new StateOption(value.getName(), value.getName()));
83 * Get the block noise reduction mode associated to a name
85 * @param name the name used to identify the block noise reduction mode
87 * @return the block noise reduction mode associated to the searched name
89 * @throws SonyProjectorException - If no block noise reduction mode is associated to the searched name
91 public static SonyProjectorBlockNr getFromName(String name) throws SonyProjectorException {
92 for (SonyProjectorBlockNr value : SonyProjectorBlockNr.values()) {
93 if (value.getName().equals(name)) {
97 throw new SonyProjectorException("Invalid name for a block noise reduction mode: " + name);
101 * Get the block noise reduction mode associated to a data code
103 * @param dataCode the data code used to identify the block noise reduction mode
105 * @return the block noise reduction mode associated to the searched data code
107 * @throws SonyProjectorException - If no block noise reduction mode is associated to the searched data code
109 public static SonyProjectorBlockNr getFromDataCode(byte[] dataCode) throws SonyProjectorException {
110 for (SonyProjectorBlockNr value : SonyProjectorBlockNr.values()) {
111 if (Arrays.equals(dataCode, value.getDataCode())) {
115 throw new SonyProjectorException(
116 "Invalid data code for a block noise reduction mode: " + HexUtils.bytesToHex(dataCode));