]> git.basschouten.com Git - openhab-addons.git/blob
018c0b66be2ad5206a4182034949d4381e47f59f
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.onkyo.internal.eiscp;
14
15 /**
16  * Represents all possible eISCP commands.
17  *
18  * @author Thomas.Eichstaedt-Engelen - initial contribution
19  * @author Pauli Anttila - add additional commands
20  * @author Paul Frank - update for openHAB 2
21  * @author Marcel Verpaalen - fix issues with some Zone 2 commands
22  */
23 public enum EiscpCommand {
24
25     // Main zone
26
27     POWER_QUERY("PWR", "QSTN"),
28     POWER_SET("PWR", "%02X"),
29     POWER("PWR", ""),
30
31     MUTE_QUERY("AMT", "QSTN"),
32     MUTE_SET("AMT", "%02X"),
33     MUTE("AMT", ""),
34
35     VOLUME_UP("MVL", "UP"),
36     VOLUME_DOWN("MVL", "DOWN"),
37     VOLUME_QUERY("MVL", "QSTN"),
38     VOLUME_SET("MVL", "%02X"),
39     VOLUME("MVL", ""),
40
41     SOURCE_UP("SLI", "UP"),
42     SOURCE_DOWN("SLI", "DOWN"),
43     SOURCE_QUERY("SLI", "QSTN"),
44     SOURCE_SET("SLI", "%02X"),
45     SOURCE("SLI", ""),
46
47     LISTEN_MODE_UP("LMD", "UP"),
48     LISTEN_MODE_DOWN("LMD", "DOWN"),
49     LISTEN_MODE_QUERY("LMD", "QSTN"),
50     LISTEN_MODE_SET("LMD", "%02X"),
51     LISTEN_MODE("LMD", ""),
52
53     INFO_QUERY("NRI", "QSTN"),
54     INFO("NRI", ""),
55
56     NETUSB_OP_PLAY("NTC", "PLAY"),
57     NETUSB_OP_STOP("NTC", "STOP"),
58     NETUSB_OP_PAUSE("NTC", "PAUSE"),
59     NETUSB_OP_TRACKUP("NTC", "TRUP"),
60     NETUSB_OP_TRACKDWN("NTC", "TRDN"),
61     NETUSB_OP_FF("NTC", "FF"),
62     NETUSB_OP_REW("NTC", "REW"),
63     NETUSB_OP_REPEAT("NTC", "REPEAT"),
64     NETUSB_OP_RANDOM("NTC", "RANDOM"),
65     NETUSB_OP_DISPLAY("NTC", "DISPLAY"),
66     NETUSB_OP_RIGHT("NTC", "RIGHT"),
67     NETUSB_OP_LEFT("NTC", "LEFT"),
68     NETUSB_OP_UP("NTC", "UP"),
69     NETUSB_OP_DOWN("NTC", "DOWN"),
70     NETUSB_OP_SELECT("NTC", "SELECT"),
71     NETUSB_OP_1("NTC", "1"),
72     NETUSB_OP_2("NTC", "2"),
73     NETUSB_OP_3("NTC", "3"),
74     NETUSB_OP_4("NTC", "4"),
75     NETUSB_OP_5("NTC", "5"),
76     NETUSB_OP_6("NTC", "6"),
77     NETUSB_OP_7("NTC", "7"),
78     NETUSB_OP_8("NTC", "8"),
79     NETUSB_OP_9("NTC", "9"),
80     NETUSB_OP_0("NTC", "0"),
81     NETUSB_OP_DELETE("NTC", "DELETE"),
82     NETUSB_OP_CAPS("NTC", "CAPS"),
83     NETUSB_OP_SETUP("NTC", "SETUP"),
84     NETUSB_OP_RETURN("NTC", "RETURN"),
85     NETUSB_OP_CHANUP("NTC", "CHUP"),
86     NETUSB_OP_CHANDWN("NTC", "CHDN"),
87     NETUSB_OP_MENU("NTC", "MENU"),
88     NETUSB_OP_TOPMENU("NTC", "TOP"),
89
90     NETUSB_SONG_ARTIST_QUERY("NAT", "QSTN"),
91     NETUSB_SONG_ARTIST("NAT", ""),
92     NETUSB_SONG_ALBUM_QUERY("NAL", "QSTN"),
93     NETUSB_SONG_ALBUM("NAL", ""),
94     NETUSB_SONG_TITLE_QUERY("NTI", "QSTN"),
95     NETUSB_SONG_TITLE("NTI", ""),
96     NETUSB_SONG_ELAPSEDTIME_QUERY("NTM", "QSTN"),
97     NETUSB_SONG_ELAPSEDTIME("NTM", ""),
98     NETUSB_SONG_TRACK_QUERY("NTR", "QSTN"),
99     NETUSB_SONG_TRACK("NTR", ""),
100     NETUSB_PLAY_STATUS_QUERY("NST", "QSTN"),
101     NETUSB_PLAY_STATUS("NST", ""),
102
103     NETUSB_MENU_SELECT("NLS", "L%X"),
104     NETUSB_MENU("NLS", ""),
105
106     NETUSB_TITLE("NLT", ""),
107     NETUSB_TITLE_QUERY("NLT", "QSTN"),
108
109     NETUSB_ALBUM_ART_QUERY("NJA", "REQ"),
110     NETUSB_ALBUM_ART("NJA", ""),
111
112     /*
113      * Zone 2
114      */
115
116     ZONE2_POWER_QUERY("ZPW", "QSTN"),
117     ZONE2_POWER_SET("ZPW", "%02X"),
118     ZONE2_POWER("ZPW", ""),
119
120     ZONE2_MUTE_QUERY("ZMT", "QSTN"),
121     ZONE2_MUTE_SET("ZMT", "%02X"),
122     ZONE2_MUTE("ZMT", ""),
123
124     ZONE2_VOLUME_UP("ZVL", "UP"),
125     ZONE2_VOLUME_DOWN("ZVL", "DOWN"),
126     ZONE2_VOLUME_QUERY("ZVL", "QSTN"),
127     ZONE2_VOLUME_SET("ZVL", "%02X"),
128     ZONE2_VOLUME("ZVL", ""),
129
130     ZONE2_SOURCE_UP("SLZ", "UP"),
131     ZONE2_SOURCE_DOWN("SLZ", "DOWN"),
132     ZONE2_SOURCE_QUERY("SLZ", "QSTN"),
133     ZONE2_SOURCE_SET("SLZ", "%02X"),
134     ZONE2_SOURCE("SLZ", ""),
135
136     /*
137      * Zone 3
138      */
139
140     ZONE3_POWER_QUERY("PW3", "QSTN"),
141     ZONE3_POWER_SET("PW3", "%02X"),
142     ZONE3_POWER("PW3", ""),
143
144     ZONE3_MUTE_QUERY("MT3", "QSTN"),
145     ZONE3_MUTE_SET("MT3", "%02X"),
146     ZONE3_MUTE("MT3", ""),
147
148     ZONE3_VOLUME_UP("VL3", "UP"),
149     ZONE3_VOLUME_DOWN("VL3", "DOWN"),
150     ZONE3_VOLUME_QUERY("VL3", "QSTN"),
151     ZONE3_VOLUME_SET("VL3", "%02X"),
152     ZONE3_VOLUME("VL3", ""),
153
154     ZONE3_SOURCE_UP("SL3", "UP"),
155     ZONE3_SOURCE_DOWN("SL3", "DOWN"),
156     ZONE3_SOURCE_QUERY("SL3", "QSTN"),
157     ZONE3_SOURCE_SET("SL3", "%02X"),
158     ZONE3_SOURCE("SL3", "");
159
160     public static enum Zone {
161         MAIN,
162         ZONE1,
163         ZONE2,
164         ZONE3
165     }
166
167     private String command;
168     private String value;
169
170     private EiscpCommand(String command, String value) {
171         this.command = command;
172         this.value = value;
173     }
174
175     /**
176      * @return the iscp command string (example 'PWR')
177      */
178     public String getCommand() {
179         return command;
180     }
181
182     /**
183      * @return the iscp value string (example 'QSTN')
184      */
185     public String getValue() {
186         return value;
187     }
188
189     public static EiscpCommand getCommandForZone(Zone zone, EiscpCommand baseCommand) throws IllegalArgumentException {
190         if (zone == Zone.MAIN || zone == Zone.ZONE1) {
191             return baseCommand;
192         } else {
193             return EiscpCommand.valueOf(zone.toString() + "_" + baseCommand);
194         }
195     }
196
197     /**
198      * @param command the command to find a matching command name for.
199      * @return the commandName that is associated with the passed command.
200      */
201     public static EiscpCommand getCommandByCommandStr(String command) throws IllegalArgumentException {
202         for (EiscpCommand candidate : values()) {
203             if (candidate.getCommand().equals(command)) {
204                 return candidate;
205             }
206         }
207         throw new IllegalArgumentException("There is no matching commandName for command '" + command + "'");
208     }
209
210     /**
211      * @param command the command to find a matching command name for.
212      * @param value the value to find a matching value for.
213      *
214      * @return the commandName that is associated with the passed command.
215      */
216     public static EiscpCommand getCommandByCommandAndValueStr(String command, String value)
217             throws IllegalArgumentException {
218         for (EiscpCommand candidate : values()) {
219             if (candidate.getCommand().equals(command) && candidate.getValue().equals(value)) {
220                 return candidate;
221             }
222         }
223         throw new IllegalArgumentException(
224                 "There is no matching commandName for command '" + command + "' and value '" + value + "'");
225     }
226 }