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.heos.internal.json.dto;
15 import java.util.stream.Stream;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
20 * Enum for the different documented error for HEOS responses
22 * @author Martin van Wingerden - Initial contribution
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");
44 private final int errorNumber;
45 private final String msg;
47 HeosErrorCode(int errorNumber, String msg) {
48 this.errorNumber = errorNumber;
53 public String toString() {
54 return String.format("#%d: %s", errorNumber, msg);
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"));