2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.bosesoundtouch.internal;
15 import java.util.Collection;
18 * The {@link ContentItemMaker} class makes ContentItems for sources
20 * @author Thomas Traunbauer - Initial contribution
22 public class ContentItemMaker {
24 private final PresetContainer presetContainer;
25 private final CommandExecutor commandExecutor;
28 * Creates a new instance of this class
30 public ContentItemMaker(CommandExecutor commandExecutor, PresetContainer presetContainer) {
31 this.commandExecutor = commandExecutor;
32 this.presetContainer = presetContainer;
36 * Returns a valid ContentItem, to switch to
38 * @param operationModeType
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
44 public ContentItem getContentItem(OperationModeType operationModeType) throws OperationModeNotAvailableException,
45 NoInternetRadioPresetFoundException, NoStoredMusicPresetFoundException {
46 switch (operationModeType) {
50 throw new OperationModeNotAvailableException();
62 return getBluetooth();
68 return getInternetRadio();
76 return getStoredMusic();
80 throw new OperationModeNotAvailableException();
84 private ContentItem getAmazon() throws OperationModeNotAvailableException {
85 throw new OperationModeNotAvailableException();
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");
95 if (contentItem != null) {
98 throw new OperationModeNotAvailableException();
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");
109 if (contentItem != null) {
112 throw new OperationModeNotAvailableException();
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");
123 if (contentItem != null) {
126 throw new OperationModeNotAvailableException();
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");
137 if (contentItem != null) {
140 throw new OperationModeNotAvailableException();
144 private ContentItem getBluetooth() throws OperationModeNotAvailableException {
145 ContentItem contentItem = null;
146 if (commandExecutor.isBluetoothAvailable()) {
147 contentItem = new ContentItem();
148 contentItem.setSource("BLUETOOTH");
150 if (contentItem != null) {
153 throw new OperationModeNotAvailableException();
157 private ContentItem getDeezer() throws OperationModeNotAvailableException {
158 throw new OperationModeNotAvailableException();
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);
169 if (contentItem != null) {
172 throw new OperationModeNotAvailableException();
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;
186 if (contentItem != null) {
189 throw new NoInternetRadioPresetFoundException();
193 private ContentItem getPandora() throws OperationModeNotAvailableException {
194 throw new OperationModeNotAvailableException();
197 private ContentItem getSiriusxm() throws OperationModeNotAvailableException {
198 throw new OperationModeNotAvailableException();
201 private ContentItem getSpotify() throws OperationModeNotAvailableException {
202 throw new OperationModeNotAvailableException();
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;
215 if (contentItem != null) {
218 throw new NoStoredMusicPresetFoundException();
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);
230 if (contentItem != null) {
233 throw new OperationModeNotAvailableException();