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.errorstatus;
15 import java.util.Arrays;
16 import java.util.HashMap;
17 import java.util.HashSet;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.pjlinkdevice.internal.device.command.ErrorCode;
22 import org.openhab.binding.pjlinkdevice.internal.device.command.PrefixedResponse;
23 import org.openhab.binding.pjlinkdevice.internal.device.command.ResponseException;
26 * The response part of {@link ErrorStatusQueryCommand}
28 * @author Nils Schnabel - Initial contribution
31 public class ErrorStatusQueryResponse extends
32 PrefixedResponse<Map<ErrorStatusQueryResponse.ErrorStatusDevicePart, ErrorStatusQueryResponse.ErrorStatusQueryResponseState>> {
34 public enum ErrorStatusQueryResponseState {
35 OK_UNKOWN("OK/no failure detection", "0"),
36 WARNING("Warning", "1"),
42 private ErrorStatusQueryResponseState(String text, String code) {
47 public String getText() {
51 public static ErrorStatusQueryResponseState parseString(String code) throws ResponseException {
52 for (ErrorStatusQueryResponseState result : ErrorStatusQueryResponseState.values()) {
53 if (result.code.equals(code)) {
58 throw new ResponseException("Cannot understand error status: " + code);
62 public enum ErrorStatusDevicePart {
63 FAN("Fan error", "FanError", 0),
64 LAMP("Lamp error", "LampError", 1),
65 TEMPERATURE("Temperature error", "TemperatureError", 2),
66 COVER_OPEN("Cover open error", "CoverOpenError", 3),
67 FILTER("Filter error", "FilterError", 4),
68 OTHER("Other errors", "OtherErrors", 5);
71 private String camelCaseText;
72 private int positionInResponse;
74 private ErrorStatusDevicePart(String text, String camelCaseText, int positionInResponse) {
76 this.camelCaseText = camelCaseText;
77 this.positionInResponse = positionInResponse;
80 public String getText() {
84 public String getCamelCaseText() {
85 return this.camelCaseText;
88 public static ErrorStatusDevicePart getDevicePartByResponsePosition(int pos) {
89 for (ErrorStatusDevicePart result : ErrorStatusDevicePart.values()) {
90 if (result.positionInResponse == pos) {
99 private static final HashSet<ErrorCode> SPECIFIED_ERRORCODES = new HashSet<>(
100 Arrays.asList(ErrorCode.UNAVAILABLE_TIME, ErrorCode.DEVICE_FAILURE));
102 public ErrorStatusQueryResponse(String response) throws ResponseException {
103 super("ERST=", SPECIFIED_ERRORCODES, response);
107 protected Map<ErrorStatusDevicePart, ErrorStatusQueryResponseState> parseResponseWithoutPrefix(
108 String responseWithoutPrefix) throws ResponseException {
109 Map<ErrorStatusDevicePart, ErrorStatusQueryResponseState> result = new HashMap<>();
110 for (int i = 0; i < ErrorStatusDevicePart.values().length; i++) {
111 result.put(ErrorStatusDevicePart.getDevicePartByResponsePosition(i),
112 ErrorStatusQueryResponseState.parseString(responseWithoutPrefix.substring(i, i + 1)));