2 * Copyright (c) 2010-2023 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();
76 @SuppressWarnings("PMD.SimplifyBooleanReturns")
78 public boolean equals(@Nullable Object obj) {
85 if (getClass() != obj.getClass()) {
88 Input other = (Input) obj;
89 if (!value.equals(other.value)) {
95 public InputType getInputType() throws ResponseException {
96 return InputType.parseString(this.value);
99 public String getInputNumber() throws ResponseException {
100 String inputNumber = this.value.substring(1, 2);
101 if (!INPUT_NUMBER_PATTERN.matcher(inputNumber).matches()) {
102 throw new ResponseException("Illegal channel number: " + inputNumber);
108 public void validate() throws ResponseException {
109 if (this.value.length() != 2) {
110 throw new ResponseException("Illegal input description: " + value);
112 // these method also validate
117 public String getValue() {
121 public String getPJLinkRepresentation() {
125 public String getText() throws ResponseException {
126 return getInputType().getText() + " " + getInputNumber();