]> git.basschouten.com Git - openhab-addons.git/blob
74945409bbad743f2e31084e917f121f2e6c08af
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.nuvo.internal.communication;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19
20 /**
21  * Provides mapping of various Nuvo status codes to plain language meanings
22  *
23  * @author Michael Lobstein - Initial contribution
24  */
25
26 @NonNullByDefault
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";
33
34     // map to lookup play mode
35     public static final Map<String, String> PLAY_MODE = new HashMap<>();
36     static {
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", "unknown-9");
47         PLAY_MODE.put("10", "unknown-10");
48         PLAY_MODE.put("11", "Radio"); // undocumented
49         PLAY_MODE.put("12", "unknown-12");
50     }
51
52     /*
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
58      */
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)) {
64             return ZERO;
65         } else if (value.substring(0, 1).equals(R)) {
66             return (DASH + value.substring(1));
67         }
68         return ZERO;
69     }
70
71     // see above comment
72     public static String getBalanceFromInt(Integer value) {
73         if (value < 0) {
74             return (L + Math.abs(value));
75         } else if (value == 0) {
76             return C;
77         } else if (value > 0) {
78             return (R + value);
79         }
80         return C;
81     }
82 }