2 * Copyright (c) 2010-2022 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.pjlinkdevice.internal.device.command.input;
15 import java.util.regex.Pattern;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.pjlinkdevice.internal.device.command.ResponseException;
22 * Describes an A/V source that can be selected on the PJLink device.
24 * @author Nils Schnabel - Initial contribution
29 private static final Pattern INPUT_NUMBER_PATTERN = Pattern.compile("[0-9A-Z]");
34 DIGITAL("Digital", '3'),
35 STORAGE("Storage", '4'),
36 NETWORK("Network", '5');
41 private InputType(String text, char code) {
46 public String getText() {
50 public static InputType parseString(String value) throws ResponseException {
51 for (InputType result : InputType.values()) {
52 if (result.code == value.charAt(0)) {
57 throw new ResponseException("Unknown input channel type: " + value);
63 public Input(String value) throws ResponseException {
69 public int hashCode() {
72 result = prime * result + value.hashCode();
77 public boolean equals(@Nullable Object obj) {
84 if (getClass() != obj.getClass()) {
87 Input other = (Input) obj;
88 if (!value.equals(other.value)) {
94 public InputType getInputType() throws ResponseException {
95 return InputType.parseString(this.value);
98 public String getInputNumber() throws ResponseException {
99 String inputNumber = this.value.substring(1, 2);
100 if (!INPUT_NUMBER_PATTERN.matcher(inputNumber).matches()) {
101 throw new ResponseException("Illegal channel number: " + inputNumber);
107 public void validate() throws ResponseException {
108 if (this.value.length() != 2) {
109 throw new ResponseException("Illegal input description: " + value);
111 // these method also validate
116 public String getValue() {
120 public String getPJLinkRepresentation() {
124 public String getText() throws ResponseException {
125 return getInputType().getText() + " " + getInputNumber();