]> git.basschouten.com Git - openhab-addons.git/blob
41c5b2f47a0d32aac3ebb42f41544a4af9496448
[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.rotel.internal.protocol;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.rotel.internal.RotelException;
17
18 /**
19  * Represents the different kinds of protocols
20  *
21  * @author Laurent Garnier - Initial contribution
22  */
23 @NonNullByDefault
24 public enum RotelProtocol {
25
26     HEX("HEX"),
27     ASCII_V1("ASCII_V1"),
28     ASCII_V2("ASCII_V2");
29
30     private String name;
31
32     /**
33      * Constructor
34      *
35      * @param name the protocol name
36      */
37     private RotelProtocol(String name) {
38         this.name = name;
39     }
40
41     /**
42      * Get the protocol name
43      *
44      * @return the protocol name
45      */
46     public String getName() {
47         return name;
48     }
49
50     /**
51      * Get the protocol associated to a name
52      *
53      * @param name the name used to identify the protocol
54      *
55      * @return the protocol associated to the searched name
56      *
57      * @throws RotelException - If no protocol is associated to the searched name
58      */
59     public static RotelProtocol getFromName(String name) throws RotelException {
60         for (RotelProtocol value : RotelProtocol.values()) {
61             if (value.getName().equals(name)) {
62                 return value;
63             }
64         }
65         throw new RotelException("Invalid protocol name: " + name);
66     }
67 }