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