2 * Copyright (c) 2010-2023 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;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
20 * The {@link ContentItemMaker} class makes ContentItems for sources
22 * @author Thomas Traunbauer - Initial contribution
25 public class ContentItemMaker {
27 private final PresetContainer presetContainer;
28 private final CommandExecutor commandExecutor;
31 * Creates a new instance of this class
33 public ContentItemMaker(CommandExecutor commandExecutor, PresetContainer presetContainer) {
34 this.commandExecutor = commandExecutor;
35 this.presetContainer = presetContainer;
39 * Returns a valid ContentItem, to switch to
41 * @param operationModeType
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
47 public ContentItem getContentItem(OperationModeType operationModeType) throws OperationModeNotAvailableException,
48 NoInternetRadioPresetFoundException, NoStoredMusicPresetFoundException {
49 switch (operationModeType) {
53 throw new OperationModeNotAvailableException();
65 return getBluetooth();
71 return getInternetRadio();
79 return getStoredMusic();
83 throw new OperationModeNotAvailableException();
87 private ContentItem getAmazon() throws OperationModeNotAvailableException {
88 throw new OperationModeNotAvailableException();
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");
98 if (contentItem != null) {
101 throw new OperationModeNotAvailableException();
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");
112 if (contentItem != null) {
115 throw new OperationModeNotAvailableException();
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");
126 if (contentItem != null) {
129 throw new OperationModeNotAvailableException();
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");
140 if (contentItem != null) {
143 throw new OperationModeNotAvailableException();
147 private ContentItem getBluetooth() throws OperationModeNotAvailableException {
148 ContentItem contentItem = null;
149 if (commandExecutor.isBluetoothAvailable()) {
150 contentItem = new ContentItem();
151 contentItem.setSource("BLUETOOTH");
153 if (contentItem != null) {
156 throw new OperationModeNotAvailableException();
160 private ContentItem getDeezer() throws OperationModeNotAvailableException {
161 throw new OperationModeNotAvailableException();
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);
172 if (contentItem != null) {
175 throw new OperationModeNotAvailableException();
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;
189 if (contentItem != null) {
192 throw new NoInternetRadioPresetFoundException();
196 private ContentItem getPandora() throws OperationModeNotAvailableException {
197 throw new OperationModeNotAvailableException();
200 private ContentItem getSiriusxm() throws OperationModeNotAvailableException {
201 throw new OperationModeNotAvailableException();
204 private ContentItem getSpotify() throws OperationModeNotAvailableException {
205 throw new OperationModeNotAvailableException();
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;
218 if (contentItem != null) {
221 throw new NoStoredMusicPresetFoundException();
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);
233 if (contentItem != null) {
236 throw new OperationModeNotAvailableException();