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;
15 import java.text.MessageFormat;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
22 * Error codes as specified in <a href="https://pjlink.jbmia.or.jp/english/data_cl2/PJLink_5-1.pdf">[PJLinkSpec]</a>
27 * @author Nils Schnabel - Initial contribution
30 public enum ErrorCode {
31 UNDEFINED_COMMAND("Undefined command", "ERR1"),
32 OUT_OF_PARAMETER("Out of parameter", "ERR2"),
33 UNAVAILABLE_TIME("Unavailable time", "ERR3"),
34 DEVICE_FAILURE("Projector/Display failure", "ERR4");
39 private ErrorCode(String text, String code) {
44 public static @Nullable ErrorCode getValueForCode(String code) {
45 for (ErrorCode result : ErrorCode.values()) {
46 if (result.code.equalsIgnoreCase(code)) {
54 public String getText() {
59 * Checks if a the given code is an error code. Optionally, restrictCodesTo can restrict the allowed error codes
60 * (based on PJLink specification).
62 * @param code string to be checked for error codes
63 * @param restrictCodesTo list of expected error codes according to PJLink specification, can be null if all error
64 * codes (ERR1-ERR4) can be expected
65 * @throws ResponseException
67 public static void checkForErrorStatus(String code, @Nullable Set<ErrorCode> restrictCodesTo)
68 throws ResponseException {
69 ErrorCode parsed = getValueForCode(code);
70 if (parsed != null && (restrictCodesTo == null || restrictCodesTo.contains(parsed))) {
71 throw new ResponseException(MessageFormat.format("Got error status {0} ({1})", parsed.getText(), code));