2 * Copyright (c) 2010-2022 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.mycroft.internal.channels;
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.List;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.mycroft.internal.MycroftBindingConstants;
21 import org.openhab.binding.mycroft.internal.MycroftHandler;
22 import org.openhab.binding.mycroft.internal.api.MessageType;
23 import org.openhab.binding.mycroft.internal.api.dto.BaseMessage;
24 import org.openhab.core.library.types.StringType;
25 import org.openhab.core.types.Command;
28 * The channel responsible for sending/receiving raw message
30 * @author Gwendal Roulleau - Initial contribution
33 public class FullMessageChannel extends MycroftChannel<StringType> {
35 private List<String> messageTypesList = new ArrayList<>();
37 public FullMessageChannel(MycroftHandler handler, String messageTypesList) {
38 super(handler, MycroftBindingConstants.FULL_MESSAGE_CHANNEL);
39 for (String messageType : messageTypesList.split(",")) {
40 this.messageTypesList.add(messageType.trim());
45 public List<MessageType> getMessageToListenTo() {
46 return Arrays.asList(MessageType.any);
50 public void messageReceived(BaseMessage message) {
51 if (messageTypesList.contains(message.type.getMessageTypeName())) {
52 updateMyState(new StringType(message.message));
57 public void handleCommand(Command command) {
58 if (command instanceof StringType) {
59 if (handler.sendMessage(command.toFullString())) {
60 updateMyState(new StringType(command.toFullString()));