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.heos.internal.handler;
15 import static org.openhab.binding.heos.internal.resources.HeosConstants.PID;
17 import java.util.List;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.core.library.types.OnOffType;
22 import org.openhab.core.thing.Channel;
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 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * The {@link HeosChannelHandlerPlayerSelect} handles the player selection channel command
32 * from the implementing thing.
34 * @author Johannes Einig - Initial contribution
37 public class HeosChannelHandlerPlayerSelect extends BaseHeosChannelHandler {
38 protected final Logger logger = LoggerFactory.getLogger(HeosChannelHandlerPlayerSelect.class);
40 private final ChannelUID channelUID;
42 public HeosChannelHandlerPlayerSelect(ChannelUID channelUID, HeosBridgeHandler bridge) {
44 this.channelUID = channelUID;
48 public void handlePlayerCommand(Command command, String id, ThingUID uid) {
53 public void handleGroupCommand(Command command, @Nullable String id, ThingUID uid,
54 HeosGroupHandler heosGroupHandler) {
59 public void handleBridgeCommand(Command command, ThingUID uid) {
60 if (command instanceof RefreshType) {
63 Channel channel = bridge.getThing().getChannel(channelUID.getId());
64 if (channel == null) {
65 logger.debug("Channel {} not found", channelUID);
69 List<String[]> selectedPlayerList = bridge.getSelectedPlayerList();
71 if (command.equals(OnOffType.ON)) {
72 String[] selectedPlayerInfo = new String[2];
73 selectedPlayerInfo[0] = channel.getProperties().get(PID);
74 selectedPlayerInfo[1] = channelUID.getId();
75 selectedPlayerList.add(selectedPlayerInfo);
76 } else if (!selectedPlayerList.isEmpty()) {
77 int indexPlayerChannel = -1;
78 for (int i = 0; i < selectedPlayerList.size(); i++) {
79 String localPID = selectedPlayerList.get(i)[0];
80 if (localPID.equals(channel.getProperties().get(PID))) {
81 indexPlayerChannel = i;
84 selectedPlayerList.remove(indexPlayerChannel);
85 bridge.setSelectedPlayerList(selectedPlayerList);