]> git.basschouten.com Git - openhab-addons.git/blob
aae61eab4f9e5f8af499173b3fac9d85417adc4b
[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.MessageSpeak;
24 import org.openhab.core.library.types.StringType;
25 import org.openhab.core.types.Command;
26
27 /**
28  * The channel responsible for TSS
29  *
30  * @author Gwendal Roulleau - Initial contribution
31  */
32 @NonNullByDefault
33 public class SpeakChannel extends MycroftChannel<StringType> {
34
35     public SpeakChannel(MycroftHandler handler) {
36         super(handler, MycroftBindingConstants.SPEAK_CHANNEL);
37     }
38
39     @Override
40     public List<MessageType> getMessageToListenTo() {
41         return Arrays.asList(MessageType.speak);
42     }
43
44     @Override
45     public void messageReceived(BaseMessage message) {
46         if (message.type == MessageType.speak) {
47             MessageSpeak messageSpeak = (MessageSpeak) message;
48             updateMyState(new StringType(messageSpeak.data.utterance));
49         }
50     }
51
52     @Override
53     public void handleCommand(Command command) {
54         if (command instanceof StringType) {
55             if (handler.sendMessage(new MessageSpeak(command.toFullString()))) {
56                 updateMyState(new StringType(command.toFullString()));
57             }
58         }
59     }
60 }