]> git.basschouten.com Git - openhab-addons.git/blob
abd92767cdb2392287a7162b3fbee82fd56d85a2
[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.benqprojector.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.core.items.Item;
17 import org.openhab.core.library.items.NumberItem;
18 import org.openhab.core.library.items.StringItem;
19 import org.openhab.core.library.items.SwitchItem;
20
21 /**
22  * Represents all valid command types which could be processed by this
23  * binding.
24  *
25  * @author Michael Lobstein - Initial contribution
26  */
27 @NonNullByDefault
28 public enum BenqProjectorCommandType {
29     POWER("power", SwitchItem.class),
30     SOURCE("source", StringItem.class),
31     PICTURE_MODE("picturemode", StringItem.class),
32     ASPECT_RATIO("aspectratio", StringItem.class),
33     FREEZE("freeze", SwitchItem.class),
34     BLANK("blank", SwitchItem.class),
35     DIRECTCMD("directcmd", StringItem.class),
36     LAMP_TIME("lamptime", NumberItem.class);
37
38     private final String text;
39     private Class<? extends Item> itemClass;
40
41     private BenqProjectorCommandType(final String text, Class<? extends Item> itemClass) {
42         this.text = text;
43         this.itemClass = itemClass;
44     }
45
46     @Override
47     public String toString() {
48         return text;
49     }
50
51     public Class<? extends Item> getItemClass() {
52         return itemClass;
53     }
54
55     /**
56      * Procedure to convert command type string to command type class.
57      *
58      * @param commandTypeText
59      *            command string e.g. RawData, Command, Brightness
60      * @return corresponding command type.
61      * @throws IllegalArgumentException
62      *             No valid class for command type.
63      */
64     public static BenqProjectorCommandType getCommandType(String commandTypeText) throws IllegalArgumentException {
65         for (BenqProjectorCommandType c : BenqProjectorCommandType.values()) {
66             if (c.text.equals(commandTypeText)) {
67                 return c;
68             }
69         }
70
71         throw new IllegalArgumentException("Not valid command type: " + commandTypeText);
72     }
73 }