2 * Copyright (c) 2010-2021 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.heos.internal;
15 import static org.openhab.binding.heos.internal.HeosBindingConstants.*;
17 import java.util.HashMap;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.binding.heos.internal.handler.*;
23 import org.openhab.binding.heos.internal.resources.HeosEventListener;
24 import org.openhab.core.thing.ChannelUID;
25 import org.openhab.core.thing.type.ChannelTypeUID;
28 * The {@link HeosChannelHandlerFactory} is responsible for creating and returning
29 * of the single handler for each channel of the single things.
30 * It also stores already created handler for further use.
32 * @author Johannes Einig - Initial contribution
35 public class HeosChannelHandlerFactory {
36 private final HeosBridgeHandler bridge;
37 private final HeosDynamicStateDescriptionProvider heosDynamicStateDescriptionProvider;
38 private final Map<ChannelUID, HeosChannelHandler> handlerStorageMap = new HashMap<>();
40 public HeosChannelHandlerFactory(HeosBridgeHandler bridge,
41 HeosDynamicStateDescriptionProvider heosDynamicStateDescriptionProvider) {
43 this.heosDynamicStateDescriptionProvider = heosDynamicStateDescriptionProvider;
46 public @Nullable HeosChannelHandler getChannelHandler(ChannelUID channelUID, HeosEventListener eventListener,
47 @Nullable ChannelTypeUID channelTypeUID) {
48 if (handlerStorageMap.containsKey(channelUID)) {
49 return handlerStorageMap.get(channelUID);
51 HeosChannelHandler handler = createNewChannelHandler(channelUID, eventListener, channelTypeUID);
52 if (handler != null) {
53 handlerStorageMap.put(channelUID, handler);
59 private @Nullable HeosChannelHandler createNewChannelHandler(ChannelUID channelUID, HeosEventListener eventListener,
60 @Nullable ChannelTypeUID channelTypeUID) {
61 switch (channelUID.getId()) {
63 return new HeosChannelHandlerControl(eventListener, bridge);
65 return new HeosChannelHandlerVolume(eventListener, bridge);
67 return new HeosChannelHandlerMute(eventListener, bridge);
69 return new HeosChannelHandlerInputs(eventListener, bridge);
70 case CH_ID_REPEAT_MODE:
71 return new HeosChannelHandlerRepeatMode(eventListener, bridge);
72 case CH_ID_SHUFFLE_MODE:
73 return new HeosChannelHandlerShuffleMode(eventListener, bridge);
80 return new HeosChannelHandlerNowPlaying(eventListener, bridge);
82 return new HeosChannelHandlerQueue(heosDynamicStateDescriptionProvider, bridge);
83 case CH_ID_CLEAR_QUEUE:
84 return new HeosChannelHandlerClearQueue(bridge);
87 return new HeosChannelHandlerPlayURL(bridge);
89 return new HeosChannelHandlerGrouping(bridge);
90 case CH_ID_RAW_COMMAND:
91 return new HeosChannelHandlerRawCommand(eventListener, bridge);
93 return new HeosChannelHandlerReboot(bridge);
94 case CH_ID_BUILDGROUP:
95 return new HeosChannelHandlerBuildGroup(channelUID, bridge);
97 return new HeosChannelHandlerPlaylist(heosDynamicStateDescriptionProvider, bridge);
99 return new HeosChannelHandlerFavorite(heosDynamicStateDescriptionProvider, bridge);
102 // nothing to handle, we receive updates automatically
106 if (channelTypeUID != null) {
107 if (CH_TYPE_PLAYER.equals(channelTypeUID)) {
108 return new HeosChannelHandlerPlayerSelect(channelUID, bridge);