]> git.basschouten.com Git - openhab-addons.git/blob
8f2f7a09d2f23818be95b6872529d15f3ff1012d
[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.heos.internal.handler;
14
15 import static org.openhab.binding.heos.internal.HeosBindingConstants.CH_ID_QUEUE;
16
17 import java.io.IOException;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.heos.internal.exception.HeosNotFoundException;
22 import org.openhab.binding.heos.internal.resources.Telnet.ReadException;
23 import org.openhab.core.thing.ChannelUID;
24 import org.openhab.core.thing.ThingUID;
25 import org.openhab.core.types.Command;
26 import org.openhab.core.types.RefreshType;
27
28 /**
29  * The {@link HeosChannelHandlerFavorite} handles the playlist selection channel command
30  * from the implementing thing.
31  *
32  * @author Johannes Einig - Initial contribution
33  */
34 @NonNullByDefault
35 public class HeosChannelHandlerQueue extends BaseHeosChannelHandler {
36     private final HeosDynamicStateDescriptionProvider heosDynamicStateDescriptionProvider;
37
38     public HeosChannelHandlerQueue(HeosDynamicStateDescriptionProvider heosDynamicStateDescriptionProvider,
39             HeosBridgeHandler bridge) {
40         super(bridge);
41         this.heosDynamicStateDescriptionProvider = heosDynamicStateDescriptionProvider;
42     }
43
44     @Override
45     public void handlePlayerCommand(Command command, String id, ThingUID uid) throws IOException, ReadException {
46         handleCommand(command, id, uid);
47     }
48
49     @Override
50     public void handleGroupCommand(Command command, @Nullable String id, ThingUID uid,
51             HeosGroupHandler heosGroupHandler) throws IOException, ReadException {
52         if (id == null) {
53             throw new HeosNotFoundException();
54         }
55
56         handleCommand(command, id, uid);
57     }
58
59     @Override
60     public void handleBridgeCommand(Command command, ThingUID uid) {
61         // not used on bridge
62     }
63
64     private void handleCommand(Command command, String id, ThingUID uid) throws IOException, ReadException {
65         ChannelUID channelUID = new ChannelUID(uid, CH_ID_QUEUE);
66         if (command instanceof RefreshType) {
67             heosDynamicStateDescriptionProvider.setQueue(channelUID, getApi().getQueue(id));
68             return;
69         }
70
71         String idCommand = heosDynamicStateDescriptionProvider.getValueByLabel(channelUID, command.toString());
72         getApi().playMediaFromQueue(id, idCommand);
73     }
74 }