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.benqprojector.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 Michael Lobstein - Initial contribution
30 public enum BenqProjectorCommandType {
31 POWER("Power", SwitchItem.class),
32 SOURCE("Source", StringItem.class),
33 PICTURE_MODE("PictureMode", StringItem.class),
34 ASPECT_RATIO("AspectRatio", StringItem.class),
35 FREEZE("Freeze", SwitchItem.class),
36 BLANK("Blank", SwitchItem.class),
37 DIRECTCMD("DirectCmd", StringItem.class),
38 LAMP_TIME("LampTime", NumberItem.class);
40 private final String text;
41 private Class<? extends Item> itemClass;
43 private BenqProjectorCommandType(final String text, Class<? extends Item> itemClass) {
45 this.itemClass = itemClass;
49 public String toString() {
53 public Class<? extends Item> getItemClass() {
58 * Procedure to validate command type string.
60 * @param commandTypeText
61 * command string e.g. RawData, Command, Brightness
62 * @return true if item is valid.
63 * @throws IllegalArgumentException
64 * Not valid command type.
65 * @throws InvalidClassException
66 * Not valid class for command type.
68 public static boolean validateBinding(String commandTypeText, Class<? extends Item> itemClass)
69 throws IllegalArgumentException, InvalidClassException {
70 for (BenqProjectorCommandType c : BenqProjectorCommandType.values()) {
71 if (c.text.equalsIgnoreCase(commandTypeText)) {
72 if (c.getItemClass().equals(itemClass)) {
75 throw new InvalidClassException("Not valid class for command type");
80 throw new IllegalArgumentException("Not valid command type");
84 * Procedure to convert command type string to command type class.
86 * @param commandTypeText
87 * command string e.g. RawData, Command, Brightness
88 * @return corresponding command type.
89 * @throws InvalidClassException
90 * Not valid class for command type.
92 public static BenqProjectorCommandType getCommandType(String commandTypeText) throws IllegalArgumentException {
93 for (BenqProjectorCommandType c : BenqProjectorCommandType.values()) {
94 if (c.text.equalsIgnoreCase(commandTypeText)) {
99 throw new IllegalArgumentException("Not valid command type");