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