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.MessageMicListen;
24 import org.openhab.core.library.types.OnOffType;
25 import org.openhab.core.types.Command;
28 * The channel responsible for triggering STT recognition
30 * @author Gwendal Roulleau - Initial contribution
33 public class ListenChannel extends MycroftChannel<OnOffType> {
35 public ListenChannel(MycroftHandler handler) {
36 super(handler, MycroftBindingConstants.LISTEN_CHANNEL);
40 public List<MessageType> getMessageToListenTo() {
41 return Arrays.asList(MessageType.recognizer_loop__record_begin, MessageType.recognizer_loop__record_end);
45 public void messageReceived(BaseMessage message) {
46 if (message.type == MessageType.recognizer_loop__record_begin) {
47 updateMyState(OnOffType.ON);
48 } else if (message.type == MessageType.recognizer_loop__record_end) {
49 updateMyState(OnOffType.OFF);
54 public void handleCommand(Command command) {
55 if (command instanceof OnOffType) {
56 if (command == OnOffType.ON) {
57 handler.sendMessage(new MessageMicListen());