2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.epsonprojector.internal;
15 import java.io.InvalidClassException;
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;
24 * Represents all valid command types which could be processed by this
27 * @author Pauli Anttila - Initial contribution
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", StringItem.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),;
60 private final String text;
61 private Class<? extends Item> itemClass;
63 private EpsonProjectorCommandType(final String text, Class<? extends Item> itemClass) {
65 this.itemClass = itemClass;
69 public String toString() {
73 public Class<? extends Item> getItemClass() {
78 * Procedure to validate command type string.
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.
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)) {
95 throw new InvalidClassException("Not valid class for command type");
100 throw new IllegalArgumentException("Not valid command type");
104 * Procedure to convert command type string to command type class.
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.
112 public static EpsonProjectorCommandType getCommandType(String commandTypeText) throws IllegalArgumentException {
113 for (EpsonProjectorCommandType c : EpsonProjectorCommandType.values()) {
114 if (c.text.equalsIgnoreCase(commandTypeText)) {
119 throw new IllegalArgumentException("Not valid command type");