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