2 * Copyright (c) 2010-2022 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.nuvo.internal.communication;
15 import java.util.HashMap;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
21 * Provides mapping of various Nuvo status codes to plain language meanings
23 * @author Michael Lobstein - Initial contribution
27 public class NuvoStatusCodes {
28 private static final String L = "L";
29 private static final String C = "C";
30 private static final String R = "R";
31 private static final String DASH = "-";
32 private static final String ZERO = "0";
34 // map to lookup play mode
35 public static final Map<String, String> PLAY_MODE = new HashMap<>();
37 PLAY_MODE.put("0", "Normal");
38 PLAY_MODE.put("1", "Idle");
39 PLAY_MODE.put("2", "Playing");
40 PLAY_MODE.put("3", "Paused");
41 PLAY_MODE.put("4", "Fast Forward");
42 PLAY_MODE.put("5", "Rewind");
43 PLAY_MODE.put("6", "Play Shuffle");
44 PLAY_MODE.put("7", "Play Repeat");
45 PLAY_MODE.put("8", "Play Shuffle Repeat");
46 PLAY_MODE.put("9", "Step Tune");
47 PLAY_MODE.put("10", "Seek Tune");
48 PLAY_MODE.put("11", "Preset Tune");
49 PLAY_MODE.put("12", "unknown-12");
53 * This looks broken because the controller is seriously broken...
54 * On the keypad when adjusting the balance to "Left 18", the serial data reports R18 ¯\_(ツ)_/¯
55 * So on top of the weird translation, the value needs to be reversed by the binding
56 * to ensure that it will match what is displayed on the keypad.
57 * For display purposes we want -18 to be full left, 0 = center, and +18 to be full right
59 public static String getBalanceFromStr(String value) {
60 // example L2; return 2 | C; return 0 | R10; return -10
61 if (value.substring(0, 1).equals(L)) {
62 return (value.substring(1));
63 } else if (value.equals(C)) {
65 } else if (value.substring(0, 1).equals(R)) {
66 return (DASH + value.substring(1));
72 public static String getBalanceFromInt(Integer value) {
74 return (L + Math.abs(value));
75 } else if (value == 0) {
77 } else if (value > 0) {