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.mycroft.internal.channels;
15 import java.util.Arrays;
16 import java.util.List;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.mycroft.internal.MycroftBindingConstants;
20 import org.openhab.binding.mycroft.internal.MycroftHandler;
21 import org.openhab.binding.mycroft.internal.api.MessageType;
22 import org.openhab.binding.mycroft.internal.api.dto.BaseMessage;
23 import org.openhab.binding.mycroft.internal.api.dto.MessageRecognizerLoopUtterance;
24 import org.openhab.core.library.types.StringType;
25 import org.openhab.core.types.Command;
28 * This channel handle the full utterance send or received by Mycroft, before any intent recognition
30 * @author Gwendal Roulleau - Initial contribution
34 public class UtteranceChannel extends MycroftChannel<StringType> {
36 public UtteranceChannel(MycroftHandler handler) {
37 super(handler, MycroftBindingConstants.UTTERANCE_CHANNEL);
41 protected List<MessageType> getMessageToListenTo() {
42 return Arrays.asList(MessageType.recognizer_loop__utterance);
46 public void messageReceived(BaseMessage message) {
47 if (message.type == MessageType.recognizer_loop__utterance) {
48 List<String> utterances = ((MessageRecognizerLoopUtterance) message).data.utterances;
49 if (!utterances.isEmpty()) {
50 updateMyState(new StringType(utterances.get(0)));
56 public void handleCommand(Command command) {
57 if (command instanceof StringType) {
58 if (handler.sendMessage(new MessageRecognizerLoopUtterance(command.toFullString()))) {
59 updateMyState(new StringType(command.toFullString()));