]> git.basschouten.com Git - openhab-addons.git/blob
4f8b6740092bbe759d665b92deda999344f55980
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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_NONE(3, "NONE", RotelCommand.STEREO, "stereo"),
60     CAT3_STEREO3(3, "STEREO3", RotelCommand.STEREO3, "dolby_3_stereo"),
61     CAT3_STEREO5(3, "STEREO5", RotelCommand.STEREO5, "5_channel_stereo"),
62     CAT3_STEREO7(3, "STEREO7", RotelCommand.STEREO7, "7_channel_stereo"),
63     CAT3_DSP1(3, "DSP1", RotelCommand.DSP1, "dsp1"),
64     CAT3_DSP2(3, "DSP2", RotelCommand.DSP2, "dsp2"),
65     CAT3_DSP3(3, "DSP3", RotelCommand.DSP3, "dsp3"),
66     CAT3_DSP4(3, "DSP4", RotelCommand.DSP4, "dsp4"),
67     CAT3_PROLOGIC(3, "PROLOGIC", RotelCommand.PROLOGIC, "dolby_prologic"),
68     CAT3_PLII_CINEMA(3, "PLIIXCINEMA", RotelCommand.PLII_CINEMA, "dolby_plii_movie"),
69     CAT3_PLII_MUSIC(3, "PLIIXMUSIC", RotelCommand.PLII_MUSIC, "dolby_plii_music"),
70     CAT3_PLII_GAME(3, "PLIIXGAME", RotelCommand.PLII_GAME, "dolby_plii_game"),
71     CAT3_NEO6_CINEMA(3, "NEO6CINEMA", RotelCommand.NEO6_CINEMA, "dts_neo:6_cinema"),
72     CAT3_NEO6_MUSIC(3, "NEO6MUSIC", RotelCommand.NEO6_MUSIC, "dts_neo:6_music"),
73
74     CAT4_NONE(4, "NONE", RotelCommand.STEREO, "stereo"),
75     CAT4_STEREO3(4, "STEREO3", RotelCommand.STEREO3, "dolby_3_stereo"),
76     CAT4_STEREO5(4, "STEREO5", RotelCommand.STEREO5, "5_channel_stereo"),
77     CAT4_STEREO7(4, "STEREO7", RotelCommand.STEREO7, "7_channel_stereo"),
78     CAT4_DSP1(4, "DSP1", RotelCommand.DSP1, "dsp1"),
79     CAT4_DSP2(4, "DSP2", RotelCommand.DSP2, "dsp2"),
80     CAT4_DSP3(4, "DSP3", RotelCommand.DSP3, "dsp3"),
81     CAT4_DSP4(4, "DSP4", RotelCommand.DSP4, "dsp4"),
82     CAT4_PROLOGIC(4, "PROLOGIC", RotelCommand.PROLOGIC, "dolby_prologic"),
83     CAT4_PLII_CINEMA(4, "PLIIXCINEMA", RotelCommand.PLII_CINEMA, "dolby_plii_movie"),
84     CAT4_PLII_MUSIC(4, "PLIIXMUSIC", RotelCommand.PLII_MUSIC, "dolby_plii_music"),
85     CAT4_PLII_GAME(4, "PLIIXGAME", RotelCommand.PLII_GAME, "dolby_plii_game"),
86     CAT4_PLIIZ(4, "PLIIZ", RotelCommand.PLIIZ, "dolby_pliiz"),
87     CAT4_NEO6_CINEMA(4, "NEO6CINEMA", RotelCommand.NEO6_CINEMA, "dts_neo:6_cinema"),
88     CAT4_NEO6_MUSIC(4, "NEO6MUSIC", RotelCommand.NEO6_MUSIC, "dts_neo:6_music"),
89
90     CAT5_BYPASS(5, "BYPASS", RotelCommand.BYPASS, "analog_bypass"),
91     CAT5_NONE(5, "NONE", RotelCommand.STEREO, "stereo"),
92     CAT5_STEREO3(5, "STEREO3", RotelCommand.STEREO3, "dolby_3_stereo"),
93     CAT5_STEREO5(5, "STEREO5", RotelCommand.STEREO5, "5_channel_stereo"),
94     CAT5_STEREO7(5, "STEREO7", RotelCommand.STEREO7, "7_channel_stereo"),
95     CAT5_STEREO9(5, "STEREO9", RotelCommand.STEREO9, "9_channel_stereo"),
96     CAT5_STEREO11(5, "STEREO11", RotelCommand.STEREO11, "11_channel_stereo"),
97     CAT5_ATMOS(5, "ATMOS", RotelCommand.ATMOS, "dolby atmos surround"),
98     CAT5_NEURAL_X(5, "NEURALX", RotelCommand.NEURAL_X, "dts neural:x"),
99
100     CAT6_BYPASS(6, "BYPASS", RotelCommand.BYPASS, "analog_bypass"),
101     CAT6_NONE(6, "NONE", RotelCommand.STEREO, "stereo"),
102     CAT6_STEREO3(6, "STEREO3", RotelCommand.STEREO3, "dolby_3_stereo"),
103     CAT6_STEREO5(6, "STEREO5", RotelCommand.STEREO5, "5_channel_stereo"),
104     CAT6_STEREO7(6, "STEREO7", RotelCommand.STEREO7, "7_channel_stereo"),
105     CAT6_PLII_CINEMA(6, "PLIIXCINEMA", RotelCommand.PLII_CINEMA, "dolby_plii_movie"),
106     CAT6_PLII_MUSIC(6, "PLIIXMUSIC", RotelCommand.PLII_MUSIC, "dolby_plii_music"),
107     CAT6_PLII_GAME(6, "PLIIXGAME", RotelCommand.PLII_GAME, "dolby_plii_game"),
108     CAT6_PLIIZ(6, "PLIIZ", RotelCommand.PLIIZ, "dolby_pliiz"),
109     CAT6_NEO6_CINEMA(6, "NEO6CINEMA", RotelCommand.NEO6_CINEMA, "dts_neo:6_cinema"),
110     CAT6_NEO6_MUSIC(6, "NEO6MUSIC", RotelCommand.NEO6_MUSIC, "dts_neo:6_music");
111
112     private int category;
113     private String name;
114     private RotelCommand command;
115     private String feedback;
116
117     /**
118      * Constructor
119      *
120      * @param category a category of models for which the DSP mode is available
121      * @param name the name of the DSP mode
122      * @param command the command to select the DSP mode
123      * @param feedback the feedback message identifying the DSP mode
124      */
125     private RotelDsp(int category, String name, RotelCommand command, String feedback) {
126         this.category = category;
127         this.name = name;
128         this.command = command;
129         this.feedback = feedback;
130     }
131
132     /**
133      * Get the category of models for the current DSP mode
134      *
135      * @return the category of models
136      */
137     public int getCategory() {
138         return category;
139     }
140
141     /**
142      * Get the name of the current DSP mode
143      *
144      * @return the name
145      */
146     public String getName() {
147         return name;
148     }
149
150     /**
151      * Get the command to select the current DSP mode
152      *
153      * @return the command
154      */
155     public RotelCommand getCommand() {
156         return command;
157     }
158
159     /**
160      * Get the feedback message identifying the current DSP mode
161      *
162      * @return the feedback message
163      */
164     public String getFeedback() {
165         return feedback;
166     }
167
168     /**
169      * Get the list of {@link StateOption} associated to the available DSP modes for a particular category of models
170      *
171      * @param category a category of models
172      *
173      * @return the list of {@link StateOption} associated to the available DSP modes for a provided category of models
174      */
175     public static List<StateOption> getStateOptions(int category) {
176         List<StateOption> options = new ArrayList<>();
177         for (RotelDsp value : RotelDsp.values()) {
178             if (value.getCategory() == category) {
179                 options.add(new StateOption(value.getName(), value.getName()));
180             }
181         }
182         return options;
183     }
184
185     /**
186      * Get the DSP mode associated to a name for a particular category of models
187      *
188      * @param category a category of models
189      * @param name the name used to identify the DSP mode
190      *
191      * @return the DSP mode associated to the searched name for the provided category of models
192      *
193      * @throws RotelException - If no DSP mode is associated to the searched name for the provided category
194      */
195     public static RotelDsp getFromName(int category, String name) throws RotelException {
196         for (RotelDsp value : RotelDsp.values()) {
197             if (value.getCategory() == category && value.getName().equals(name)) {
198                 return value;
199             }
200         }
201         throw new RotelException("Invalid name for a DSP mode: " + name);
202     }
203
204     /**
205      * Get the DSP mode identified by a feedback message for a particular category of models
206      *
207      * @param category a category of models
208      * @param feedback the feedback message used to identify the DSP mode
209      *
210      * @return the DSP mode associated to the searched feedback message for the provided category of models
211      *
212      * @throws RotelException - If no DSP mode is associated to the searched feedback message for the provided category
213      */
214     public static RotelDsp getFromFeedback(int category, String feedback) throws RotelException {
215         for (RotelDsp value : RotelDsp.values()) {
216             if (value.getCategory() == category && value.getFeedback().equals(feedback)) {
217                 return value;
218             }
219         }
220         throw new RotelException("Invalid feedback for a DSP mode: " + feedback);
221     }
222
223     /**
224      * Get the DSP mode associated to a command for a particular category of models
225      *
226      * @param category a category of models
227      * @param command the command used to identify the DSP mode
228      *
229      * @return the DSP mode associated to the searched command for the provided category of models
230      *
231      * @throws RotelException - If no DSP mode is associated to the searched command for the provided category
232      */
233     public static RotelDsp getFromCommand(int category, RotelCommand command) throws RotelException {
234         for (RotelDsp value : RotelDsp.values()) {
235             if (value.getCategory() == category && value.getCommand() == command) {
236                 return value;
237             }
238         }
239         throw new RotelException("Invalid command for a DSP mode: " + command.getLabel());
240     }
241 }