]> git.basschouten.com Git - openhab-addons.git/blob
42b0162ad29e69c4d097bb98b708996f0979119d
[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.rotel.internal.communication;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.rotel.internal.RotelException;
20 import org.openhab.core.types.StateOption;
21
22 /**
23  * Represents the different DSP modes available for the Rotel equipments
24  *
25  * @author Laurent Garnier - Initial contribution
26  */
27 @NonNullByDefault
28 public enum RotelDsp {
29
30     CAT1_NONE(1, "NONE", RotelCommand.STEREO, "stereo"),
31     CAT1_STEREO3(1, "STEREO3", RotelCommand.STEREO3, "dolby_3_stereo"),
32     CAT1_STEREO5(1, "STEREO5", RotelCommand.STEREO5, "5_channel_stereo"),
33     CAT1_STEREO7(1, "STEREO7", RotelCommand.STEREO7, "7_channel_stereo"),
34     CAT1_MUSIC1(1, "MUSIC1", RotelCommand.DSP1, "dsp1"),
35     CAT1_MUSIC2(1, "MUSIC2", RotelCommand.DSP2, "dsp2"),
36     CAT1_MUSIC3(1, "MUSIC3", RotelCommand.DSP3, "dsp3"),
37     CAT1_MUSIC4(1, "MUSIC4", RotelCommand.DSP4, "dsp4"),
38     CAT1_PROLOGIC(1, "PROLOGIC", RotelCommand.PROLOGIC, "dolby_prologic"),
39     CAT1_PLII_CINEMA(1, "PLIICINEMA", RotelCommand.PLII_CINEMA, "dolby_plii_movie"),
40     CAT1_PLII_MUSIC(1, "PLIIMUSIC", RotelCommand.PLII_MUSIC, "dolby_plii_music"),
41     CAT1_NEO6_CINEMA(1, "NEO6CINEMA", RotelCommand.NEO6_CINEMA, "dts_neo:6_cinema"),
42     CAT1_NEO6_MUSIC(1, "NEO6MUSIC", RotelCommand.NEO6_MUSIC, "dts_neo:6_music"),
43
44     CAT2_NONE(2, "NONE", RotelCommand.STEREO, "stereo"),
45     CAT2_STEREO3(2, "STEREO3", RotelCommand.STEREO3, "dolby_3_stereo"),
46     CAT2_STEREO5(2, "STEREO5", RotelCommand.STEREO5, "5_channel_stereo"),
47     CAT2_STEREO7(2, "STEREO7", RotelCommand.STEREO7, "7_channel_stereo"),
48     CAT2_MUSIC1(2, "MUSIC1", RotelCommand.DSP1, "dsp1"),
49     CAT2_MUSIC2(2, "MUSIC2", RotelCommand.DSP2, "dsp2"),
50     CAT2_MUSIC3(2, "MUSIC3", RotelCommand.DSP3, "dsp3"),
51     CAT2_MUSIC4(2, "MUSIC4", RotelCommand.DSP4, "dsp4"),
52     CAT2_PROLOGIC(2, "PROLOGIC", RotelCommand.PROLOGIC, "dolby_prologic"),
53     CAT2_PLII_CINEMA(2, "PLIICINEMA", RotelCommand.PLII_CINEMA, "dolby_plii_movie"),
54     CAT2_PLII_MUSIC(2, "PLIIMUSIC", RotelCommand.PLII_MUSIC, "dolby_plii_music"),
55     CAT2_PLII_GAME(2, "PLIIGAME", RotelCommand.PLII_GAME, "dolby_plii_game"),
56     CAT2_NEO6_CINEMA(2, "NEO6CINEMA", RotelCommand.NEO6_CINEMA, "dts_neo:6_cinema"),
57     CAT2_NEO6_MUSIC(2, "NEO6MUSIC", RotelCommand.NEO6_MUSIC, "dts_neo:6_music"),
58
59     CAT3_BYPASS(3, "BYPASS", RotelCommand.BYPASS, "analog_bypass"),
60     CAT3_NONE(3, "NONE", RotelCommand.STEREO, "stereo"),
61     CAT3_STEREO3(3, "STEREO3", RotelCommand.STEREO3, "dolby_3_stereo"),
62     CAT3_STEREO5(3, "STEREO5", RotelCommand.STEREO5, "5_channel_stereo"),
63     CAT3_STEREO7(3, "STEREO7", RotelCommand.STEREO7, "7_channel_stereo"),
64     CAT3_DSP1(3, "DSP1", RotelCommand.DSP1, "dsp1"),
65     CAT3_DSP2(3, "DSP2", RotelCommand.DSP2, "dsp2"),
66     CAT3_DSP3(3, "DSP3", RotelCommand.DSP3, "dsp3"),
67     CAT3_DSP4(3, "DSP4", RotelCommand.DSP4, "dsp4"),
68     CAT3_PROLOGIC(3, "PROLOGIC", RotelCommand.PROLOGIC, "dolby_prologic"),
69     CAT3_PLII_CINEMA(3, "PLIIXCINEMA", RotelCommand.PLII_CINEMA, "dolby_plii_movie"),
70     CAT3_PLII_MUSIC(3, "PLIIXMUSIC", RotelCommand.PLII_MUSIC, "dolby_plii_music"),
71     CAT3_PLII_GAME(3, "PLIIXGAME", RotelCommand.PLII_GAME, "dolby_plii_game"),
72     CAT3_NEO6_CINEMA(3, "NEO6CINEMA", RotelCommand.NEO6_CINEMA, "dts_neo:6_cinema"),
73     CAT3_NEO6_MUSIC(3, "NEO6MUSIC", RotelCommand.NEO6_MUSIC, "dts_neo:6_music"),
74
75     CAT4_BYPASS(4, "BYPASS", RotelCommand.BYPASS, "analog_bypass"),
76     CAT4_NONE(4, "NONE", RotelCommand.STEREO, "stereo"),
77     CAT4_STEREO3(4, "STEREO3", RotelCommand.STEREO3, "dolby_3_stereo"),
78     CAT4_STEREO5(4, "STEREO5", RotelCommand.STEREO5, "5_channel_stereo"),
79     CAT4_STEREO7(4, "STEREO7", RotelCommand.STEREO7, "7_channel_stereo"),
80     CAT4_DSP1(4, "DSP1", RotelCommand.DSP1, "dsp1"),
81     CAT4_DSP2(4, "DSP2", RotelCommand.DSP2, "dsp2"),
82     CAT4_DSP3(4, "DSP3", RotelCommand.DSP3, "dsp3"),
83     CAT4_DSP4(4, "DSP4", RotelCommand.DSP4, "dsp4"),
84     CAT4_PROLOGIC(4, "PROLOGIC", RotelCommand.PROLOGIC, "dolby_prologic"),
85     CAT4_PLII_CINEMA(4, "PLIIXCINEMA", RotelCommand.PLII_CINEMA, "dolby_plii_movie"),
86     CAT4_PLII_MUSIC(4, "PLIIXMUSIC", RotelCommand.PLII_MUSIC, "dolby_plii_music"),
87     CAT4_PLII_GAME(4, "PLIIXGAME", RotelCommand.PLII_GAME, "dolby_plii_game"),
88     CAT4_PLIIZ(4, "PLIIZ", RotelCommand.PLIIZ, "dolby_pliiz"),
89     CAT4_NEO6_CINEMA(4, "NEO6CINEMA", RotelCommand.NEO6_CINEMA, "dts_neo:6_cinema"),
90     CAT4_NEO6_MUSIC(4, "NEO6MUSIC", RotelCommand.NEO6_MUSIC, "dts_neo:6_music"),
91
92     CAT5_BYPASS(5, "BYPASS", RotelCommand.BYPASS, "analog_bypass"),
93     CAT5_NONE(5, "NONE", RotelCommand.STEREO, "stereo"),
94     CAT5_STEREO3(5, "STEREO3", RotelCommand.STEREO3, "dolby_3_stereo"),
95     CAT5_STEREO5(5, "STEREO5", RotelCommand.STEREO5, "5_channel_stereo"),
96     CAT5_STEREO7(5, "STEREO7", RotelCommand.STEREO7, "7_channel_stereo"),
97     CAT5_STEREO9(5, "STEREO9", RotelCommand.STEREO9, "9_channel_stereo"),
98     CAT5_STEREO11(5, "STEREO11", RotelCommand.STEREO11, "11_channel_stereo"),
99     CAT5_ATMOS(5, "ATMOS", RotelCommand.ATMOS, "dolby atmos surround"),
100     CAT5_NEURAL_X(5, "NEURALX", RotelCommand.NEURAL_X, "dts neural:x"),
101
102     CAT6_BYPASS(6, "BYPASS", RotelCommand.BYPASS, "analog_bypass"),
103     CAT6_NONE(6, "NONE", RotelCommand.STEREO, "stereo"),
104     CAT6_STEREO3(6, "STEREO3", RotelCommand.STEREO3, "dolby_3_stereo"),
105     CAT6_STEREO5(6, "STEREO5", RotelCommand.STEREO5, "5_channel_stereo"),
106     CAT6_STEREO7(6, "STEREO7", RotelCommand.STEREO7, "7_channel_stereo"),
107     CAT6_PLII_CINEMA(6, "PLIIXCINEMA", RotelCommand.PLII_CINEMA, "dolby_plii_movie"),
108     CAT6_PLII_MUSIC(6, "PLIIXMUSIC", RotelCommand.PLII_MUSIC, "dolby_plii_music"),
109     CAT6_PLII_GAME(6, "PLIIXGAME", RotelCommand.PLII_GAME, "dolby_plii_game"),
110     CAT6_PLIIZ(6, "PLIIZ", RotelCommand.PLIIZ, "dolby_pliiz"),
111     CAT6_NEO6_CINEMA(6, "NEO6CINEMA", RotelCommand.NEO6_CINEMA, "dts_neo:6_cinema"),
112     CAT6_NEO6_MUSIC(6, "NEO6MUSIC", RotelCommand.NEO6_MUSIC, "dts_neo:6_music");
113
114     private int category;
115     private String name;
116     private RotelCommand command;
117     private String feedback;
118
119     /**
120      * Constructor
121      *
122      * @param category a category of models for which the DSP mode is available
123      * @param name the name of the DSP mode
124      * @param command the command to select the DSP mode
125      * @param feedback the feedback message identifying the DSP mode
126      */
127     private RotelDsp(int category, String name, RotelCommand command, String feedback) {
128         this.category = category;
129         this.name = name;
130         this.command = command;
131         this.feedback = feedback;
132     }
133
134     /**
135      * Get the category of models for the current DSP mode
136      *
137      * @return the category of models
138      */
139     public int getCategory() {
140         return category;
141     }
142
143     /**
144      * Get the name of the current DSP mode
145      *
146      * @return the name
147      */
148     public String getName() {
149         return name;
150     }
151
152     /**
153      * Get the command to select the current DSP mode
154      *
155      * @return the command
156      */
157     public RotelCommand getCommand() {
158         return command;
159     }
160
161     /**
162      * Get the feedback message identifying the current DSP mode
163      *
164      * @return the feedback message
165      */
166     public String getFeedback() {
167         return feedback;
168     }
169
170     /**
171      * Get the list of {@link StateOption} associated to the available DSP modes for a particular category of models
172      *
173      * @param category a category of models
174      *
175      * @return the list of {@link StateOption} associated to the available DSP modes for a provided category of models
176      */
177     public static List<StateOption> getStateOptions(int category) {
178         List<StateOption> options = new ArrayList<>();
179         for (RotelDsp value : RotelDsp.values()) {
180             if (value.getCategory() == category) {
181                 options.add(new StateOption(value.getName(), value.getName()));
182             }
183         }
184         return options;
185     }
186
187     /**
188      * Get the DSP mode associated to a name for a particular category of models
189      *
190      * @param category a category of models
191      * @param name the name used to identify the DSP mode
192      *
193      * @return the DSP mode associated to the searched name for the provided category of models
194      *
195      * @throws RotelException - If no DSP mode is associated to the searched name for the provided category
196      */
197     public static RotelDsp getFromName(int category, String name) throws RotelException {
198         for (RotelDsp value : RotelDsp.values()) {
199             if (value.getCategory() == category && value.getName().equals(name)) {
200                 return value;
201             }
202         }
203         throw new RotelException("Invalid name for a DSP mode: " + name);
204     }
205
206     /**
207      * Get the DSP mode identified by a feedback message for a particular category of models
208      *
209      * @param category a category of models
210      * @param feedback the feedback message used to identify the DSP mode
211      *
212      * @return the DSP mode associated to the searched feedback message for the provided category of models
213      *
214      * @throws RotelException - If no DSP mode is associated to the searched feedback message for the provided category
215      */
216     public static RotelDsp getFromFeedback(int category, String feedback) throws RotelException {
217         for (RotelDsp value : RotelDsp.values()) {
218             if (value.getCategory() == category && value.getFeedback().equals(feedback)) {
219                 return value;
220             }
221         }
222         throw new RotelException("Invalid feedback for a DSP mode: " + feedback);
223     }
224
225     /**
226      * Get the DSP mode associated to a command for a particular category of models
227      *
228      * @param category a category of models
229      * @param command the command used to identify the DSP mode
230      *
231      * @return the DSP mode associated to the searched command for the provided category of models
232      *
233      * @throws RotelException - If no DSP mode is associated to the searched command for the provided category
234      */
235     public static RotelDsp getFromCommand(int category, RotelCommand command) throws RotelException {
236         for (RotelDsp value : RotelDsp.values()) {
237             if (value.getCategory() == category && value.getCommand() == command) {
238                 return value;
239             }
240         }
241         throw new RotelException("Invalid command for a DSP mode: " + command.getName());
242     }
243 }