]> git.basschouten.com Git - openhab-addons.git/blob
1dc8c46e57899164e831295aa0c207a13bc05e29
[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.bosesoundtouch.internal;
14
15 import java.util.Collection;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18
19 /**
20  * The {@link ContentItemMaker} class makes ContentItems for sources
21  *
22  * @author Thomas Traunbauer - Initial contribution
23  */
24 @NonNullByDefault
25 public class ContentItemMaker {
26
27     private final PresetContainer presetContainer;
28     private final CommandExecutor commandExecutor;
29
30     /**
31      * Creates a new instance of this class
32      */
33     public ContentItemMaker(CommandExecutor commandExecutor, PresetContainer presetContainer) {
34         this.commandExecutor = commandExecutor;
35         this.presetContainer = presetContainer;
36     }
37
38     /**
39      * Returns a valid ContentItem, to switch to
40      *
41      * @param operationModeType
42      *
43      * @throws OperationModeNotAvailableException if OperationMode is not supported yet or on this device
44      * @throws NoInternetRadioPresetFoundException if OperationMode is INTERNET_RADIO and no PRESET is defined
45      * @throws NoStoredMusicPresetFoundException if OperationMode is STORED_MUSIC and no PRESET is defined
46      */
47     public ContentItem getContentItem(OperationModeType operationModeType) throws OperationModeNotAvailableException,
48             NoInternetRadioPresetFoundException, NoStoredMusicPresetFoundException {
49         switch (operationModeType) {
50             case OFFLINE:
51             case OTHER:
52             case STANDBY:
53                 throw new OperationModeNotAvailableException();
54             case AMAZON:
55                 return getAmazon();
56             case AUX:
57                 return getAUX();
58             case AUX1:
59                 return getAUX1();
60             case AUX2:
61                 return getAUX2();
62             case AUX3:
63                 return getAUX3();
64             case BLUETOOTH:
65                 return getBluetooth();
66             case DEEZER:
67                 return getDeezer();
68             case HDMI1:
69                 return getHDMI();
70             case INTERNET_RADIO:
71                 return getInternetRadio();
72             case PANDORA:
73                 return getPandora();
74             case SIRIUSXM:
75                 return getSiriusxm();
76             case SPOTIFY:
77                 return getSpotify();
78             case STORED_MUSIC:
79                 return getStoredMusic();
80             case TV:
81                 return getTV();
82             default:
83                 throw new OperationModeNotAvailableException();
84         }
85     }
86
87     private ContentItem getAmazon() throws OperationModeNotAvailableException {
88         throw new OperationModeNotAvailableException();
89     }
90
91     private ContentItem getAUX() throws OperationModeNotAvailableException {
92         ContentItem contentItem = null;
93         if (commandExecutor.isAUXAvailable()) {
94             contentItem = new ContentItem();
95             contentItem.setSource("AUX");
96             contentItem.setSourceAccount("AUX");
97         }
98         if (contentItem != null) {
99             return contentItem;
100         } else {
101             throw new OperationModeNotAvailableException();
102         }
103     }
104
105     private ContentItem getAUX1() throws OperationModeNotAvailableException {
106         ContentItem contentItem = null;
107         if (commandExecutor.isAUX1Available()) {
108             contentItem = new ContentItem();
109             contentItem.setSource("AUX");
110             contentItem.setSourceAccount("AUX1");
111         }
112         if (contentItem != null) {
113             return contentItem;
114         } else {
115             throw new OperationModeNotAvailableException();
116         }
117     }
118
119     private ContentItem getAUX2() throws OperationModeNotAvailableException {
120         ContentItem contentItem = null;
121         if (commandExecutor.isAUX2Available()) {
122             contentItem = new ContentItem();
123             contentItem.setSource("AUX");
124             contentItem.setSourceAccount("AUX2");
125         }
126         if (contentItem != null) {
127             return contentItem;
128         } else {
129             throw new OperationModeNotAvailableException();
130         }
131     }
132
133     private ContentItem getAUX3() throws OperationModeNotAvailableException {
134         ContentItem contentItem = null;
135         if (commandExecutor.isAUX3Available()) {
136             contentItem = new ContentItem();
137             contentItem.setSource("AUX");
138             contentItem.setSourceAccount("AUX3");
139         }
140         if (contentItem != null) {
141             return contentItem;
142         } else {
143             throw new OperationModeNotAvailableException();
144         }
145     }
146
147     private ContentItem getBluetooth() throws OperationModeNotAvailableException {
148         ContentItem contentItem = null;
149         if (commandExecutor.isBluetoothAvailable()) {
150             contentItem = new ContentItem();
151             contentItem.setSource("BLUETOOTH");
152         }
153         if (contentItem != null) {
154             return contentItem;
155         } else {
156             throw new OperationModeNotAvailableException();
157         }
158     }
159
160     private ContentItem getDeezer() throws OperationModeNotAvailableException {
161         throw new OperationModeNotAvailableException();
162     }
163
164     private ContentItem getHDMI() throws OperationModeNotAvailableException {
165         ContentItem contentItem = null;
166         if (commandExecutor.isHDMI1Available()) {
167             contentItem = new ContentItem();
168             contentItem.setSource("PRODUCT");
169             contentItem.setSourceAccount("HDMI_1");
170             contentItem.setPresetable(false);
171         }
172         if (contentItem != null) {
173             return contentItem;
174         } else {
175             throw new OperationModeNotAvailableException();
176         }
177     }
178
179     private ContentItem getInternetRadio() throws NoInternetRadioPresetFoundException {
180         ContentItem contentItem = null;
181         if (commandExecutor.isInternetRadioAvailable()) {
182             Collection<ContentItem> listOfPresets = presetContainer.getAllPresets();
183             for (ContentItem iteratedItem : listOfPresets) {
184                 if ((contentItem == null) && (iteratedItem.getOperationMode() == OperationModeType.INTERNET_RADIO)) {
185                     contentItem = iteratedItem;
186                 }
187             }
188         }
189         if (contentItem != null) {
190             return contentItem;
191         } else {
192             throw new NoInternetRadioPresetFoundException();
193         }
194     }
195
196     private ContentItem getPandora() throws OperationModeNotAvailableException {
197         throw new OperationModeNotAvailableException();
198     }
199
200     private ContentItem getSiriusxm() throws OperationModeNotAvailableException {
201         throw new OperationModeNotAvailableException();
202     }
203
204     private ContentItem getSpotify() throws OperationModeNotAvailableException {
205         throw new OperationModeNotAvailableException();
206     }
207
208     private ContentItem getStoredMusic() throws NoStoredMusicPresetFoundException {
209         ContentItem contentItem = null;
210         if (commandExecutor.isStoredMusicAvailable()) {
211             Collection<ContentItem> listOfPresets = presetContainer.getAllPresets();
212             for (ContentItem iteratedItem : listOfPresets) {
213                 if ((contentItem == null) && (iteratedItem.getOperationMode() == OperationModeType.STORED_MUSIC)) {
214                     contentItem = iteratedItem;
215                 }
216             }
217         }
218         if (contentItem != null) {
219             return contentItem;
220         } else {
221             throw new NoStoredMusicPresetFoundException();
222         }
223     }
224
225     private ContentItem getTV() throws OperationModeNotAvailableException {
226         ContentItem contentItem = null;
227         if (commandExecutor.isTVAvailable()) {
228             contentItem = new ContentItem();
229             contentItem.setSource("PRODUCT");
230             contentItem.setSourceAccount("TV");
231             contentItem.setPresetable(false);
232         }
233         if (contentItem != null) {
234             return contentItem;
235         } else {
236             throw new OperationModeNotAvailableException();
237         }
238     }
239 }