]> git.basschouten.com Git - openhab-addons.git/blob
774d2cc08526c2756740020dd0151cae5ed789a1
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.epsonprojector.internal;
14
15 import java.io.InvalidClassException;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.core.items.Item;
19 import org.openhab.core.library.items.NumberItem;
20 import org.openhab.core.library.items.StringItem;
21 import org.openhab.core.library.items.SwitchItem;
22
23 /**
24  * Represents all valid command types which could be processed by this
25  * binding.
26  *
27  * @author Pauli Anttila - Initial contribution
28  */
29 @NonNullByDefault
30 public enum EpsonProjectorCommandType {
31     POWER("Power", SwitchItem.class),
32     POWER_STATE("PowerState", StringItem.class),
33     LAMP_TIME("LampTime", NumberItem.class),
34     KEY_CODE("KeyCode", NumberItem.class),
35     VKEYSTONE("VerticalKeystone", NumberItem.class),
36     HKEYSTONE("HorizontalKeystone", NumberItem.class),
37     AKEYSTONE("AutoKeystone", SwitchItem.class),
38     FREEZE("Freeze", SwitchItem.class),
39     ASPECT_RATIO("AspectRatio", StringItem.class),
40     LUMINANCE("Luminance", StringItem.class),
41     SOURCE("Source", StringItem.class),
42     BRIGHTNESS("Brightness", NumberItem.class),
43     CONTRAST("Contrast", NumberItem.class),
44     DENSITY("Density", NumberItem.class),
45     TINT("Tint", NumberItem.class),
46     COLOR_TEMP("ColorTemperature", NumberItem.class),
47     FLESH_TEMP("FleshTemperature", NumberItem.class),
48     COLOR_MODE("ColorMode", StringItem.class),
49     HPOSITION("HorizontalPosition", NumberItem.class),
50     VPOSITION("VerticalPosition", NumberItem.class),
51     GAMMA("Gamma", StringItem.class),
52     VOLUME("Volume", NumberItem.class),
53     MUTE("Mute", SwitchItem.class),
54     HREVERSE("HorizontalReverse", SwitchItem.class),
55     VREVERSE("VerticalReverse", SwitchItem.class),
56     BACKGROUND("Background", StringItem.class),
57     ERR_CODE("ErrCode", NumberItem.class),
58     ERR_MESSAGE("ErrMessage", StringItem.class),;
59
60     private final String text;
61     private Class<? extends Item> itemClass;
62
63     private EpsonProjectorCommandType(final String text, Class<? extends Item> itemClass) {
64         this.text = text;
65         this.itemClass = itemClass;
66     }
67
68     @Override
69     public String toString() {
70         return text;
71     }
72
73     public Class<? extends Item> getItemClass() {
74         return itemClass;
75     }
76
77     /**
78      * Procedure to validate command type string.
79      *
80      * @param commandTypeText
81      *            command string e.g. RawData, Command, Brightness
82      * @return true if item is valid.
83      * @throws IllegalArgumentException
84      *             Not valid command type.
85      * @throws InvalidClassException
86      *             Not valid class for command type.
87      */
88     public static boolean validateBinding(String commandTypeText, Class<? extends Item> itemClass)
89             throws IllegalArgumentException, InvalidClassException {
90         for (EpsonProjectorCommandType c : EpsonProjectorCommandType.values()) {
91             if (c.text.equalsIgnoreCase(commandTypeText)) {
92                 if (c.getItemClass().equals(itemClass)) {
93                     return true;
94                 } else {
95                     throw new InvalidClassException("Not valid class for command type");
96                 }
97             }
98         }
99
100         throw new IllegalArgumentException("Not valid command type");
101     }
102
103     /**
104      * Procedure to convert command type string to command type class.
105      *
106      * @param commandTypeText
107      *            command string e.g. RawData, Command, Brightness
108      * @return corresponding command type.
109      * @throws InvalidClassException
110      *             Not valid class for command type.
111      */
112     public static EpsonProjectorCommandType getCommandType(String commandTypeText) throws IllegalArgumentException {
113         for (EpsonProjectorCommandType c : EpsonProjectorCommandType.values()) {
114             if (c.text.equalsIgnoreCase(commandTypeText)) {
115                 return c;
116             }
117         }
118
119         throw new IllegalArgumentException("Not valid command type");
120     }
121 }