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