]> git.basschouten.com Git - openhab-addons.git/blob
cb247eed6b0f2e728a34fda42edcac55497ebb9c
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.heos.internal.json.dto;
14
15 import java.util.stream.Stream;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18
19 /**
20  * Enum for the different documented error for HEOS responses
21  *
22  * @author Martin van Wingerden - Initial contribution
23  */
24 @NonNullByDefault
25 public enum HeosErrorCode {
26     UNRECOGNIZED_COMMAND(1, "Unrecognized Command"),
27     INVALID_ID(2, "Invalid ID"),
28     WRONG_NUMBER_OF_COMMAND_ARGUMENTS(3, "Wrong Number of Command Arguments"),
29     REQUESTED_DATA_NOT_AVAILABLE(4, "Requested data not available"),
30     RESOURCE_CURRENTLY_NOT_AVAILABLE(5, "Resource currently not available"),
31     INVALID_CREDENTIALS(6, "Invalid Credentials"),
32     COMMAND_COULD_NOT_BE_EXECUTED(7, "Command Could Not Be Executed"),
33     USER_NOT_LOGGED_IN(8, "User not logged In"),
34     PARAMETER_OUT_OF_RANGE(9, "Parameter out of range"),
35     USER_NOT_FOUND(10, "User not found"),
36     INTERNAL_ERROR(11, "Internal Error"),
37     SYSTEM_ERROR(12, "System Error"),
38     PROCESSING_PREVIOUS_COMMAND(13, "Processing Previous Command"),
39     MEDIA_CANT_BE_PLAYED(14, "Media can't be played"),
40     OPTION_NO_SUPPORTED(15, "Option no supported"),
41     TOO_MANY_COMMANDS_IN_MESSAGE_QUEUE_TO_PROCESS(16, "Too many commands in message queue to process"),
42     REACHED_SKIP_LIMIT(17, "Reached skip limit");
43
44     private final int errorNumber;
45     private final String msg;
46
47     HeosErrorCode(int errorNumber, String msg) {
48         this.errorNumber = errorNumber;
49         this.msg = msg;
50     }
51
52     @Override
53     public String toString() {
54         return String.format("#%d: %s", errorNumber, msg);
55     }
56
57     public static HeosErrorCode of(long errorNumber) {
58         return Stream.of(values()).filter(v -> errorNumber == v.errorNumber).findAny()
59                 .orElseThrow(() -> new IllegalArgumentException("An unknown error " + errorNumber + " occurred"));
60     }
61 }