]> git.basschouten.com Git - openhab-addons.git/blob
f738eec7e29ed3a08d360f419969273747a9df63
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.sonyprojector.internal.communication;
14
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.List;
18
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;
23
24 /**
25  * Represents the different iris sensitivities available for the projector
26  *
27  * @author Laurent Garnier - Initial contribution
28  */
29 @NonNullByDefault
30 public enum SonyProjectorIrisSensitivity {
31
32     RECOMMEND("Recommend", new byte[] { 0x00, 0x00 }),
33     FAST("Fast", new byte[] { 0x00, 0x01 }),
34     SLOW("Slow", new byte[] { 0x00, 0x02 });
35
36     private String name;
37     private byte[] dataCode;
38
39     /**
40      * Constructor
41      *
42      * @param name the name of the iris sensitivity
43      * @param dataCode the data code identifying the iris sensitivity
44      */
45     private SonyProjectorIrisSensitivity(String name, byte[] dataCode) {
46         this.name = name;
47         this.dataCode = dataCode;
48     }
49
50     /**
51      * Get the data code identifying the current iris sensitivity
52      *
53      * @return the data code
54      */
55     public byte[] getDataCode() {
56         return dataCode;
57     }
58
59     /**
60      * Get the name of the current iris sensitivity
61      *
62      * @return the name
63      */
64     public String getName() {
65         return name;
66     }
67
68     /**
69      * Get the list of {@link StateOption} associated to the available iris sensitivities
70      *
71      * @return the list of {@link StateOption} associated to the available iris sensitivities
72      */
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()));
77         }
78         return options;
79     }
80
81     /**
82      * Get the iris sensitivity associated to a name
83      *
84      * @param name the name used to identify the iris sensitivity
85      *
86      * @return the iris sensitivity associated to the searched name
87      *
88      * @throws SonyProjectorException - If no iris sensitivity is associated to the searched name
89      */
90     public static SonyProjectorIrisSensitivity getFromName(String name) throws SonyProjectorException {
91         for (SonyProjectorIrisSensitivity value : SonyProjectorIrisSensitivity.values()) {
92             if (value.getName().equals(name)) {
93                 return value;
94             }
95         }
96         throw new SonyProjectorException("Invalid name for an iris sensitivity: " + name);
97     }
98
99     /**
100      * Get the iris sensitivity associated to a data code
101      *
102      * @param dataCode the data code used to identify the iris sensitivity
103      *
104      * @return the iris sensitivity associated to the searched data code
105      *
106      * @throws SonyProjectorException - If no iris sensitivity is associated to the searched data code
107      */
108     public static SonyProjectorIrisSensitivity getFromDataCode(byte[] dataCode) throws SonyProjectorException {
109         for (SonyProjectorIrisSensitivity value : SonyProjectorIrisSensitivity.values()) {
110             if (Arrays.equals(dataCode, value.getDataCode())) {
111                 return value;
112             }
113         }
114         throw new SonyProjectorException("Invalid data code for an iris sensitivity: " + HexUtils.bytesToHex(dataCode));
115     }
116 }