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.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;
25 * Represents all valid command types which could be processed by this
28 * @author Pauli Anttila - Initial contribution
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),;
61 private final String text;
62 private Class<? extends Item> itemClass;
64 private EpsonProjectorCommandType(final String text, Class<? extends Item> itemClass) {
66 this.itemClass = itemClass;
70 public String toString() {
74 public Class<? extends Item> getItemClass() {
79 * Procedure to validate command type string.
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.
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)) {
96 throw new InvalidClassException("Not valid class for command type");
101 throw new IllegalArgumentException("Not valid command type");
105 * Procedure to convert command type string to command type class.
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.
113 public static EpsonProjectorCommandType getCommandType(String commandTypeText) throws IllegalArgumentException {
114 for (EpsonProjectorCommandType c : EpsonProjectorCommandType.values()) {
115 if (c.text.equalsIgnoreCase(commandTypeText)) {
120 throw new IllegalArgumentException("Not valid command type");