]> git.basschouten.com Git - openhab-addons.git/blob
b6af30eb8dbd4c5c35b49876114759f1e4f6dff9
[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.mycroft.internal.channels;
14
15 import java.util.Arrays;
16 import java.util.List;
17
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;
26
27 /**
28  * The channel responsible for triggering STT recognition
29  *
30  * @author Gwendal Roulleau - Initial contribution
31  */
32 @NonNullByDefault
33 public class ListenChannel extends MycroftChannel<OnOffType> {
34
35     public ListenChannel(MycroftHandler handler) {
36         super(handler, MycroftBindingConstants.LISTEN_CHANNEL);
37     }
38
39     @Override
40     public List<MessageType> getMessageToListenTo() {
41         return Arrays.asList(MessageType.recognizer_loop__record_begin, MessageType.recognizer_loop__record_end);
42     }
43
44     @Override
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);
50         }
51     }
52
53     @Override
54     public void handleCommand(Command command) {
55         if (command instanceof OnOffType) {
56             if (command == OnOffType.ON) {
57                 handler.sendMessage(new MessageMicListen());
58             }
59         }
60     }
61 }