From 25982dcee1ecee17024d40133321c28bb0f996aa Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Tue, 20 Jul 2021 23:51:09 +0200 Subject: [PATCH 01/39] [mycroft] Mycroft binding - Initial contrib (#11033) This binding will connect to Mycroft A.I. in order to control it or react to event by listening on the message bus. Signed-off-by: Gwendal ROULLEAU --- CODEOWNERS | 1 + bom/openhab-addons/pom.xml | 5 + bundles/org.openhab.binding.mycroft/NOTICE | 13 + bundles/org.openhab.binding.mycroft/README.md | 110 +++++++ bundles/org.openhab.binding.mycroft/pom.xml | 17 ++ .../src/main/feature/feature.xml | 10 + .../internal/MycroftBindingConstants.java | 44 +++ .../internal/MycroftConfiguration.java | 27 ++ .../mycroft/internal/MycroftHandler.java | 249 ++++++++++++++++ .../internal/MycroftHandlerFactory.java | 65 +++++ .../mycroft/internal/api/MessageType.java | 114 ++++++++ .../internal/api/MessageTypeConverter.java | 48 ++++ .../internal/api/MycroftConnection.java | 268 ++++++++++++++++++ .../api/MycroftConnectionListener.java | 35 +++ .../internal/api/MycroftMessageListener.java | 40 +++ .../mycroft/internal/api/dto/BaseMessage.java | 25 ++ .../internal/api/dto/MessageAudioNext.java | 27 ++ .../internal/api/dto/MessageAudioPause.java | 26 ++ .../internal/api/dto/MessageAudioPlay.java | 27 ++ .../internal/api/dto/MessageAudioPrev.java | 27 ++ .../internal/api/dto/MessageAudioResume.java | 27 ++ .../internal/api/dto/MessageAudioStop.java | 26 ++ .../api/dto/MessageAudioTrackInfo.java | 26 ++ .../api/dto/MessageAudioTrackInfoReply.java | 26 ++ .../internal/api/dto/MessageMicListen.java | 26 ++ .../dto/MessageRecognizerLoopRecordBegin.java | 34 +++ .../dto/MessageRecognizerLoopRecordEnd.java | 34 +++ .../dto/MessageRecognizerLoopUtterance.java | 51 ++++ .../internal/api/dto/MessageSpeak.java | 50 ++++ .../api/dto/MessageVolumeDecrease.java | 32 +++ .../internal/api/dto/MessageVolumeDuck.java | 35 +++ .../internal/api/dto/MessageVolumeGet.java | 35 +++ .../api/dto/MessageVolumeGetResponse.java | 33 +++ .../api/dto/MessageVolumeIncrease.java | 32 +++ .../internal/api/dto/MessageVolumeMute.java | 32 +++ .../internal/api/dto/MessageVolumeSet.java | 32 +++ .../internal/api/dto/MessageVolumeUnduck.java | 35 +++ .../internal/api/dto/MessageVolumeUnmute.java | 32 +++ .../internal/channels/AudioPlayerChannel.java | 98 +++++++ .../channels/ChannelCommandHandler.java | 27 ++ .../internal/channels/DuckChannel.java | 68 +++++ .../internal/channels/FullMessageChannel.java | 64 +++++ .../internal/channels/ListenChannel.java | 61 ++++ .../internal/channels/MuteChannel.java | 68 +++++ .../internal/channels/MycroftChannel.java | 70 +++++ .../internal/channels/SpeakChannel.java | 60 ++++ .../internal/channels/UtteranceChannel.java | 63 ++++ .../internal/channels/VolumeChannel.java | 163 +++++++++++ .../main/resources/OH-INF/binding/binding.xml | 13 + .../resources/OH-INF/thing/thing-types.xml | 92 ++++++ .../internal/api/MycroftConnectionTest.java | 112 ++++++++ .../binding/mycroft/internal/api/speak.json | 1 + .../OH-INF/i18n/playstation.properties | 0 bundles/pom.xml | 1 + 54 files changed, 2737 insertions(+) create mode 100644 bundles/org.openhab.binding.mycroft/NOTICE create mode 100644 bundles/org.openhab.binding.mycroft/README.md create mode 100644 bundles/org.openhab.binding.mycroft/pom.xml create mode 100644 bundles/org.openhab.binding.mycroft/src/main/feature/feature.xml create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftBindingConstants.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftConfiguration.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandlerFactory.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageType.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageTypeConverter.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnectionListener.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftMessageListener.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/BaseMessage.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioNext.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPause.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPlay.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPrev.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioResume.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioStop.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfo.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfoReply.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageMicListen.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordBegin.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordEnd.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopUtterance.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageSpeak.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDecrease.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDuck.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGet.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGetResponse.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeIncrease.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeMute.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeSet.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnduck.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnmute.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/AudioPlayerChannel.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ChannelCommandHandler.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/DuckChannel.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/FullMessageChannel.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ListenChannel.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MuteChannel.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MycroftChannel.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/SpeakChannel.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/UtteranceChannel.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java create mode 100644 bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml create mode 100644 bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml create mode 100644 bundles/org.openhab.binding.mycroft/src/test/java/org/openhab/binding/mycroft/internal/api/MycroftConnectionTest.java create mode 100644 bundles/org.openhab.binding.mycroft/src/test/resources/org/openhab/binding/mycroft/internal/api/speak.json mode change 100644 => 100755 bundles/org.openhab.binding.playstation/src/main/resources/OH-INF/i18n/playstation.properties diff --git a/CODEOWNERS b/CODEOWNERS index c09e2b9f1e3be..bcba505f25025 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -197,6 +197,7 @@ /bundles/org.openhab.binding.mqtt.homeassistant/ @davidgraeff @antroids /bundles/org.openhab.binding.mqtt.homie/ @davidgraeff /bundles/org.openhab.binding.myq/ @digitaldan +/bundles/org.openhab.binding.mycroft/ @dalgwen /bundles/org.openhab.binding.mystrom/ @pail23 /bundles/org.openhab.binding.nanoleaf/ @raepple @stefan-hoehn /bundles/org.openhab.binding.neato/ @jjlauterbach diff --git a/bom/openhab-addons/pom.xml b/bom/openhab-addons/pom.xml index 8e2a9ade62de9..7c8e528bd4eef 100644 --- a/bom/openhab-addons/pom.xml +++ b/bom/openhab-addons/pom.xml @@ -971,6 +971,11 @@ org.openhab.binding.mqtt.homie ${project.version} + + org.openhab.addons.bundles + org.openhab.binding.mycroft + ${project.version} + org.openhab.addons.bundles org.openhab.binding.myq diff --git a/bundles/org.openhab.binding.mycroft/NOTICE b/bundles/org.openhab.binding.mycroft/NOTICE new file mode 100644 index 0000000000000..38d625e349232 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/NOTICE @@ -0,0 +1,13 @@ +This content is produced and maintained by the openHAB project. + +* Project home: https://www.openhab.org + +== Declared Project Licenses + +This program and the accompanying materials are made available under the terms +of the Eclipse Public License 2.0 which is available at +https://www.eclipse.org/legal/epl-2.0/. + +== Source Code + +https://github.com/openhab/openhab-addons diff --git a/bundles/org.openhab.binding.mycroft/README.md b/bundles/org.openhab.binding.mycroft/README.md new file mode 100644 index 0000000000000..2c3ce2312aa59 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/README.md @@ -0,0 +1,110 @@ +# Mycroft Binding + +This binding will connect to Mycroft A.I. in order to control it or react to event by listening on the message bus. + +Possibilies include : + +- Press a button in OpenHAB to wake Mycroft without using a wake word. +- Simulate a voice command to launch a skill, as if you just spoke it +- Send some text that Mycroft will say (Using its Text To Speach service) +- Control the music player +- Control the sound volume of Mycroft +- React to all the aforementioned events ... +- ... And send/receive all other kind of messages on the message bus + + +## Supported Things + +The only thing managed by this binding is a Mycroft instance. + + +## Discovery + +There is no discovery service, as Mycroft doesn't announce itself on the network. + + +## Thing Configuration + +The configuration is simple, as you just need to give the IP/hostname of the Mycroft instance accessible on the network. +The default port is 8181, but you could change it if you want. + +``` +Thing mycroft:mycroft:myMycroft "Mycroft A.I." @ "Living Room" [host="192.168.X.X"] +``` + +| property | type | description | mandatory | +|---------------|---------------------------------|-------------------------------------------------------------------------|-----------| +| host | IP or string | IP address or hostname | Yes | +| port | integer | Port to reach Mycroft (default 8181) | No | + + +## Channels + +The Mycroft thing supports the following channels : + + +| channel type id | Item type | description | +|------------------------------|-----------|------------------------------------------------------------------------------------------------| +| listen | Switch | Switch to ON when Mycroft is listening. Can simulate a wake word detection to trigger the STT | +| speak | String | The last sentence Mycroft speaks, or ask Mycroft to say something | +| utterance | String | The last utterance Mycroft receive, or ask Mycroft something | +| player | Player | The music player Mycroft is currently controlling | +| volume | Dimmer | The volume of the Mycroft speaker. NOT FUNCTIONNAL. [SEE THIS POST TO SEE EVOLUTION](https://community.mycroft.ai/t/openhab-plugin-development-audio-volume-message-types-missing/10576) | +| volume_mute | Switch | Mute the Mycroft speaker | +| volume_duck | Switch | Duck the volume of the Mycroft speaker | +| full_message | String | The last message (full json) seen on the Mycroft Bus. Filtered by the messageTypes properties | + + +The channel 'full_message' has the following configuration available : + +| property | type | description | mandatory | +|---------------|---------------------------------|-------------------------------------------------------------------------|-----------| +| messageTypes | List of string, comma separated | Only these message types will be forwarded to the Full Message Channel | No | + + +## Full Example + +A manual setup through a `things/mycroft.things` file could look like this: + +```java +Thing mycroft:mycroft:myMycroft "Mycroft A.I." @ "Living Room" [host="192.168.X.X", port=8181] { + Channels: + Type full-message-channel : Text [ + messageTypes="message.type.1,message.type.4" + ] +} +``` + +### Item Configuration + +The `mycroft.item` file : + +```java +Switch myMycroft_mute "Mute" { channel="mycroft:mycroft:myMycroft:volume_mute" } +Switch myMycroft_duck "Duck" { channel="mycroft:mycroft:myMycroft:volume_duck" } +Dimmer myMycroft_volume "Volume [%d]" { channel="mycroft:mycroft:myMycroft:volume" } +Player myMycroft_player "Control" { channel="mycroft:mycroft:myMycroft:player" } +Switch myMycroft_listen "Wake and listen" { channel="mycroft:mycroft:myMycroft:listen" } +String myMycroft_speak "Speak STT" { channel="mycroft:mycroft:myMycroft:speak" } +String myMycroft_utterance "Utterance" { channel="mycroft:mycroft:myMycroft:utterance" } +String myMycroft_fullmessage "Full JSON message" { channel="mycroft:mycroft:myMycroft:full_message" } +``` + +### Sitemap Configuration + +A `demo.sitemap` file : + +```perl +sitemap demo label="myMycroft" +{ + Frame label="myMycroft" { + Switch item=myMycroft_mute + Switch item=myMycroft_duck + Slider item=myMycroft_volume + Default item=myMycroft_player + Switch item=myMycroft_listen + Text item=myMycroft_speak + Text item=myMycroft_utterance + Text item=myMycroft_fullmessage + } +} diff --git a/bundles/org.openhab.binding.mycroft/pom.xml b/bundles/org.openhab.binding.mycroft/pom.xml new file mode 100644 index 0000000000000..c06a12e3f4f6c --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/pom.xml @@ -0,0 +1,17 @@ + + + + 4.0.0 + + + org.openhab.addons.bundles + org.openhab.addons.reactor.bundles + 3.2.0-SNAPSHOT + + + org.openhab.binding.mycroft + + openHAB Add-ons :: Bundles :: Mycroft Binding + + diff --git a/bundles/org.openhab.binding.mycroft/src/main/feature/feature.xml b/bundles/org.openhab.binding.mycroft/src/main/feature/feature.xml new file mode 100644 index 0000000000000..04d5e3b8ff972 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/feature/feature.xml @@ -0,0 +1,10 @@ + + + mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features + + + openhab-runtime-base + openhab-transport-http + mvn:org.openhab.addons.bundles/org.openhab.binding.mycroft/${project.version} + + diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftBindingConstants.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftBindingConstants.java new file mode 100644 index 0000000000000..611da2a258808 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftBindingConstants.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.core.thing.ThingTypeUID; + +/** + * The {@link MycroftBindingConstants} class defines common constants, which are + * used across the whole binding. + * + * @author Gwendal ROULLEAU - Initial contribution + */ +@NonNullByDefault +public class MycroftBindingConstants { + + private static final String BINDING_ID = "mycroft"; + + // List of all Thing Type UIDs + public static final ThingTypeUID MYCROFT = new ThingTypeUID(BINDING_ID, "mycroft"); + + // List of all Channel ids + public static final String LISTEN_CHANNEL = "listen"; + public static final String SPEAK_CHANNEL = "speak"; + public static final String PLAYER_CHANNEL = "player"; + public static final String VOLUME_CHANNEL = "volume"; + public static final String VOLUME_MUTE_CHANNEL = "volume_mute"; + public static final String VOLUME_DUCK_CHANNEL = "volume_duck"; + public static final String UTTERANCE_CHANNEL = "utterance"; + public static final String FULL_MESSAGE_CHANNEL = "full_message"; + + // Channel property : + public static final String FULL_MESSAGE_CHANNEL_MESSAGE_TYPE_PROPERTY = "messageTypes"; +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftConfiguration.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftConfiguration.java new file mode 100644 index 0000000000000..6c22b52653522 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftConfiguration.java @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal; + +import org.eclipse.jdt.annotation.NonNullByDefault; + +/** + * The {@link MycroftConfiguration} class contains fields mapping thing configuration parameters. + * + * @author Gwendal ROULLEAU - Initial contribution + */ +@NonNullByDefault +public class MycroftConfiguration { + + public String host = ""; + public int port = 8181; +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java new file mode 100644 index 0000000000000..bf1e9f991f6e7 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java @@ -0,0 +1,249 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.openhab.binding.mycroft.internal.api.MessageType; +import org.openhab.binding.mycroft.internal.api.MycroftConnection; +import org.openhab.binding.mycroft.internal.api.MycroftConnectionListener; +import org.openhab.binding.mycroft.internal.api.MycroftMessageListener; +import org.openhab.binding.mycroft.internal.api.dto.BaseMessage; +import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeGet; +import org.openhab.binding.mycroft.internal.channels.AudioPlayerChannel; +import org.openhab.binding.mycroft.internal.channels.ChannelCommandHandler; +import org.openhab.binding.mycroft.internal.channels.DuckChannel; +import org.openhab.binding.mycroft.internal.channels.FullMessageChannel; +import org.openhab.binding.mycroft.internal.channels.ListenChannel; +import org.openhab.binding.mycroft.internal.channels.MuteChannel; +import org.openhab.binding.mycroft.internal.channels.MycroftChannel; +import org.openhab.binding.mycroft.internal.channels.SpeakChannel; +import org.openhab.binding.mycroft.internal.channels.UtteranceChannel; +import org.openhab.binding.mycroft.internal.channels.VolumeChannel; +import org.openhab.core.io.net.http.WebSocketFactory; +import org.openhab.core.thing.Channel; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.thing.Thing; +import org.openhab.core.thing.ThingStatus; +import org.openhab.core.thing.ThingStatusDetail; +import org.openhab.core.thing.binding.BaseThingHandler; +import org.openhab.core.types.Command; +import org.openhab.core.types.State; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The {@link MycroftHandler} is responsible for handling commands, which are + * sent to one of the channels. + * + * @author Gwendal ROULLEAU - Initial contribution + */ +@NonNullByDefault +public class MycroftHandler extends BaseThingHandler implements MycroftConnectionListener { + + private final Logger logger = LoggerFactory.getLogger(MycroftHandler.class); + + protected final MycroftConnection connection; + private @Nullable ScheduledFuture scheduledFuture; + private MycroftConfiguration config = new MycroftConfiguration(); + private boolean thingDisposing = false; + private AtomicBoolean isStartingWebSocket = new AtomicBoolean(false); + protected Map> mycroftChannels = new HashMap<>(); + + /** The reconnect frequency in case of error */ + private static final int POLL_FREQUENCY_SEC = 10; + private int sometimesSendVolumeRequest = 0; + + public MycroftHandler(Thing thing, WebSocketFactory webSocketFactory) { + super(thing); + String websocketID = thing.getUID().getAsString().replace(':', '-'); + if (websocketID.length() < 4) { + websocketID = "openHAB-mycroft-" + websocketID; + } else if (websocketID.length() > 20) { + websocketID = websocketID.substring(websocketID.length() - 20); + } + this.connection = new MycroftConnection(this, webSocketFactory.createWebSocketClient(websocketID)); + } + + /** + * Stops the API request or websocket reconnect timer + */ + private void stopTimer() { + ScheduledFuture future = scheduledFuture; + if (future != null) { + future.cancel(false); + scheduledFuture = null; + } + } + + /** + * Starts the websocket connection. + * sometimes send a get volume request to fully test the connection / refresh volume. + */ + private void startWebsocket() { + if (thingDisposing) { + return; + } + if (!isStartingWebSocket.compareAndExchange(false, true)) { + try { + if (connection.isConnected()) { + // sometimes test the connection by sending a real message + // AND refreshing volume in the same step + if (sometimesSendVolumeRequest >= 3) { // arbitrary one on three times + sometimesSendVolumeRequest = 0; + sendMessage(new MessageVolumeGet()); + } else { + sometimesSendVolumeRequest++; + } + } else { + connection.start(config.host, config.port); + } + } finally { + stopTimer(); + scheduledFuture = scheduler.schedule(this::startWebsocket, POLL_FREQUENCY_SEC, TimeUnit.SECONDS); + isStartingWebSocket.set(false); + } + } + } + + @Override + public void handleCommand(ChannelUID channelUID, Command command) { + + ChannelCommandHandler channelCommand = mycroftChannels.get(channelUID); + if (channelCommand == null) { + logger.error("Command {} for channel {} cannot be handled", command.toString(), channelUID.toString()); + } else { + channelCommand.handleCommand(command); + } + } + + @Override + public void initialize() { + + updateStatus(ThingStatus.UNKNOWN); + + logger.debug("Start initializing mycroft {}", thing.getUID()); + + config = getConfigAs(MycroftConfiguration.class); + + scheduler.execute(() -> { + startWebsocket(); + }); + + registerChannel(new ListenChannel(this)); + registerChannel(new VolumeChannel(this)); + registerChannel(new MuteChannel(this)); + registerChannel(new DuckChannel(this)); + registerChannel(new SpeakChannel(this)); + registerChannel(new AudioPlayerChannel(this)); + registerChannel(new UtteranceChannel(this)); + + final Channel fullMessageChannel = getThing().getChannel(MycroftBindingConstants.FULL_MESSAGE_CHANNEL); + @SuppressWarnings("null") // cannot be null + String messageTypesProperty = (String) fullMessageChannel.getConfiguration() + .get(MycroftBindingConstants.FULL_MESSAGE_CHANNEL_MESSAGE_TYPE_PROPERTY); + + registerChannel(new FullMessageChannel(this, messageTypesProperty)); + + checkLinkedChannelsAndRegisterMessageListeners(); + } + + private void checkLinkedChannelsAndRegisterMessageListeners() { + for (Entry> channelEntry : mycroftChannels.entrySet()) { + ChannelUID uid = channelEntry.getKey(); + MycroftChannel channel = channelEntry.getValue(); + if (isLinked(uid)) { + channel.registerListeners(); + } else { + channel.unregisterListeners(); + } + } + } + + @Override + public void channelLinked(ChannelUID channelUID) { + checkLinkedChannelsAndRegisterMessageListeners(); + } + + @Override + public void channelUnlinked(ChannelUID channelUID) { + checkLinkedChannelsAndRegisterMessageListeners(); + } + + private void registerChannel(MycroftChannel channel) { + mycroftChannels.put(channel.getChannelUID(), channel); + } + + public void registerMessageListener(MessageType messageType, MycroftMessageListener listener) { + this.connection.registerListener(messageType, listener); + } + + public void unregisterMessageListener(MessageType messageType, MycroftMessageListener listener) { + this.connection.unregisterListener(messageType, listener); + } + + @Override + public void connectionEstablished() { + stopTimer(); + logger.debug("Mycroft thing {} is online", thing.getUID()); + updateStatus(ThingStatus.ONLINE); + } + + @Override + public void connectionLost(String reason) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, reason); + + stopTimer(); + // Wait for POLL_FREQUENCY_SEC after a connection was closed before trying again + scheduledFuture = scheduler.schedule(this::startWebsocket, POLL_FREQUENCY_SEC, TimeUnit.SECONDS); + } + + @Override + public void dispose() { + thingDisposing = true; + stopTimer(); + connection.close(); + } + + public void updateMyChannel(MycroftChannel mycroftChannel, T state) { + updateState(mycroftChannel.getChannelUID(), state); + } + + public boolean sendMessage(BaseMessage message) { + try { + connection.sendMessage(message); + return true; + } catch (IOException e) { + logger.warn("Cannot send message of type {}, for reason {}", message.getClass().getName(), e.getMessage()); + return false; + } + } + + public boolean sendMessage(String message) { + try { + connection.sendMessage(message); + return true; + } catch (IOException e) { + logger.warn("Cannot send message of type {}, for reason {}", message.getClass().getName(), e.getMessage()); + return false; + } + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandlerFactory.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandlerFactory.java new file mode 100644 index 0000000000000..ed2fd2ccf2125 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandlerFactory.java @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + * + * @author Gwendal ROULLEAU - Initial contribution + */ +package org.openhab.binding.mycroft.internal; + +import java.util.Set; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.openhab.core.io.net.http.WebSocketFactory; +import org.openhab.core.thing.Thing; +import org.openhab.core.thing.ThingTypeUID; +import org.openhab.core.thing.binding.BaseThingHandlerFactory; +import org.openhab.core.thing.binding.ThingHandler; +import org.openhab.core.thing.binding.ThingHandlerFactory; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; + +/** + * The {@link MycroftHandlerFactory} is responsible for creating things and thing + * handlers. + * + * @author Gwendal ROULLEAU - Initial contribution + */ +@NonNullByDefault +@Component(configurationPid = "binding.mycroft", service = ThingHandlerFactory.class) +public class MycroftHandlerFactory extends BaseThingHandlerFactory { + + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(MycroftBindingConstants.MYCROFT); + + private final WebSocketFactory webSocketFactory; + + @Activate + public MycroftHandlerFactory(final @Reference WebSocketFactory webSocketFactory) { + this.webSocketFactory = webSocketFactory; + } + + @Override + public boolean supportsThingType(ThingTypeUID thingTypeUID) { + return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID); + } + + @Override + protected @Nullable ThingHandler createHandler(Thing thing) { + ThingTypeUID thingTypeUID = thing.getThingTypeUID(); + + if (MycroftBindingConstants.MYCROFT.equals(thingTypeUID)) { + return new MycroftHandler(thing, webSocketFactory); + } + + return null; + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageType.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageType.java new file mode 100644 index 0000000000000..fe4378a503aa5 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageType.java @@ -0,0 +1,114 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api; + +import java.util.stream.Stream; + +import javax.validation.constraints.NotNull; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.binding.mycroft.internal.api.dto.BaseMessage; +import org.openhab.binding.mycroft.internal.api.dto.MessageAudioNext; +import org.openhab.binding.mycroft.internal.api.dto.MessageAudioPause; +import org.openhab.binding.mycroft.internal.api.dto.MessageAudioPlay; +import org.openhab.binding.mycroft.internal.api.dto.MessageAudioPrev; +import org.openhab.binding.mycroft.internal.api.dto.MessageAudioResume; +import org.openhab.binding.mycroft.internal.api.dto.MessageAudioStop; +import org.openhab.binding.mycroft.internal.api.dto.MessageAudioTrackInfo; +import org.openhab.binding.mycroft.internal.api.dto.MessageAudioTrackInfoReply; +import org.openhab.binding.mycroft.internal.api.dto.MessageMicListen; +import org.openhab.binding.mycroft.internal.api.dto.MessageRecognizerLoopRecordBegin; +import org.openhab.binding.mycroft.internal.api.dto.MessageRecognizerLoopRecordEnd; +import org.openhab.binding.mycroft.internal.api.dto.MessageRecognizerLoopUtterance; +import org.openhab.binding.mycroft.internal.api.dto.MessageSpeak; +import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeDecrease; +import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeDuck; +import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeGet; +import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeGetResponse; +import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeIncrease; +import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeMute; +import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeSet; +import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeUnduck; +import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeUnmute; + +/** + * All message type of interest, issued by Mycroft, are referenced here + * + * @author Gwendal ROULLEAU - Initial contribution + */ +@NonNullByDefault +public enum MessageType { + + any("special-anymessages", BaseMessage.class), + speak("speak", MessageSpeak.class), + recognizer_loop__record_begin("recognizer_loop:record_begin", MessageRecognizerLoopRecordBegin.class), + recognizer_loop__record_end("recognizer_loop:record_end", MessageRecognizerLoopRecordEnd.class), + recognizer_loop__utterance("recognizer_loop:utterance", MessageRecognizerLoopUtterance.class), + mycroft_mic_listen("mycroft.mic.listen", MessageMicListen.class), + + mycroft_audio_service_pause("mycroft.audio.service.pause", MessageAudioPause.class), + mycroft_audio_service_resume("mycroft.audio.service.resume", MessageAudioResume.class), + mycroft_audio_service_stop("mycroft.audio.service.stop", MessageAudioStop.class), + mycroft_audio_service_play("mycroft.audio.service.play", MessageAudioPlay.class), + mycroft_audio_service_next("mycroft.audio.service.next", MessageAudioNext.class), + mycroft_audio_service_prev("mycroft.audio.service.prev", MessageAudioPrev.class), + mycroft_audio_service_track_info("mycroft.audio.service.track_info", MessageAudioTrackInfo.class), + mycroft_audio_service_track_info_reply("mycroft.audio.service.track_info_reply", MessageAudioTrackInfoReply.class), + + mycroft_volume_set("mycroft.volume.set", MessageVolumeSet.class), + mycroft_volume_increase("mycroft.volume.increase", MessageVolumeIncrease.class), + mycroft_volume_decrease("mycroft.volume.decrease", MessageVolumeDecrease.class), + mycroft_volume_get("mycroft.volume.get", MessageVolumeGet.class), + mycroft_volume_get_response("mycroft.volume.get.response", MessageVolumeGetResponse.class), + mycroft_volume_mute("mycroft.volume.mute", MessageVolumeMute.class), + mycroft_volume_unmute("mycroft.volume.unmute", MessageVolumeUnmute.class), + mycroft_volume_duck("mycroft.volume.duck", MessageVolumeDuck.class), + mycroft_volume_unduck("mycroft.volume.unduck", MessageVolumeUnduck.class), + + mycroft_reminder_mycroftai__reminder("mycroft-reminder.mycroftai:reminder", BaseMessage.class), + mycroft_date_time_mycroftai__timeskillupdate_display("mycroft-date-time.mycroftai:TimeSkillupdate_display", + BaseMessage.class), + mycroft_configuration_mycroftai__configurationskillupdate_remote( + "mycroft-configuration.mycroftai:ConfigurationSkillupdate_remote", BaseMessage.class); + + private @NotNull Class messageTypeClass; + private @NotNull String messageTypeName; + + MessageType(String messageTypeName, Class messageType) { + this.messageTypeClass = messageType; + this.messageTypeName = messageTypeName; + } + + /** + * get the expected message type for this message type + * + * @return + */ + public @NotNull Class getMessageTypeClass() { + return messageTypeClass; + } + + @NotNull + public static MessageType fromString(String asString) { + return Stream.of(values()).filter(messageType -> messageType.messageTypeName.equals(asString)).findFirst() + .orElse(any); + } + + public String getMessageTypeName() { + return messageTypeName; + } + + protected void setMessageTypeName(String messageTypeName) { + this.messageTypeName = messageTypeName; + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageTypeConverter.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageTypeConverter.java new file mode 100644 index 0000000000000..11a8800bb3ed4 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageTypeConverter.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api; + +import java.lang.reflect.Type; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +/** + * Custom deserializer for {@link LightType} + * + * @author Gwendal Roulleau - Initial contribution + */ +@NonNullByDefault +public class MessageTypeConverter implements JsonDeserializer, JsonSerializer { + @Override + public @Nullable MessageType deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + MessageType messageType = MessageType.fromString(json.getAsString()); + // for message of type non recognized : + messageType.setMessageTypeName(json.getAsString()); + return messageType; + } + + @Override + public JsonElement serialize(MessageType src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.getMessageTypeName()); + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java new file mode 100644 index 0000000000000..8bce75a2b9800 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java @@ -0,0 +1,268 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api; + +import java.io.IOException; +import java.net.URI; +import java.util.HashSet; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.jetty.websocket.api.Session; +import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose; +import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect; +import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError; +import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; +import org.eclipse.jetty.websocket.api.annotations.WebSocket; +import org.eclipse.jetty.websocket.client.WebSocketClient; +import org.openhab.binding.mycroft.internal.api.dto.BaseMessage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +/** + * Establishes and keeps a websocket connection to the Mycroft bus + * + * @author Gwendal ROULLEAU - Initial contribution. Inspired by the deconz binding. + */ +@WebSocket +@NonNullByDefault +public class MycroftConnection { + private static final AtomicInteger INSTANCE_COUNTER = new AtomicInteger(); + private final Logger logger = LoggerFactory.getLogger(MycroftConnection.class); + + private final WebSocketClient client; + private final String socketName; + private final Gson gson; + + private final MycroftConnectionListener connectionListener; + private final Map>> listeners = new ConcurrentHashMap<>(); + + private ConnectionState connectionState = ConnectionState.DISCONNECTED; + private @Nullable Session session; + + private static final int TIMEOUT_MILLISECONDS = 3000; + + public MycroftConnection(MycroftConnectionListener listener, WebSocketClient client) { + this.connectionListener = listener; + this.client = client; + this.client.setConnectTimeout(TIMEOUT_MILLISECONDS); + this.client.setMaxIdleTimeout(0); + this.socketName = "Websocket$" + System.currentTimeMillis() + "-" + INSTANCE_COUNTER.incrementAndGet(); + + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(MessageType.class, new MessageTypeConverter()); + gson = gsonBuilder.create(); + } + + public MycroftConnection(MycroftConnectionListener listener) { + this.connectionListener = listener; + this.client = new WebSocketClient(); + this.client.setMaxIdleTimeout(0); + this.client.setConnectTimeout(TIMEOUT_MILLISECONDS); + this.socketName = "Websocket$" + System.currentTimeMillis() + "-" + INSTANCE_COUNTER.incrementAndGet(); + + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(MessageType.class, new MessageTypeConverter()); + gson = gsonBuilder.create(); + } + + public void start(String ip, int port) { + if (connectionState == ConnectionState.CONNECTED) { + return; + } else if (connectionState == ConnectionState.CONNECTING) { + logger.debug("{} already connecting", socketName); + return; + } else if (connectionState == ConnectionState.DISCONNECTING) { + logger.warn("{} trying to re-connect while still disconnecting", socketName); + } + Future futureConnect = null; + try { + URI destUri = URI.create("ws://" + ip + ":" + port + "/core"); + client.start(); + logger.debug("Trying to connect {} to {}", socketName, destUri); + futureConnect = client.connect(this, destUri); + futureConnect.get(TIMEOUT_MILLISECONDS, TimeUnit.MILLISECONDS); + } catch (Exception e) { + if (futureConnect != null) { + futureConnect.cancel(true); + } + connectionListener + .connectionLost("Error while connecting: " + (e.getMessage() != null ? e.getMessage() : "unknown")); + } + } + + public void close() { + try { + connectionState = ConnectionState.DISCONNECTING; + client.stop(); + } catch (Exception e) { + logger.debug("{} encountered an error while closing connection", socketName, e); + } + client.destroy(); + } + + /** + * The listener registered in this method will be called when a corresponding message will be detected + * on the mycroft bus + * + * @param messageType + * @param listener + */ + public void registerListener(MessageType messageType, MycroftMessageListener listener) { + Set> messageTypeListeners = listeners.get(messageType); + if (messageTypeListeners == null) { + messageTypeListeners = new HashSet>(); + listeners.put(messageType, messageTypeListeners); + } + messageTypeListeners.add(listener); + } + + public void unregisterListener(MessageType messageType, MycroftMessageListener listener) { + Optional.ofNullable(listeners.get(messageType)) + .ifPresent((messageTypeListeners) -> messageTypeListeners.remove(listener)); + } + + public void sendMessage(BaseMessage message) throws IOException { + sendMessage(gson.toJson(message)); + } + + public void sendMessage(String message) throws IOException { + final Session storedSession = this.session; + try { + if (storedSession != null) { + storedSession.getRemote().sendString(message); + } else { + throw new IOException("Session is not initialized"); + } + } catch (IOException e) { + if (storedSession != null && storedSession.isOpen()) { + storedSession.close(-1, "Sending message error"); + } + throw e; + } + } + + @OnWebSocketConnect + public void onConnect(Session session) { + connectionState = ConnectionState.CONNECTED; + logger.debug("{} successfully connected to {}: {}", socketName, session.getRemoteAddress().getAddress(), + session.hashCode()); + connectionListener.connectionEstablished(); + this.session = session; + } + + @OnWebSocketMessage + public void onMessage(Session session, String message) { + if (!session.equals(this.session)) { + handleWrongSession(session, message); + return; + } + logger.trace("{} received raw data: {}", socketName, message); + + try { + + // listeners on message type : + BaseMessage mycroftMessage = gson.fromJson(message, BaseMessage.class); + Objects.requireNonNull(mycroftMessage); + mycroftMessage.message = message; + + // special listener : to any messages + Set> listenersAnyToNotify = listeners.get(MessageType.any); + if (listenersAnyToNotify != null && !listenersAnyToNotify.isEmpty()) { + for (MycroftMessageListener listener : listenersAnyToNotify) { + listener.baseMessageReceived(mycroftMessage); + } + } + + // listener for specific message type + Set> listenersToNotify = listeners.get(mycroftMessage.type); + if (mycroftMessage.type != MessageType.any && listenersToNotify != null && !listenersToNotify.isEmpty()) { + BaseMessage fullMycroftMessage = gson.fromJson(message, mycroftMessage.type.getMessageTypeClass()); + mycroftMessage.message = message; + Objects.requireNonNull(fullMycroftMessage); + listenersToNotify.forEach(listener -> listener.baseMessageReceived(fullMycroftMessage)); + } + + } catch (RuntimeException e) { + // we need to catch all processing exceptions, otherwise they could affect the connection + logger.warn("{} encountered an error while processing the message {}: {}", socketName, message, + e.getMessage()); + } + } + + @OnWebSocketError + public void onError(@Nullable Session session, Throwable cause) { + + if (session == null || !session.equals(this.session)) { + handleWrongSession(session, "Connection error: " + cause.getMessage()); + return; + } + logger.warn("{} connection error, closing: {}", socketName, cause.getMessage()); + + Session storedSession = this.session; + if (storedSession != null && storedSession.isOpen()) { + storedSession.close(-1, "Processing error"); + } + } + + @OnWebSocketClose + public void onClose(Session session, int statusCode, String reason) { + if (!session.equals(this.session)) { + handleWrongSession(session, "Connection closed: " + statusCode + " / " + reason); + return; + } + logger.trace("{} closed connection: {} / {}", socketName, statusCode, reason); + connectionState = ConnectionState.DISCONNECTED; + this.session = null; + connectionListener.connectionLost(reason); + } + + private void handleWrongSession(@Nullable Session session, String message) { + if (session == null) { + logger.warn("received and discarded message for null session : {}", message); + } else { + logger.warn("{} received and discarded message for other session {}: {}.", socketName, session.hashCode(), + message); + } + } + + /** + * check connection state (successfully connected) + * + * @return true if connected, false if connecting, disconnecting or disconnected + */ + public boolean isConnected() { + return connectionState == ConnectionState.CONNECTED; + } + + /** + * used internally to represent the connection state + */ + private enum ConnectionState { + CONNECTING, + CONNECTED, + DISCONNECTING, + DISCONNECTED + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnectionListener.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnectionListener.java new file mode 100644 index 0000000000000..c6256a39e6344 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnectionListener.java @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api; + +import org.eclipse.jdt.annotation.NonNullByDefault; + +/** + * Informs about the websocket connection. + * + * @author Gwendal Roulleau - Initial contribution + */ +@NonNullByDefault +public interface MycroftConnectionListener { + /** + * Connection successfully established. + */ + void connectionEstablished(); + + /** + * Connection lost. A reconnect timer has been started. + * + * @param reason A reason for the disconnection + */ + void connectionLost(String reason); +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftMessageListener.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftMessageListener.java new file mode 100644 index 0000000000000..f8d549cf62246 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftMessageListener.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.binding.mycroft.internal.api.dto.BaseMessage; + +/** + * Informs about received messages + * + * @author Gwendal Roulleau - Initial contribution + */ +@NonNullByDefault +public interface MycroftMessageListener { + /** + * A new message was received + * + * @param message The received message + */ + void messageReceived(T message); + + @SuppressWarnings("unchecked") + default void baseMessageReceived(BaseMessage baseMessage) { + try { + messageReceived(((T) baseMessage)); + } catch (ClassCastException cce) { + throw new ClassCastException("Incorrect use of message in Mycroft binding"); + } + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/BaseMessage.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/BaseMessage.java new file mode 100644 index 0000000000000..649cdc96ca4d7 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/BaseMessage.java @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api.dto; + +import org.openhab.binding.mycroft.internal.api.MessageType; + +/** + * + * @author Gwendal ROULLEAU - Initial contribution + */ +public class BaseMessage { + + public MessageType type; + public String message = ""; +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioNext.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioNext.java new file mode 100644 index 0000000000000..062316c9f0c3f --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioNext.java @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api.dto; + +import org.openhab.binding.mycroft.internal.api.MessageType; + +/** + * + * @author Gwendal ROULLEAU - Initial Contribution + * + */ +public class MessageAudioNext extends BaseMessage { + + public MessageAudioNext() { + this.type = MessageType.mycroft_audio_service_next; + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPause.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPause.java new file mode 100644 index 0000000000000..27c614944088f --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPause.java @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api.dto; + +import org.openhab.binding.mycroft.internal.api.MessageType; + +/** + * + * @author Gwendal ROULLEAU - Initial contribution + */ +public class MessageAudioPause extends BaseMessage { + + public MessageAudioPause() { + this.type = MessageType.mycroft_audio_service_pause; + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPlay.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPlay.java new file mode 100644 index 0000000000000..b9f1e0335980a --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPlay.java @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api.dto; + +import org.openhab.binding.mycroft.internal.api.MessageType; + +/** + * + * @author Gwendal ROULLEAU - Initial contribution + * + */ +public class MessageAudioPlay extends BaseMessage { + + public MessageAudioPlay() { + this.type = MessageType.mycroft_audio_service_play; + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPrev.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPrev.java new file mode 100644 index 0000000000000..76d03fabdb8a3 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPrev.java @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api.dto; + +import org.openhab.binding.mycroft.internal.api.MessageType; + +/** + * + * @author Gwendal ROULLEAU - Initial contribution + * + */ +public class MessageAudioPrev extends BaseMessage { + + public MessageAudioPrev() { + this.type = MessageType.mycroft_audio_service_prev; + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioResume.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioResume.java new file mode 100644 index 0000000000000..9de316e87dc61 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioResume.java @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api.dto; + +import org.openhab.binding.mycroft.internal.api.MessageType; + +/** + * + * @author Gwendal ROULLEAU - Initial contribution + * + */ +public class MessageAudioResume extends BaseMessage { + + public MessageAudioResume() { + this.type = MessageType.mycroft_audio_service_resume; + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioStop.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioStop.java new file mode 100644 index 0000000000000..17d42dd3f48ab --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioStop.java @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api.dto; + +import org.openhab.binding.mycroft.internal.api.MessageType; + +/** + * + * @author Gwendal ROULLEAU - Initial contribution + */ +public class MessageAudioStop extends BaseMessage { + + public MessageAudioStop() { + this.type = MessageType.mycroft_audio_service_stop; + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfo.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfo.java new file mode 100644 index 0000000000000..8415f8ad022e5 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfo.java @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api.dto; + +import org.openhab.binding.mycroft.internal.api.MessageType; + +/** + * + * @author Gwendal ROULLEAU - Initial contribution + */ +public class MessageAudioTrackInfo extends BaseMessage { + + public MessageAudioTrackInfo() { + this.type = MessageType.mycroft_audio_service_track_info; + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfoReply.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfoReply.java new file mode 100644 index 0000000000000..1ea96c6891f7b --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfoReply.java @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api.dto; + +import org.openhab.binding.mycroft.internal.api.MessageType; + +/** + * + * @author Gwendal ROULLEAU - Initial contribution + */ +public class MessageAudioTrackInfoReply extends BaseMessage { + + public MessageAudioTrackInfoReply() { + this.type = MessageType.mycroft_audio_service_track_info_reply; + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageMicListen.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageMicListen.java new file mode 100644 index 0000000000000..da2267cc47849 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageMicListen.java @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api.dto; + +import org.openhab.binding.mycroft.internal.api.MessageType; + +/** + * + * @author Gwendal ROULLEAU - Initial contribution + */ +public class MessageMicListen extends BaseMessage { + + public MessageMicListen() { + this.type = MessageType.mycroft_mic_listen; + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordBegin.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordBegin.java new file mode 100644 index 0000000000000..28468bbcc5518 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordBegin.java @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api.dto; + +import org.openhab.binding.mycroft.internal.api.MessageType; + +/** + * + * @author Gwendal ROULLEAU - Initial contribution + */ +public class MessageRecognizerLoopRecordBegin extends BaseMessage { + + public Context context = new Context(); + + public MessageRecognizerLoopRecordBegin() { + this.type = MessageType.recognizer_loop__record_begin; + } + + public static class Context { + public String client_name = ""; + public String source = ""; + public String destination = ""; + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordEnd.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordEnd.java new file mode 100644 index 0000000000000..abf92e9e293b9 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordEnd.java @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api.dto; + +import org.openhab.binding.mycroft.internal.api.MessageType; + +/** + * + * @author Gwendal ROULLEAU - Initial contribution + */ +public class MessageRecognizerLoopRecordEnd extends BaseMessage { + + public Context context = new Context(); + + public MessageRecognizerLoopRecordEnd() { + this.type = MessageType.recognizer_loop__record_end; + } + + public static class Context { + public String client_name = ""; + public String source = ""; + public String destination = ""; + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopUtterance.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopUtterance.java new file mode 100644 index 0000000000000..1937af97e7fab --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopUtterance.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api.dto; + +import java.util.ArrayList; +import java.util.List; + +import org.openhab.binding.mycroft.internal.api.MessageType; + +/** + * + * @author Gwendal ROULLEAU - Initial contribution + */ +public class MessageRecognizerLoopUtterance extends BaseMessage { + + public Data data = new Data(); + + public Context context = new Context(); + + public MessageRecognizerLoopUtterance() { + this.type = MessageType.recognizer_loop__utterance; + } + + public MessageRecognizerLoopUtterance(String utterance) { + this(); + this.data.utterances.add(utterance); + this.context.client_name = "java_api"; + this.context.source = "audio"; + this.context.destination.add("skills"); + } + + public static class Data { + public List utterances = new ArrayList<>(); + } + + public static class Context { + public String client_name = ""; + public String source = ""; + public List destination = new ArrayList<>(); + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageSpeak.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageSpeak.java new file mode 100644 index 0000000000000..e307e3d8c1996 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageSpeak.java @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api.dto; + +import java.util.ArrayList; +import java.util.List; + +import org.openhab.binding.mycroft.internal.api.MessageType; + +/** + * + * @author Gwendal ROULLEAU - Initial contribution + */ +public class MessageSpeak extends BaseMessage { + + public Data data = new Data(); + + public Context context = new Context(); + + public MessageSpeak() { + this.type = MessageType.speak; + } + + public MessageSpeak(String textToSay) { + this(); + this.data = new Data(); + this.data.utterance = textToSay; + } + + public static class Data { + public String utterance = ""; + public String expect_response = ""; + }; + + public static class Context { + public String client_name = ""; + public List source = new ArrayList<>(); + public String destination = ""; + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDecrease.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDecrease.java new file mode 100644 index 0000000000000..f2f4239c64f49 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDecrease.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api.dto; + +import org.openhab.binding.mycroft.internal.api.MessageType; + +/** + * + * @author Gwendal ROULLEAU - Initial contribution + */ +public class MessageVolumeDecrease extends BaseMessage { + + public Data data = new Data(); + + public MessageVolumeDecrease() { + this.type = MessageType.mycroft_volume_decrease; + } + + public static class Data { + public Boolean play_sound = true; + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDuck.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDuck.java new file mode 100644 index 0000000000000..cce27468e9f24 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDuck.java @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api.dto; + +import org.openhab.binding.mycroft.internal.api.MessageType; + +/** + * + * @author Gwendal ROULLEAU - Initial contribution + */ +public class MessageVolumeDuck extends BaseMessage { + + public Data data = new Data(); + public Context context = new Context(); + + public MessageVolumeDuck() { + this.type = MessageType.mycroft_volume_duck; + } + + public static final class Data { + } + + public static final class Context { + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGet.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGet.java new file mode 100644 index 0000000000000..8ef06cce84916 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGet.java @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api.dto; + +import org.openhab.binding.mycroft.internal.api.MessageType; + +/** + * + * @author Gwendal ROULLEAU - Initial contribution + */ +public class MessageVolumeGet extends BaseMessage { + + public Data data = new Data(); + public Context context = new Context(); + + public MessageVolumeGet() { + this.type = MessageType.mycroft_volume_get; + } + + public static final class Data { + } + + public static final class Context { + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGetResponse.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGetResponse.java new file mode 100644 index 0000000000000..6792e5c68f8ec --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGetResponse.java @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api.dto; + +import org.openhab.binding.mycroft.internal.api.MessageType; + +/** + * + * @author Gwendal ROULLEAU - Initial contribution + */ +public class MessageVolumeGetResponse extends BaseMessage { + + public Data data = new Data(); + + public MessageVolumeGetResponse() { + this.type = MessageType.mycroft_volume_get_response; + } + + public static class Data { + public float percent = 0; + public Boolean muted = false; + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeIncrease.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeIncrease.java new file mode 100644 index 0000000000000..466208e283b61 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeIncrease.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api.dto; + +import org.openhab.binding.mycroft.internal.api.MessageType; + +/** + * + * @author Gwendal ROULLEAU - Initial contribution + */ +public class MessageVolumeIncrease extends BaseMessage { + + public Data data = new Data(); + + public MessageVolumeIncrease() { + this.type = MessageType.mycroft_volume_increase; + } + + public static class Data { + public Boolean play_sound = true; + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeMute.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeMute.java new file mode 100644 index 0000000000000..e28b631287ba2 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeMute.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api.dto; + +import org.openhab.binding.mycroft.internal.api.MessageType; + +/** + * + * @author Gwendal ROULLEAU - Initial contribution + */ +public class MessageVolumeMute extends BaseMessage { + + public Data data = new Data(); + + public MessageVolumeMute() { + this.type = MessageType.mycroft_volume_mute; + } + + public static class Data { + public Boolean speak_message = false; + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeSet.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeSet.java new file mode 100644 index 0000000000000..9872bf77b30f9 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeSet.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api.dto; + +import org.openhab.binding.mycroft.internal.api.MessageType; + +/** + * + * @author Gwendal ROULLEAU - Initial contribution + */ +public class MessageVolumeSet extends BaseMessage { + + public Data data = new Data(); + + public MessageVolumeSet() { + this.type = MessageType.mycroft_volume_set; + } + + public static class Data { + public float percent = 0; + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnduck.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnduck.java new file mode 100644 index 0000000000000..eb3ca059bc7f8 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnduck.java @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api.dto; + +import org.openhab.binding.mycroft.internal.api.MessageType; + +/** + * + * @author Gwendal ROULLEAU - Initial contribution + */ +public class MessageVolumeUnduck extends BaseMessage { + + public Data data = new Data(); + public Context context = new Context(); + + public MessageVolumeUnduck() { + this.type = MessageType.mycroft_volume_unduck; + } + + public static final class Data { + } + + public static final class Context { + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnmute.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnmute.java new file mode 100644 index 0000000000000..79525eba55e2d --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnmute.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api.dto; + +import org.openhab.binding.mycroft.internal.api.MessageType; + +/** + * + * @author Gwendal ROULLEAU - Initial contribution + */ +public class MessageVolumeUnmute extends BaseMessage { + + public Data data = new Data(); + + public MessageVolumeUnmute() { + this.type = MessageType.mycroft_volume_unmute; + } + + public static class Data { + public Boolean speak_message = false; + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/AudioPlayerChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/AudioPlayerChannel.java new file mode 100644 index 0000000000000..d69429f711d9d --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/AudioPlayerChannel.java @@ -0,0 +1,98 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.channels; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.binding.mycroft.internal.MycroftBindingConstants; +import org.openhab.binding.mycroft.internal.MycroftHandler; +import org.openhab.binding.mycroft.internal.api.MessageType; +import org.openhab.binding.mycroft.internal.api.dto.BaseMessage; +import org.openhab.binding.mycroft.internal.api.dto.MessageAudioNext; +import org.openhab.binding.mycroft.internal.api.dto.MessageAudioPause; +import org.openhab.binding.mycroft.internal.api.dto.MessageAudioPlay; +import org.openhab.binding.mycroft.internal.api.dto.MessageAudioPrev; +import org.openhab.binding.mycroft.internal.api.dto.MessageAudioResume; +import org.openhab.core.library.types.NextPreviousType; +import org.openhab.core.library.types.PlayPauseType; +import org.openhab.core.types.Command; +import org.openhab.core.types.State; + +/** + * This channel handle the Mycroft capability to act as a music player + * (depending on common play music skills installed) + * + * @author Gwendal ROULLEAU - Initial contribution + */ +@NonNullByDefault +public class AudioPlayerChannel extends MycroftChannel { + + public AudioPlayerChannel(MycroftHandler handler) { + super(handler, MycroftBindingConstants.PLAYER_CHANNEL); + } + + @Override + protected List getMessageToListenTo() { + return Arrays.asList(MessageType.mycroft_audio_service_prev, MessageType.mycroft_audio_service_next, + MessageType.mycroft_audio_service_pause, MessageType.mycroft_audio_service_resume, + MessageType.mycroft_audio_service_play, MessageType.mycroft_audio_service_stop, + MessageType.mycroft_audio_service_track_info, MessageType.mycroft_audio_service_track_info_reply); + } + + @Override + public void messageReceived(BaseMessage message) { + switch (message.type) { + case mycroft_audio_service_pause: + case mycroft_audio_service_stop: + updateMyState(PlayPauseType.PAUSE); + break; + case mycroft_audio_service_play: + case mycroft_audio_service_resume: + updateMyState(PlayPauseType.PLAY); + break; + default: + break; + } + } + + @Override + public void handleCommand(Command command) { + if (command instanceof PlayPauseType) { + if (((PlayPauseType) command) == PlayPauseType.PAUSE) { + if (handler.sendMessage(new MessageAudioPause())) { + updateMyState(PlayPauseType.PAUSE); + } + } + if (((PlayPauseType) command) == PlayPauseType.PLAY) { + handler.sendMessage(new MessageAudioPlay()); + if (handler.sendMessage(new MessageAudioResume())) { + updateMyState(PlayPauseType.PLAY); + } + } + } + if (command instanceof NextPreviousType) { + if (((NextPreviousType) command) == NextPreviousType.NEXT) { + if (handler.sendMessage(new MessageAudioNext())) { + updateMyState(PlayPauseType.PLAY); + } + } + if (((NextPreviousType) command) == NextPreviousType.PREVIOUS) { + if (handler.sendMessage(new MessageAudioPrev())) { + updateMyState(PlayPauseType.PLAY); + } + } + } + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ChannelCommandHandler.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ChannelCommandHandler.java new file mode 100644 index 0000000000000..98831fbd23a81 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ChannelCommandHandler.java @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.channels; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.core.types.Command; + +/** + * Interface for channel which can handle command + * + * @author Gwendal ROULLEAU - Initial contribution + */ +@NonNullByDefault +public interface ChannelCommandHandler { + + public void handleCommand(Command command); +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/DuckChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/DuckChannel.java new file mode 100644 index 0000000000000..22e95cd24ab51 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/DuckChannel.java @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.channels; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.binding.mycroft.internal.MycroftBindingConstants; +import org.openhab.binding.mycroft.internal.MycroftHandler; +import org.openhab.binding.mycroft.internal.api.MessageType; +import org.openhab.binding.mycroft.internal.api.dto.BaseMessage; +import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeDuck; +import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeUnduck; +import org.openhab.core.library.types.OnOffType; +import org.openhab.core.types.Command; + +/** + * The channel responsible for triggering STT recognition + * + * @author Gwendal ROULLEAU - Initial contribution + */ +@NonNullByDefault +public class DuckChannel extends MycroftChannel { + + public DuckChannel(MycroftHandler handler) { + super(handler, MycroftBindingConstants.VOLUME_DUCK_CHANNEL); + } + + @Override + public List getMessageToListenTo() { + return Arrays.asList(MessageType.mycroft_volume_duck, MessageType.mycroft_volume_unduck); + } + + @Override + public void messageReceived(BaseMessage message) { + if (message.type == MessageType.mycroft_volume_duck) { + updateMyState(OnOffType.ON); + } else if (message.type == MessageType.mycroft_volume_unduck) { + updateMyState(OnOffType.OFF); + } + } + + @Override + public void handleCommand(Command command) { + if (command instanceof OnOffType) { + if (command == OnOffType.ON) { + if (handler.sendMessage(new MessageVolumeDuck())) { + updateMyState(OnOffType.ON); + } + } else if (command == OnOffType.OFF) { + if (handler.sendMessage(new MessageVolumeUnduck())) { + updateMyState(OnOffType.OFF); + } + } + } + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/FullMessageChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/FullMessageChannel.java new file mode 100644 index 0000000000000..55ceab488f621 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/FullMessageChannel.java @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.channels; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.binding.mycroft.internal.MycroftBindingConstants; +import org.openhab.binding.mycroft.internal.MycroftHandler; +import org.openhab.binding.mycroft.internal.api.MessageType; +import org.openhab.binding.mycroft.internal.api.dto.BaseMessage; +import org.openhab.core.library.types.StringType; +import org.openhab.core.types.Command; + +/** + * The channel responsible for sending/receiving raw message + * + * @author Gwendal ROULLEAU - Initial contribution + */ +@NonNullByDefault +public class FullMessageChannel extends MycroftChannel { + + private List messageTypesList = new ArrayList<>(); + + public FullMessageChannel(MycroftHandler handler, String messageTypesList) { + super(handler, MycroftBindingConstants.FULL_MESSAGE_CHANNEL); + for (String messageType : messageTypesList.split(",")) { + this.messageTypesList.add(messageType.trim()); + } + } + + @Override + public List getMessageToListenTo() { + return Arrays.asList(MessageType.any); + } + + @Override + public void messageReceived(BaseMessage message) { + if (messageTypesList.contains(message.type.getMessageTypeName())) { + updateMyState(new StringType(message.message)); + } + } + + @Override + public void handleCommand(Command command) { + if (command instanceof StringType) { + if (handler.sendMessage(command.toString())) { + updateMyState(new StringType(command.toString())); + } + } + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ListenChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ListenChannel.java new file mode 100644 index 0000000000000..ba654dd650574 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ListenChannel.java @@ -0,0 +1,61 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.channels; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.binding.mycroft.internal.MycroftBindingConstants; +import org.openhab.binding.mycroft.internal.MycroftHandler; +import org.openhab.binding.mycroft.internal.api.MessageType; +import org.openhab.binding.mycroft.internal.api.dto.BaseMessage; +import org.openhab.binding.mycroft.internal.api.dto.MessageMicListen; +import org.openhab.core.library.types.OnOffType; +import org.openhab.core.types.Command; + +/** + * The channel responsible for triggering STT recognition + * + * @author Gwendal ROULLEAU - Initial contribution + */ +@NonNullByDefault +public class ListenChannel extends MycroftChannel { + + public ListenChannel(MycroftHandler handler) { + super(handler, MycroftBindingConstants.LISTEN_CHANNEL); + } + + @Override + public List getMessageToListenTo() { + return Arrays.asList(MessageType.recognizer_loop__record_begin, MessageType.recognizer_loop__record_end); + } + + @Override + public void messageReceived(BaseMessage message) { + if (message.type == MessageType.recognizer_loop__record_begin) { + updateMyState(OnOffType.ON); + } else if (message.type == MessageType.recognizer_loop__record_end) { + updateMyState(OnOffType.OFF); + } + } + + @Override + public void handleCommand(Command command) { + if (command instanceof OnOffType) { + if (command == OnOffType.ON) { + handler.sendMessage(new MessageMicListen()); + } + } + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MuteChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MuteChannel.java new file mode 100644 index 0000000000000..f99aa1150c020 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MuteChannel.java @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.channels; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.binding.mycroft.internal.MycroftBindingConstants; +import org.openhab.binding.mycroft.internal.MycroftHandler; +import org.openhab.binding.mycroft.internal.api.MessageType; +import org.openhab.binding.mycroft.internal.api.dto.BaseMessage; +import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeMute; +import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeUnmute; +import org.openhab.core.library.types.OnOffType; +import org.openhab.core.types.Command; + +/** + * The channel responsible for muting the Mycroft speaker + * + * @author Gwendal ROULLEAU - Initial contribution + */ +@NonNullByDefault +public class MuteChannel extends MycroftChannel { + + public MuteChannel(MycroftHandler handler) { + super(handler, MycroftBindingConstants.VOLUME_MUTE_CHANNEL); + } + + @Override + public List getMessageToListenTo() { + return Arrays.asList(MessageType.mycroft_volume_mute, MessageType.mycroft_volume_unmute); + } + + @Override + public void messageReceived(BaseMessage message) { + if (message.type == MessageType.mycroft_volume_mute) { + updateMyState(OnOffType.ON); + } else if (message.type == MessageType.mycroft_volume_unmute) { + updateMyState(OnOffType.OFF); + } + } + + @Override + public void handleCommand(Command command) { + if (command instanceof OnOffType) { + if (command == OnOffType.ON) { + if (handler.sendMessage(new MessageVolumeMute())) { + updateMyState(OnOffType.ON); + } + } else if (command == OnOffType.OFF) { + if (handler.sendMessage(new MessageVolumeUnmute())) { + updateMyState(OnOffType.OFF); + } + } + } + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MycroftChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MycroftChannel.java new file mode 100644 index 0000000000000..b8452d535b0a6 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MycroftChannel.java @@ -0,0 +1,70 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.channels; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.binding.mycroft.internal.MycroftHandler; +import org.openhab.binding.mycroft.internal.api.MessageType; +import org.openhab.binding.mycroft.internal.api.MycroftMessageListener; +import org.openhab.binding.mycroft.internal.api.dto.BaseMessage; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.types.State; + +/** + * A helper method for channel handling + * + * @author Gwendal ROULLEAU - Initial contribution + */ +@NonNullByDefault +public abstract class MycroftChannel + implements ChannelCommandHandler, MycroftMessageListener { + + private ChannelUID channelUID; + protected MycroftHandler handler; + + public MycroftChannel(MycroftHandler handler, String channelUIDPart) { + this.handler = handler; + this.channelUID = new ChannelUID(handler.getThing().getUID(), channelUIDPart); + } + + public final ChannelUID getChannelUID() { + return channelUID; + } + + protected final void updateMyState(T state) { + handler.updateMyChannel(this, state); + } + + public final void registerListeners() { + for (MessageType messageType : getMessageToListenTo()) { + handler.registerMessageListener(messageType, this); + } + } + + protected List getMessageToListenTo() { + return new ArrayList<>(); + } + + public final void unregisterListeners() { + for (MessageType messageType : getMessageToListenTo()) { + handler.unregisterMessageListener(messageType, this); + } + } + + @Override + public void messageReceived(BaseMessage message) { + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/SpeakChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/SpeakChannel.java new file mode 100644 index 0000000000000..2d4c8a9ebe770 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/SpeakChannel.java @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.channels; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.binding.mycroft.internal.MycroftBindingConstants; +import org.openhab.binding.mycroft.internal.MycroftHandler; +import org.openhab.binding.mycroft.internal.api.MessageType; +import org.openhab.binding.mycroft.internal.api.dto.BaseMessage; +import org.openhab.binding.mycroft.internal.api.dto.MessageSpeak; +import org.openhab.core.library.types.StringType; +import org.openhab.core.types.Command; + +/** + * The channel responsible for TSS + * + * @author Gwendal ROULLEAU - Initial contribution + */ +@NonNullByDefault +public class SpeakChannel extends MycroftChannel { + + public SpeakChannel(MycroftHandler handler) { + super(handler, MycroftBindingConstants.SPEAK_CHANNEL); + } + + @Override + public List getMessageToListenTo() { + return Arrays.asList(MessageType.speak); + } + + @Override + public void messageReceived(BaseMessage message) { + if (message.type == MessageType.speak) { + MessageSpeak messageSpeak = (MessageSpeak) message; + updateMyState(new StringType(messageSpeak.data.utterance)); + } + } + + @Override + public void handleCommand(Command command) { + if (command instanceof StringType) { + if (handler.sendMessage(new MessageSpeak(command.toString()))) { + updateMyState(new StringType(command.toString())); + } + } + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/UtteranceChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/UtteranceChannel.java new file mode 100644 index 0000000000000..6682c92ea6428 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/UtteranceChannel.java @@ -0,0 +1,63 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.channels; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.binding.mycroft.internal.MycroftBindingConstants; +import org.openhab.binding.mycroft.internal.MycroftHandler; +import org.openhab.binding.mycroft.internal.api.MessageType; +import org.openhab.binding.mycroft.internal.api.dto.BaseMessage; +import org.openhab.binding.mycroft.internal.api.dto.MessageRecognizerLoopUtterance; +import org.openhab.core.library.types.StringType; +import org.openhab.core.types.Command; + +/** + * This channel handle the full utterance send or received by Mycroft, before any intent recognition + * + * @author Gwendal ROULLEAU - Initial contribution + * + */ +@NonNullByDefault +public class UtteranceChannel extends MycroftChannel { + + public UtteranceChannel(MycroftHandler handler) { + super(handler, MycroftBindingConstants.UTTERANCE_CHANNEL); + } + + @Override + protected List getMessageToListenTo() { + return Arrays.asList(MessageType.recognizer_loop__utterance); + } + + @Override + public void messageReceived(BaseMessage message) { + if (message.type == MessageType.recognizer_loop__utterance) { + List utterances = ((MessageRecognizerLoopUtterance) message).data.utterances; + if (!utterances.isEmpty()) { + updateMyState(new StringType(utterances.get(0))); + } + } + } + + @Override + public void handleCommand(Command command) { + if (command instanceof StringType) { + MessageRecognizerLoopUtterance utteranceMessage = new MessageRecognizerLoopUtterance(command.toString()); + handler.sendMessage(utteranceMessage); + updateMyState(new StringType(command.toString())); + } + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java new file mode 100644 index 0000000000000..591d07b7b66dd --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java @@ -0,0 +1,163 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.channels; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.binding.mycroft.internal.MycroftBindingConstants; +import org.openhab.binding.mycroft.internal.MycroftHandler; +import org.openhab.binding.mycroft.internal.api.MessageType; +import org.openhab.binding.mycroft.internal.api.dto.BaseMessage; +import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeDecrease; +import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeGet; +import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeGetResponse; +import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeIncrease; +import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeSet; +import org.openhab.core.library.types.IncreaseDecreaseType; +import org.openhab.core.library.types.OnOffType; +import org.openhab.core.library.types.PercentType; +import org.openhab.core.types.Command; +import org.openhab.core.types.RefreshType; +import org.openhab.core.types.State; + +/** + * The channel responsible for handling the volume of the Mycroft speaker + * + * @author Gwendal ROULLEAU - Initial contribution + */ +@NonNullByDefault +public class VolumeChannel extends MycroftChannel { + + private PercentType lastVolume = new PercentType(50); + private PercentType lastNonZeroVolume = new PercentType(50); + + public VolumeChannel(MycroftHandler handler) { + super(handler, MycroftBindingConstants.VOLUME_CHANNEL); + } + + @Override + public List getMessageToListenTo() { + return Arrays.asList(MessageType.mycroft_volume_get_response, MessageType.mycroft_volume_set, + MessageType.mycroft_volume_mute, MessageType.mycroft_volume_unmute, MessageType.mycroft_volume_increase, + MessageType.mycroft_volume_decrease); + } + + @Override + public void messageReceived(BaseMessage message) { + + if (message.type == MessageType.mycroft_volume_get_response) { + float volumeGet = ((MessageVolumeGetResponse) message).data.percent; + updateAndSaveMyState(normalizeVolume(volumeGet)); + } else if (message.type == MessageType.mycroft_volume_set) { + float volumeSet = ((MessageVolumeSet) message).data.percent; + updateAndSaveMyState(normalizeVolume(volumeSet)); + } else if (message.type == MessageType.mycroft_volume_mute) { + updateAndSaveMyState(new PercentType(0)); + } else if (message.type == MessageType.mycroft_volume_unmute) { + updateAndSaveMyState(lastNonZeroVolume); + } else if (message.type == MessageType.mycroft_volume_increase) { + updateAndSaveMyState(normalizeVolume(lastVolume.intValue() + 10)); + } else if (message.type == MessageType.mycroft_volume_decrease) { + updateAndSaveMyState(normalizeVolume(lastVolume.intValue() - 10)); + } + } + + protected final void updateAndSaveMyState(State state) { + if (state instanceof PercentType) { + this.lastVolume = ((PercentType) state); + if (((PercentType) state).intValue() > 0) { + this.lastNonZeroVolume = ((PercentType) state); + } + } + super.updateMyState(state); + } + + /** + * Volume between 0 and 100 + * + * @param volume + * @return + */ + private PercentType normalizeVolume(int volume) { + if (volume >= 100) { + return PercentType.HUNDRED; + } else if (volume <= 0) { + return PercentType.ZERO; + } else { + return new PercentType(volume); + } + } + + /** + * Volume between 0 and 1 + * + * @param volume + * @return + */ + private PercentType normalizeVolume(float volume) { + if (volume >= 1) { + return PercentType.HUNDRED; + } else if (volume <= 0) { + return PercentType.ZERO; + } else { + return new PercentType(Math.round(volume * 100)); + } + } + + public float toMycroftVolume(PercentType percentType) { + return Float.valueOf(percentType.intValue() / 100f); + } + + public PercentType computeNewVolume(int valueAdded) { + return new PercentType(lastVolume.intValue() + valueAdded); + } + + @Override + public void handleCommand(Command command) { + if (command instanceof OnOffType) { + if (command == OnOffType.ON) { + MessageVolumeSet messageVolumeSet = new MessageVolumeSet(); + messageVolumeSet.data.percent = toMycroftVolume(lastNonZeroVolume); + if (handler.sendMessage(messageVolumeSet)) { + updateAndSaveMyState(lastNonZeroVolume); + } + } + if (command == OnOffType.OFF) { + MessageVolumeSet messageVolumeSet = new MessageVolumeSet(); + messageVolumeSet.data.percent = 0; + if (handler.sendMessage(messageVolumeSet)) { + updateAndSaveMyState(PercentType.ZERO); + } + } + } else if (command instanceof IncreaseDecreaseType) { + if (command == IncreaseDecreaseType.INCREASE) { + if (handler.sendMessage(new MessageVolumeIncrease())) { + updateAndSaveMyState(computeNewVolume(10)); + } + } + if (command == IncreaseDecreaseType.DECREASE) { + handler.sendMessage(new MessageVolumeDecrease()); + updateAndSaveMyState(computeNewVolume(-10)); + } + } else if (command instanceof PercentType) { + MessageVolumeSet messageVolumeSet = new MessageVolumeSet(); + messageVolumeSet.data.percent = toMycroftVolume((PercentType) command); + handler.sendMessage(messageVolumeSet); + updateAndSaveMyState((PercentType) command); + } else if (command instanceof RefreshType) { + handler.sendMessage(new MessageVolumeGet()); + } + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml new file mode 100644 index 0000000000000..1479265170236 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml @@ -0,0 +1,13 @@ + + + + Mycroft Binding + Connect to the Mycroft message bus in order to receive information from, and send command to Mycroft. + Typical usage includes triggering Mycroft to listen (as if a wake word was detected), sending text for Mycroft to + speak, + reacting on some specific intent, command skills by faking a spoken utterance, etc. + Gwendal ROULLEAU + + diff --git a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml new file mode 100644 index 0000000000000..cf5b4b2db4b54 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml @@ -0,0 +1,92 @@ + + + + + + + A Mycroft instance + + + + + + + + + + + + + + + + This is the host to connect to (ip or hostname) + + + + This is the port to connect to. + 8181 + + + + + + + Switch + + Switch to ON when Mycroft is listening. Can simulate a wake work detection to trigger the STT. + + + + String + + The last sentence Mycroft speaks, or ask Mycroft to say something. + + + + String + + The last utterance Mycroft receive, or ask Mycroft something. + + + + String + + The last full message seen on the Mycroft Bus. + + + + The full message channel will be updated on these message types only (comma separated value) + message.type.1,message.type.2 + + + + + + Player + + The music player Mycroft is currently controlling. + + + + Dimmer + + The volume of the Mycroft speaker + + + + Switch + + Mute the Mycroft speaker + + + + Switch + + Duck the volume of the Mycroft speaker + + + diff --git a/bundles/org.openhab.binding.mycroft/src/test/java/org/openhab/binding/mycroft/internal/api/MycroftConnectionTest.java b/bundles/org.openhab.binding.mycroft/src/test/java/org/openhab/binding/mycroft/internal/api/MycroftConnectionTest.java new file mode 100644 index 0000000000000..b1bca2f524d7c --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/test/java/org/openhab/binding/mycroft/internal/api/MycroftConnectionTest.java @@ -0,0 +1,112 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.mycroft.internal.api; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.InetSocketAddress; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jetty.websocket.api.Session; +import org.eclipse.jetty.websocket.client.WebSocketClient; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; +import org.mockito.ArgumentMatchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; +import org.openhab.binding.mycroft.internal.api.dto.BaseMessage; +import org.openhab.binding.mycroft.internal.api.dto.MessageSpeak; + +/** + * This class provides tests for mycroft binding + * + * @author Gwendal Roulleau - Initial contribution + */ +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.WARN) +@NonNullByDefault +public class MycroftConnectionTest { + + private @Mock @NonNullByDefault({}) MycroftConnectionListener mycroftConnectionListener; + private @Mock @NonNullByDefault({}) Session sessionMock; + + @Test + public void testConnectionOK() throws IOException { + + MycroftConnection mycroftConnection = new MycroftConnection(mycroftConnectionListener, new WebSocketClient()); + Mockito.when(sessionMock.getRemoteAddress()).thenReturn(new InetSocketAddress(1234)); + mycroftConnection.onConnect(sessionMock); + + Mockito.verify(mycroftConnectionListener, Mockito.times(1)).connectionEstablished(); + } + + @Test + public void testAnyListener() throws UnsupportedEncodingException, IOException { + MycroftConnection mycroftConnection = new MycroftConnection(mycroftConnectionListener, new WebSocketClient()); + + Mockito.when(sessionMock.getRemoteAddress()).thenReturn(new InetSocketAddress(1234)); + mycroftConnection.onConnect(sessionMock); + + @SuppressWarnings("unchecked") + MycroftMessageListener mockListener = Mockito.mock(MycroftMessageListener.class); + ArgumentCaptor argCaptorMessage = ArgumentCaptor.forClass(BaseMessage.class); + + // given we register any listener + mycroftConnection.registerListener(MessageType.any, mockListener); + + // when we send speak message + @SuppressWarnings("null") + String speakMessageJson = new String( + MycroftConnectionTest.class.getResourceAsStream("speak.json").readAllBytes(), "UTF-8"); + mycroftConnection.onMessage(sessionMock, speakMessageJson); + + // then message is correctly received by listener + Mockito.verify(mockListener, Mockito.times(1)).baseMessageReceived(ArgumentMatchers.any()); + Mockito.verify(mockListener).baseMessageReceived(argCaptorMessage.capture()); + + assertEquals(argCaptorMessage.getValue().message, speakMessageJson); + } + + @Test + public void testSpeakListener() throws IOException { + + MycroftConnection mycroftConnection = new MycroftConnection(mycroftConnectionListener, new WebSocketClient()); + + Mockito.when(sessionMock.getRemoteAddress()).thenReturn(new InetSocketAddress(1234)); + mycroftConnection.onConnect(sessionMock); + + @SuppressWarnings("unchecked") + MycroftMessageListener mockListener = Mockito.mock(MycroftMessageListener.class); + ArgumentCaptor argCaptorMessage = ArgumentCaptor.forClass(MessageSpeak.class); + + // given we register speak listener + mycroftConnection.registerListener(MessageType.speak, mockListener); + + // when we send speak message + @SuppressWarnings("null") + String speakMessageJson = new String( + MycroftConnectionTest.class.getResourceAsStream("speak.json").readAllBytes(), "UTF-8"); + mycroftConnection.onMessage(sessionMock, speakMessageJson); + + // then message is correctly received by listener + Mockito.verify(mockListener).baseMessageReceived(argCaptorMessage.capture()); + + assertEquals(argCaptorMessage.getValue().data.utterance, "coucou"); + } +} diff --git a/bundles/org.openhab.binding.mycroft/src/test/resources/org/openhab/binding/mycroft/internal/api/speak.json b/bundles/org.openhab.binding.mycroft/src/test/resources/org/openhab/binding/mycroft/internal/api/speak.json new file mode 100644 index 0000000000000..dcb8697be4d86 --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/test/resources/org/openhab/binding/mycroft/internal/api/speak.json @@ -0,0 +1 @@ +{"type": "speak", "data": {"utterance": "coucou", "expect_response": false, "meta": {"skill": "SpeakSkill"}, "is_error": false}, "context": {"client_name": "mycroft_cli", "source": ["skills"], "destination": "debug_cli"}} \ No newline at end of file diff --git a/bundles/org.openhab.binding.playstation/src/main/resources/OH-INF/i18n/playstation.properties b/bundles/org.openhab.binding.playstation/src/main/resources/OH-INF/i18n/playstation.properties old mode 100644 new mode 100755 diff --git a/bundles/pom.xml b/bundles/pom.xml index 62cc68f539505..27c9d92cc68bb 100644 --- a/bundles/pom.xml +++ b/bundles/pom.xml @@ -228,6 +228,7 @@ org.openhab.binding.mqtt.generic org.openhab.binding.mqtt.homeassistant org.openhab.binding.mqtt.homie + org.openhab.binding.mycroft org.openhab.binding.myq org.openhab.binding.mystrom org.openhab.binding.nanoleaf From b67b7d0b3843b38e220fcf1b0b035dafed17a85a Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Mon, 4 Oct 2021 22:03:21 +0200 Subject: [PATCH 02/39] Adding some actions Signed-off-by: Gwendal ROULLEAU --- bundles/org.openhab.binding.mycroft/README.md | 51 +++++++++++ .../mycroft/internal/MycroftActions.java | 86 +++++++++++++++++++ .../mycroft/internal/MycroftHandler.java | 8 ++ 3 files changed, 145 insertions(+) create mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftActions.java diff --git a/bundles/org.openhab.binding.mycroft/README.md b/bundles/org.openhab.binding.mycroft/README.md index 2c3ce2312aa59..dd719debc934e 100644 --- a/bundles/org.openhab.binding.mycroft/README.md +++ b/bundles/org.openhab.binding.mycroft/README.md @@ -108,3 +108,54 @@ sitemap demo label="myMycroft" Text item=myMycroft_fullmessage } } +``` + +## Rule Actions + +This binding includes a number of rule actions, which allow triggering Mycroft from within rules. + + +``` +(Rule DSL) +val mycroftAction = getActions("mycroft","mycroft:mycroft:") +``` + +``` +(javascript JSR) +var mycroftAction = actions.get("mycroft", "mycroft:mycroft:"); +``` + + +Where uid is the Thing UID of the Mycroft thing. + +Once this action instance is retrieved, you can invoke the `speak' method on it: + +``` +mycroftAction.speak("Hello world!") +``` + + +The following actions are supported. + + +| Action | Description | +|----------------------------|--------------| +| speak(String message) | Mycroft will say this. | +| listen() | Trigger Mycroft as if the wake word was detected | +| utterance(String utterance) | Ask Mycroft something| + +## Full Example + +### Ask Mycroft to say something + +mycroft.rules + +```java +rule "Say Hello" +when + Item Presence_Isaac changed +then + val mycroftAction = getActions("mycroft","mycroft:mycroft:2b155b22") + mycroftAction.speak("Hello Isaac") +end +``` diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftActions.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftActions.java new file mode 100644 index 0000000000000..6814f4ac81b2e --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftActions.java @@ -0,0 +1,86 @@ +package org.openhab.binding.mycroft.internal; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.openhab.binding.mycroft.internal.channels.MycroftChannel; +import org.openhab.core.automation.annotation.ActionInput; +import org.openhab.core.automation.annotation.RuleAction; +import org.openhab.core.library.types.OnOffType; +import org.openhab.core.library.types.StringType; +import org.openhab.core.thing.Channel; +import org.openhab.core.thing.binding.ThingActions; +import org.openhab.core.thing.binding.ThingActionsScope; +import org.openhab.core.thing.binding.ThingHandler; + +@ThingActionsScope(name = "mycroft") // Your bindings id is usually the scope +@NonNullByDefault +public class MycroftActions implements ThingActions { + + private @Nullable MycroftHandler handler; + + @Override + public void setThingHandler(@Nullable ThingHandler handler) { + this.handler = (MycroftHandler) handler; + } + + @Override + public @Nullable ThingHandler getThingHandler() { + return handler; + } + + @RuleAction(label = "Speak", description = "Ask Mycroft to say something") + public void speak( + @ActionInput(name = "speak", label = "speak", description = "What to say") @Nullable String speak) { + getChannel(MycroftBindingConstants.SPEAK_CHANNEL).handleCommand(new StringType(speak)); + } + + private MycroftChannel getChannel(String channelName) { + MycroftHandler handlerFinal = handler; + if (handlerFinal != null) { + Channel channel = handlerFinal.getThing().getChannel(channelName); + if (channel != null) { + MycroftChannel mycroftChannel = handlerFinal.mycroftChannels.get(channel.getUID()); + if (mycroftChannel != null) { + return mycroftChannel; + } + } + } + throw new IllegalArgumentException("channelName is not a valid mycroft channel"); + } + + public static void speak(@Nullable ThingActions actions, @Nullable String speak) { + if (actions instanceof MycroftActions) { + ((MycroftActions) actions).speak(speak); + } else { + throw new IllegalArgumentException("Instance is not an MycroftActions class."); + } + } + + @RuleAction(label = "Listen", description = "Simulate a wake word detection") + public void listen() { + getChannel(MycroftBindingConstants.LISTEN_CHANNEL).handleCommand(OnOffType.ON); + } + + public static void listen(@Nullable ThingActions actions) { + if (actions instanceof MycroftActions) { + ((MycroftActions) actions).listen(); + } else { + throw new IllegalArgumentException("Instance is not an MycroftActions class."); + } + } + + @RuleAction(label = "Utterance", description = "Ask Mycroft something") + public void utterance( + @ActionInput(name = "utterance", label = "utterance", description = "What to ask") @Nullable String utterance) { + getChannel(MycroftBindingConstants.UTTERANCE_CHANNEL).handleCommand(new StringType(utterance)); + } + + public static void utterance(@Nullable ThingActions actions, @Nullable String utterance) { + if (actions instanceof MycroftActions) { + ((MycroftActions) actions).utterance(utterance); + } else { + throw new IllegalArgumentException("Instance is not an MycroftActions class."); + } + } + +} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java index bf1e9f991f6e7..44b6b83dd2fef 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java @@ -13,6 +13,8 @@ package org.openhab.binding.mycroft.internal; import java.io.IOException; +import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -45,6 +47,7 @@ import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatusDetail; import org.openhab.core.thing.binding.BaseThingHandler; +import org.openhab.core.thing.binding.ThingHandlerService; import org.openhab.core.types.Command; import org.openhab.core.types.State; import org.slf4j.Logger; @@ -246,4 +249,9 @@ public boolean sendMessage(String message) { return false; } } + + @Override + public Collection> getServices() { + return Collections.singleton(MycroftActions.class); + } } From 7a784bc6fcfa397b3b0a13e815345aea187c470d Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Sat, 13 Nov 2021 10:44:10 +0100 Subject: [PATCH 03/39] Some corrections after review. Signed-off-by: Gwendal ROULLEAU --- bundles/org.openhab.binding.mycroft/README.md | 12 +++---- .../mycroft/internal/MycroftActions.java | 32 ++++++++++--------- .../internal/api/MessageTypeConverter.java | 2 +- .../internal/channels/VolumeChannel.java | 2 ++ .../main/resources/OH-INF/binding/binding.xml | 3 +- .../resources/OH-INF/thing/thing-types.xml | 14 ++++---- 6 files changed, 34 insertions(+), 31 deletions(-) diff --git a/bundles/org.openhab.binding.mycroft/README.md b/bundles/org.openhab.binding.mycroft/README.md index dd719debc934e..334eac7c9adbd 100644 --- a/bundles/org.openhab.binding.mycroft/README.md +++ b/bundles/org.openhab.binding.mycroft/README.md @@ -1,12 +1,12 @@ # Mycroft Binding -This binding will connect to Mycroft A.I. in order to control it or react to event by listening on the message bus. +This binding will connect to Mycroft A.I. in order to control it or react to events by listening on the message bus. Possibilies include : - Press a button in OpenHAB to wake Mycroft without using a wake word. - Simulate a voice command to launch a skill, as if you just spoke it -- Send some text that Mycroft will say (Using its Text To Speach service) +- Send some text that Mycroft will say (Using its Text To Speech service) - Control the music player - Control the sound volume of Mycroft - React to all the aforementioned events ... @@ -46,10 +46,9 @@ The Mycroft thing supports the following channels : | channel type id | Item type | description | |------------------------------|-----------|------------------------------------------------------------------------------------------------| | listen | Switch | Switch to ON when Mycroft is listening. Can simulate a wake word detection to trigger the STT | -| speak | String | The last sentence Mycroft speaks, or ask Mycroft to say something | -| utterance | String | The last utterance Mycroft receive, or ask Mycroft something | +| speak | String | The last sentence Mycroft speaks | +| utterance | String | The last utterance Mycroft receive | | player | Player | The music player Mycroft is currently controlling | -| volume | Dimmer | The volume of the Mycroft speaker. NOT FUNCTIONNAL. [SEE THIS POST TO SEE EVOLUTION](https://community.mycroft.ai/t/openhab-plugin-development-audio-volume-message-types-missing/10576) | | volume_mute | Switch | Mute the Mycroft speaker | | volume_duck | Switch | Duck the volume of the Mycroft speaker | | full_message | String | The last message (full json) seen on the Mycroft Bus. Filtered by the messageTypes properties | @@ -94,7 +93,7 @@ String myMycroft_fullmessage "Full JSON message" { channel="my A `demo.sitemap` file : -```perl +``` sitemap demo label="myMycroft" { Frame label="myMycroft" { @@ -141,7 +140,6 @@ The following actions are supported. | Action | Description | |----------------------------|--------------| | speak(String message) | Mycroft will say this. | -| listen() | Trigger Mycroft as if the wake word was detected | | utterance(String utterance) | Ask Mycroft something| ## Full Example diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftActions.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftActions.java index 6814f4ac81b2e..ca50d9c7c336c 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftActions.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftActions.java @@ -1,3 +1,15 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ package org.openhab.binding.mycroft.internal; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -5,13 +17,17 @@ import org.openhab.binding.mycroft.internal.channels.MycroftChannel; import org.openhab.core.automation.annotation.ActionInput; import org.openhab.core.automation.annotation.RuleAction; -import org.openhab.core.library.types.OnOffType; import org.openhab.core.library.types.StringType; import org.openhab.core.thing.Channel; import org.openhab.core.thing.binding.ThingActions; import org.openhab.core.thing.binding.ThingActionsScope; import org.openhab.core.thing.binding.ThingHandler; +/** + * This class defines Actions. + * + * @author Gwendal ROULLEAU - Initial contribution + */ @ThingActionsScope(name = "mycroft") // Your bindings id is usually the scope @NonNullByDefault public class MycroftActions implements ThingActions { @@ -56,19 +72,6 @@ public static void speak(@Nullable ThingActions actions, @Nullable String speak) } } - @RuleAction(label = "Listen", description = "Simulate a wake word detection") - public void listen() { - getChannel(MycroftBindingConstants.LISTEN_CHANNEL).handleCommand(OnOffType.ON); - } - - public static void listen(@Nullable ThingActions actions) { - if (actions instanceof MycroftActions) { - ((MycroftActions) actions).listen(); - } else { - throw new IllegalArgumentException("Instance is not an MycroftActions class."); - } - } - @RuleAction(label = "Utterance", description = "Ask Mycroft something") public void utterance( @ActionInput(name = "utterance", label = "utterance", description = "What to ask") @Nullable String utterance) { @@ -82,5 +85,4 @@ public static void utterance(@Nullable ThingActions actions, @Nullable String ut throw new IllegalArgumentException("Instance is not an MycroftActions class."); } } - } diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageTypeConverter.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageTypeConverter.java index 11a8800bb3ed4..3efa6688527bc 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageTypeConverter.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageTypeConverter.java @@ -26,7 +26,7 @@ import com.google.gson.JsonSerializer; /** - * Custom deserializer for {@link LightType} + * Custom deserializer * * @author Gwendal Roulleau - Initial contribution */ diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java index 591d07b7b66dd..9ee45dc5acfc8 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java @@ -34,6 +34,8 @@ /** * The channel responsible for handling the volume of the Mycroft speaker + * NOT FUNCTIONAL + * (see https://community.mycroft.ai/t/openhab-plugin-development-audio-volume-message-types-missing/10576) * * @author Gwendal ROULLEAU - Initial contribution */ diff --git a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml index 1479265170236..9ce70c80aa910 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml +++ b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml @@ -6,8 +6,7 @@ Mycroft Binding Connect to the Mycroft message bus in order to receive information from, and send command to Mycroft. Typical usage includes triggering Mycroft to listen (as if a wake word was detected), sending text for Mycroft to - speak, - reacting on some specific intent, command skills by faking a spoken utterance, etc. + speak, reacting on some specific intent, command skills by faking a spoken utterance, etc. Gwendal ROULLEAU diff --git a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml index cf5b4b2db4b54..0fcc96a25c2de 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml @@ -14,7 +14,7 @@ - + @@ -43,16 +43,18 @@ String - The last sentence Mycroft speaks, or ask Mycroft to say something. + The last sentence Mycroft speaks. + String - The last utterance Mycroft receive, or ask Mycroft something. + The last utterance Mycroft receive. + - + String The last full message seen on the Mycroft Bus. @@ -71,11 +73,11 @@ The music player Mycroft is currently controlling. - + Switch From a59a7c00f0296a70c7da8eb47bff8378812eb41b Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Mon, 22 Nov 2021 15:57:32 +0100 Subject: [PATCH 04/39] Remove volume channel information Signed-off-by: Gwendal Roulleau --- bundles/org.openhab.binding.mycroft/README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.mycroft/README.md b/bundles/org.openhab.binding.mycroft/README.md index 334eac7c9adbd..4fa27b806a1d6 100644 --- a/bundles/org.openhab.binding.mycroft/README.md +++ b/bundles/org.openhab.binding.mycroft/README.md @@ -4,11 +4,11 @@ This binding will connect to Mycroft A.I. in order to control it or react to eve Possibilies include : -- Press a button in OpenHAB to wake Mycroft without using a wake word. +- Press a button in openHAB to wake Mycroft without using a wake word. - Simulate a voice command to launch a skill, as if you just spoke it - Send some text that Mycroft will say (Using its Text To Speech service) - Control the music player -- Control the sound volume of Mycroft +- Mute or duck the sound volume of Mycroft - React to all the aforementioned events ... - ... And send/receive all other kind of messages on the message bus @@ -81,7 +81,6 @@ The `mycroft.item` file : ```java Switch myMycroft_mute "Mute" { channel="mycroft:mycroft:myMycroft:volume_mute" } Switch myMycroft_duck "Duck" { channel="mycroft:mycroft:myMycroft:volume_duck" } -Dimmer myMycroft_volume "Volume [%d]" { channel="mycroft:mycroft:myMycroft:volume" } Player myMycroft_player "Control" { channel="mycroft:mycroft:myMycroft:player" } Switch myMycroft_listen "Wake and listen" { channel="mycroft:mycroft:myMycroft:listen" } String myMycroft_speak "Speak STT" { channel="mycroft:mycroft:myMycroft:speak" } @@ -99,7 +98,6 @@ sitemap demo label="myMycroft" Frame label="myMycroft" { Switch item=myMycroft_mute Switch item=myMycroft_duck - Slider item=myMycroft_volume Default item=myMycroft_player Switch item=myMycroft_listen Text item=myMycroft_speak From 223601b37e415db097905a7a28ce051afcfafc96 Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Mon, 22 Nov 2021 16:23:04 +0100 Subject: [PATCH 05/39] Removing Actions Signed-off-by: Gwendal Roulleau --- bundles/org.openhab.binding.mycroft/README.md | 36 +------- .../mycroft/internal/MycroftActions.java | 88 ------------------- .../mycroft/internal/MycroftHandler.java | 8 -- 3 files changed, 1 insertion(+), 131 deletions(-) delete mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftActions.java diff --git a/bundles/org.openhab.binding.mycroft/README.md b/bundles/org.openhab.binding.mycroft/README.md index 4fa27b806a1d6..bf5d00c20f37c 100644 --- a/bundles/org.openhab.binding.mycroft/README.md +++ b/bundles/org.openhab.binding.mycroft/README.md @@ -107,39 +107,6 @@ sitemap demo label="myMycroft" } ``` -## Rule Actions - -This binding includes a number of rule actions, which allow triggering Mycroft from within rules. - - -``` -(Rule DSL) -val mycroftAction = getActions("mycroft","mycroft:mycroft:") -``` - -``` -(javascript JSR) -var mycroftAction = actions.get("mycroft", "mycroft:mycroft:"); -``` - - -Where uid is the Thing UID of the Mycroft thing. - -Once this action instance is retrieved, you can invoke the `speak' method on it: - -``` -mycroftAction.speak("Hello world!") -``` - - -The following actions are supported. - - -| Action | Description | -|----------------------------|--------------| -| speak(String message) | Mycroft will say this. | -| utterance(String utterance) | Ask Mycroft something| - ## Full Example ### Ask Mycroft to say something @@ -151,7 +118,6 @@ rule "Say Hello" when Item Presence_Isaac changed then - val mycroftAction = getActions("mycroft","mycroft:mycroft:2b155b22") - mycroftAction.speak("Hello Isaac") + myMycroft_speak.sendCommand("Hello Isaac") end ``` diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftActions.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftActions.java deleted file mode 100644 index ca50d9c7c336c..0000000000000 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftActions.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * Copyright (c) 2010-2021 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.mycroft.internal; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; -import org.openhab.binding.mycroft.internal.channels.MycroftChannel; -import org.openhab.core.automation.annotation.ActionInput; -import org.openhab.core.automation.annotation.RuleAction; -import org.openhab.core.library.types.StringType; -import org.openhab.core.thing.Channel; -import org.openhab.core.thing.binding.ThingActions; -import org.openhab.core.thing.binding.ThingActionsScope; -import org.openhab.core.thing.binding.ThingHandler; - -/** - * This class defines Actions. - * - * @author Gwendal ROULLEAU - Initial contribution - */ -@ThingActionsScope(name = "mycroft") // Your bindings id is usually the scope -@NonNullByDefault -public class MycroftActions implements ThingActions { - - private @Nullable MycroftHandler handler; - - @Override - public void setThingHandler(@Nullable ThingHandler handler) { - this.handler = (MycroftHandler) handler; - } - - @Override - public @Nullable ThingHandler getThingHandler() { - return handler; - } - - @RuleAction(label = "Speak", description = "Ask Mycroft to say something") - public void speak( - @ActionInput(name = "speak", label = "speak", description = "What to say") @Nullable String speak) { - getChannel(MycroftBindingConstants.SPEAK_CHANNEL).handleCommand(new StringType(speak)); - } - - private MycroftChannel getChannel(String channelName) { - MycroftHandler handlerFinal = handler; - if (handlerFinal != null) { - Channel channel = handlerFinal.getThing().getChannel(channelName); - if (channel != null) { - MycroftChannel mycroftChannel = handlerFinal.mycroftChannels.get(channel.getUID()); - if (mycroftChannel != null) { - return mycroftChannel; - } - } - } - throw new IllegalArgumentException("channelName is not a valid mycroft channel"); - } - - public static void speak(@Nullable ThingActions actions, @Nullable String speak) { - if (actions instanceof MycroftActions) { - ((MycroftActions) actions).speak(speak); - } else { - throw new IllegalArgumentException("Instance is not an MycroftActions class."); - } - } - - @RuleAction(label = "Utterance", description = "Ask Mycroft something") - public void utterance( - @ActionInput(name = "utterance", label = "utterance", description = "What to ask") @Nullable String utterance) { - getChannel(MycroftBindingConstants.UTTERANCE_CHANNEL).handleCommand(new StringType(utterance)); - } - - public static void utterance(@Nullable ThingActions actions, @Nullable String utterance) { - if (actions instanceof MycroftActions) { - ((MycroftActions) actions).utterance(utterance); - } else { - throw new IllegalArgumentException("Instance is not an MycroftActions class."); - } - } -} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java index 44b6b83dd2fef..bf1e9f991f6e7 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java @@ -13,8 +13,6 @@ package org.openhab.binding.mycroft.internal; import java.io.IOException; -import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -47,7 +45,6 @@ import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatusDetail; import org.openhab.core.thing.binding.BaseThingHandler; -import org.openhab.core.thing.binding.ThingHandlerService; import org.openhab.core.types.Command; import org.openhab.core.types.State; import org.slf4j.Logger; @@ -249,9 +246,4 @@ public boolean sendMessage(String message) { return false; } } - - @Override - public Collection> getServices() { - return Collections.singleton(MycroftActions.class); - } } From 59e086d74a0321d01724033aa8e2978e1205e1fc Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Mon, 22 Nov 2021 16:40:21 +0100 Subject: [PATCH 06/39] Fix misuse of initialization boolean to prevent reconnection issue Signed-off-by: Gwendal Roulleau --- .../org/openhab/binding/mycroft/internal/MycroftHandler.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java index bf1e9f991f6e7..8443c8bdb0ea0 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java @@ -138,6 +138,8 @@ public void handleCommand(ChannelUID channelUID, Command command) { @Override public void initialize() { + thingDisposing = false; + updateStatus(ThingStatus.UNKNOWN); logger.debug("Start initializing mycroft {}", thing.getUID()); From f798010e099c9c64363893f79902feaeb5c8141f Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Wed, 24 Nov 2021 08:24:23 +0100 Subject: [PATCH 07/39] Length restrictions on websocket name Signed-off-by: Gwendal Roulleau --- .../org/openhab/binding/mycroft/internal/MycroftHandler.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java index 8443c8bdb0ea0..9bf9459544d8b 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java @@ -76,8 +76,9 @@ public MycroftHandler(Thing thing, WebSocketFactory webSocketFactory) { super(thing); String websocketID = thing.getUID().getAsString().replace(':', '-'); if (websocketID.length() < 4) { - websocketID = "openHAB-mycroft-" + websocketID; - } else if (websocketID.length() > 20) { + websocketID = "mycroft-" + websocketID; + } + if (websocketID.length() > 20) { websocketID = websocketID.substring(websocketID.length() - 20); } this.connection = new MycroftConnection(this, webSocketFactory.createWebSocketClient(websocketID)); From 1c31133e17b07f1a1f68f24b99285b9ff4119ed2 Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Sat, 27 Nov 2021 10:28:38 +0100 Subject: [PATCH 08/39] Rewrite the scheduled reconnection Signed-off-by: Gwendal Roulleau --- .../mycroft/internal/MycroftHandler.java | 44 ++++++------------- 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java index 9bf9459544d8b..d76d70a393a29 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java @@ -18,7 +18,6 @@ import java.util.Map.Entry; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -65,11 +64,10 @@ public class MycroftHandler extends BaseThingHandler implements MycroftConnectio private @Nullable ScheduledFuture scheduledFuture; private MycroftConfiguration config = new MycroftConfiguration(); private boolean thingDisposing = false; - private AtomicBoolean isStartingWebSocket = new AtomicBoolean(false); protected Map> mycroftChannels = new HashMap<>(); /** The reconnect frequency in case of error */ - private static final int POLL_FREQUENCY_SEC = 10; + private static final int POLL_FREQUENCY_SEC = 30; private int sometimesSendVolumeRequest = 0; public MycroftHandler(Thing thing, WebSocketFactory webSocketFactory) { @@ -103,25 +101,17 @@ private void startWebsocket() { if (thingDisposing) { return; } - if (!isStartingWebSocket.compareAndExchange(false, true)) { - try { - if (connection.isConnected()) { - // sometimes test the connection by sending a real message - // AND refreshing volume in the same step - if (sometimesSendVolumeRequest >= 3) { // arbitrary one on three times - sometimesSendVolumeRequest = 0; - sendMessage(new MessageVolumeGet()); - } else { - sometimesSendVolumeRequest++; - } - } else { - connection.start(config.host, config.port); - } - } finally { - stopTimer(); - scheduledFuture = scheduler.schedule(this::startWebsocket, POLL_FREQUENCY_SEC, TimeUnit.SECONDS); - isStartingWebSocket.set(false); + if (connection.isConnected()) { + // sometimes test the connection by sending a real message + // AND refreshing volume in the same step + if (sometimesSendVolumeRequest >= 3) { // arbitrary one on three times + sometimesSendVolumeRequest = 0; + sendMessage(new MessageVolumeGet()); + } else { + sometimesSendVolumeRequest++; } + } else { + connection.start(config.host, config.port); } } @@ -143,13 +133,12 @@ public void initialize() { updateStatus(ThingStatus.UNKNOWN); - logger.debug("Start initializing mycroft {}", thing.getUID()); + logger.debug("Start initializing Mycroft {}", thing.getUID()); config = getConfigAs(MycroftConfiguration.class); - scheduler.execute(() -> { - startWebsocket(); - }); + scheduledFuture = scheduler.scheduleWithFixedDelay(this::startWebsocket, 0, POLL_FREQUENCY_SEC, + TimeUnit.SECONDS); registerChannel(new ListenChannel(this)); registerChannel(new VolumeChannel(this)); @@ -205,7 +194,6 @@ public void unregisterMessageListener(MessageType messageType, MycroftMessageLis @Override public void connectionEstablished() { - stopTimer(); logger.debug("Mycroft thing {} is online", thing.getUID()); updateStatus(ThingStatus.ONLINE); } @@ -213,10 +201,6 @@ public void connectionEstablished() { @Override public void connectionLost(String reason) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, reason); - - stopTimer(); - // Wait for POLL_FREQUENCY_SEC after a connection was closed before trying again - scheduledFuture = scheduler.schedule(this::startWebsocket, POLL_FREQUENCY_SEC, TimeUnit.SECONDS); } @Override From 423ccdaaa2547db70d8b62ba07dba8a5c1b4a840 Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Sat, 27 Nov 2021 08:55:22 +0100 Subject: [PATCH 09/39] Remove two empty lines Signed-off-by: Gwendal Roulleau --- .../org/openhab/binding/mycroft/internal/MycroftHandler.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java index d76d70a393a29..c0dc27f5557fe 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java @@ -117,7 +117,6 @@ private void startWebsocket() { @Override public void handleCommand(ChannelUID channelUID, Command command) { - ChannelCommandHandler channelCommand = mycroftChannels.get(channelUID); if (channelCommand == null) { logger.error("Command {} for channel {} cannot be handled", command.toString(), channelUID.toString()); @@ -128,7 +127,6 @@ public void handleCommand(ChannelUID channelUID, Command command) { @Override public void initialize() { - thingDisposing = false; updateStatus(ThingStatus.UNKNOWN); From b2e10a8ae548d619c48627ac55a817de06a453b2 Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Sat, 27 Nov 2021 08:58:25 +0100 Subject: [PATCH 10/39] Rewriting a comment Signed-off-by: Gwendal Roulleau --- .../org/openhab/binding/mycroft/internal/api/MessageType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageType.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageType.java index fe4378a503aa5..eb28cd4115b04 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageType.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageType.java @@ -90,7 +90,7 @@ public enum MessageType { } /** - * get the expected message type for this message type + * get the expected message type for this message * * @return */ From efc043986e52fcc8f6cb5ab6829c01823cec5d6a Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Sat, 27 Nov 2021 09:01:10 +0100 Subject: [PATCH 11/39] Remove duplicated code in constructor Signed-off-by: Gwendal Roulleau --- .../mycroft/internal/api/MycroftConnection.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java index 8bce75a2b9800..3003cb814df01 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java @@ -76,15 +76,7 @@ public MycroftConnection(MycroftConnectionListener listener, WebSocketClient cli } public MycroftConnection(MycroftConnectionListener listener) { - this.connectionListener = listener; - this.client = new WebSocketClient(); - this.client.setMaxIdleTimeout(0); - this.client.setConnectTimeout(TIMEOUT_MILLISECONDS); - this.socketName = "Websocket$" + System.currentTimeMillis() + "-" + INSTANCE_COUNTER.incrementAndGet(); - - GsonBuilder gsonBuilder = new GsonBuilder(); - gsonBuilder.registerTypeAdapter(MessageType.class, new MessageTypeConverter()); - gson = gsonBuilder.create(); + this(listener, new WebSocketClient()); } public void start(String ip, int port) { From 968e80eea15b9aedc4ad5632a2e2885c9a81d448 Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Sat, 27 Nov 2021 09:06:58 +0100 Subject: [PATCH 12/39] Use "mycroft" in websocket name Signed-off-by: Gwendal Roulleau --- .../openhab/binding/mycroft/internal/api/MycroftConnection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java index 3003cb814df01..6d424c106a5bf 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java @@ -68,7 +68,7 @@ public MycroftConnection(MycroftConnectionListener listener, WebSocketClient cli this.client = client; this.client.setConnectTimeout(TIMEOUT_MILLISECONDS); this.client.setMaxIdleTimeout(0); - this.socketName = "Websocket$" + System.currentTimeMillis() + "-" + INSTANCE_COUNTER.incrementAndGet(); + this.socketName = "Websocket-Mycroft$" + System.currentTimeMillis() + "-" + INSTANCE_COUNTER.incrementAndGet(); GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(MessageType.class, new MessageTypeConverter()); From cfa855f831db1dcfb7d20260dfad7a6ce7131ce5 Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Sat, 27 Nov 2021 09:13:25 +0100 Subject: [PATCH 13/39] Remove empty line Signed-off-by: Gwendal Roulleau --- .../openhab/binding/mycroft/internal/api/MycroftConnection.java | 1 - 1 file changed, 1 deletion(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java index 6d424c106a5bf..254465683da0a 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java @@ -173,7 +173,6 @@ public void onMessage(Session session, String message) { logger.trace("{} received raw data: {}", socketName, message); try { - // listeners on message type : BaseMessage mycroftMessage = gson.fromJson(message, BaseMessage.class); Objects.requireNonNull(mycroftMessage); From 97dc907aa19d49dc45a5e3bd7f5f901387105b95 Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Sat, 27 Nov 2021 10:30:48 +0100 Subject: [PATCH 14/39] Log to debug Signed-off-by: Gwendal Roulleau --- .../binding/mycroft/internal/api/MycroftConnection.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java index 254465683da0a..ab2bcba042f2d 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java @@ -197,7 +197,7 @@ public void onMessage(Session session, String message) { } catch (RuntimeException e) { // we need to catch all processing exceptions, otherwise they could affect the connection - logger.warn("{} encountered an error while processing the message {}: {}", socketName, message, + logger.debug("{} encountered an error while processing the message {}: {}", socketName, message, e.getMessage()); } } @@ -231,9 +231,9 @@ public void onClose(Session session, int statusCode, String reason) { private void handleWrongSession(@Nullable Session session, String message) { if (session == null) { - logger.warn("received and discarded message for null session : {}", message); + logger.debug("received and discarded message for null session : {}", message); } else { - logger.warn("{} received and discarded message for other session {}: {}.", socketName, session.hashCode(), + logger.debug("{} received and discarded message for other session {}: {}.", socketName, session.hashCode(), message); } } From afed4e6136ba06d3467a6f0bebcfdfd265025de4 Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Sat, 27 Nov 2021 12:05:46 +0100 Subject: [PATCH 15/39] Typo Signed-off-by: Gwendal Roulleau --- .../binding/mycroft/internal/channels/AudioPlayerChannel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/AudioPlayerChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/AudioPlayerChannel.java index d69429f711d9d..14ef3d70e88e3 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/AudioPlayerChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/AudioPlayerChannel.java @@ -31,7 +31,7 @@ import org.openhab.core.types.State; /** - * This channel handle the Mycroft capability to act as a music player + * This channel handles the Mycroft capability to act as a music player * (depending on common play music skills installed) * * @author Gwendal ROULLEAU - Initial contribution From e7f91fb23bd37a518b1955f7efb41149121a391b Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Sat, 27 Nov 2021 12:10:59 +0100 Subject: [PATCH 16/39] Use of toFullString instead of toString Signed-off-by: Gwendal Roulleau --- .../mycroft/internal/channels/FullMessageChannel.java | 4 ++-- .../binding/mycroft/internal/channels/SpeakChannel.java | 4 ++-- .../binding/mycroft/internal/channels/UtteranceChannel.java | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/FullMessageChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/FullMessageChannel.java index 55ceab488f621..bbc3a95ef4ade 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/FullMessageChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/FullMessageChannel.java @@ -56,8 +56,8 @@ public void messageReceived(BaseMessage message) { @Override public void handleCommand(Command command) { if (command instanceof StringType) { - if (handler.sendMessage(command.toString())) { - updateMyState(new StringType(command.toString())); + if (handler.sendMessage(command.toFullString())) { + updateMyState(new StringType(command.toFullString())); } } } diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/SpeakChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/SpeakChannel.java index 2d4c8a9ebe770..3244e7ad282bd 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/SpeakChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/SpeakChannel.java @@ -52,8 +52,8 @@ public void messageReceived(BaseMessage message) { @Override public void handleCommand(Command command) { if (command instanceof StringType) { - if (handler.sendMessage(new MessageSpeak(command.toString()))) { - updateMyState(new StringType(command.toString())); + if (handler.sendMessage(new MessageSpeak(command.toFullString()))) { + updateMyState(new StringType(command.toFullString())); } } } diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/UtteranceChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/UtteranceChannel.java index 6682c92ea6428..2e3519c19d83e 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/UtteranceChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/UtteranceChannel.java @@ -55,9 +55,9 @@ public void messageReceived(BaseMessage message) { @Override public void handleCommand(Command command) { if (command instanceof StringType) { - MessageRecognizerLoopUtterance utteranceMessage = new MessageRecognizerLoopUtterance(command.toString()); - handler.sendMessage(utteranceMessage); - updateMyState(new StringType(command.toString())); + if (handler.sendMessage(new MessageRecognizerLoopUtterance(command.toFullString()))) { + updateMyState(new StringType(command.toFullString())); + } } } } From d3823925fe2a6ee2b0d22f6f2f2447fed4e6a357 Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Mon, 22 Nov 2021 16:46:35 +0100 Subject: [PATCH 17/39] Fix typo and comment Signed-off-by: Gwendal Roulleau --- .../src/main/resources/OH-INF/binding/binding.xml | 2 +- .../src/main/resources/OH-INF/thing/thing-types.xml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml index 9ce70c80aa910..1668cccbd2f9a 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml +++ b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="https://openhab.org/schemas/binding/v1.0.0 https://openhab.org/schemas/binding-1.0.0.xsd"> Mycroft Binding - Connect to the Mycroft message bus in order to receive information from, and send command to Mycroft. + Connect to the Mycroft message bus in order to receive information from, and send commands to Mycroft. Typical usage includes triggering Mycroft to listen (as if a wake word was detected), sending text for Mycroft to speak, reacting on some specific intent, command skills by faking a spoken utterance, etc. Gwendal ROULLEAU diff --git a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml index 0fcc96a25c2de..0ad62372044be 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml @@ -4,7 +4,6 @@ xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0" xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd"> - A Mycroft instance From 7d7a3235984c21161fa68e337eec49509f3584aa Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Sat, 27 Nov 2021 12:54:27 +0100 Subject: [PATCH 18/39] Use of a network-address context Signed-off-by: Gwendal Roulleau --- .../src/main/resources/OH-INF/thing/thing-types.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml index 0ad62372044be..5aa96c15331f4 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml @@ -23,6 +23,7 @@ This is the host to connect to (ip or hostname) + network-address From f0a740d293c5019e1a36c652e9a0f98f6aae0e81 Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Sat, 27 Nov 2021 12:55:11 +0100 Subject: [PATCH 19/39] Fix typos Signed-off-by: Gwendal Roulleau --- .../src/main/resources/OH-INF/thing/thing-types.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml index 5aa96c15331f4..81870a0bbdd79 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml @@ -43,14 +43,14 @@ String - The last sentence Mycroft speaks. + The last sentence Mycroft spoke. String - The last utterance Mycroft receive. + The last utterance Mycroft received. From 2cdfd9c9ce39534430b10c1c7903a63950c9a1cd Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Sat, 27 Nov 2021 12:55:49 +0100 Subject: [PATCH 20/39] Do not put in read-only the speak and utterance channels Signed-off-by: Gwendal Roulleau --- .../src/main/resources/OH-INF/thing/thing-types.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml index 81870a0bbdd79..3bf4b1a7121b0 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml @@ -44,14 +44,12 @@ String The last sentence Mycroft spoke. - String The last utterance Mycroft received. - From 0ba3f6f2293113177ec4412ad768d89840592f84 Mon Sep 17 00:00:00 2001 From: dalgwen Date: Mon, 20 Dec 2021 16:06:15 +0100 Subject: [PATCH 21/39] Directly apply some suggestions from code review in the README.md Signed-off-by: Gwendal Roulleau Co-authored-by: Kai Kreuzer --- bundles/org.openhab.binding.mycroft/README.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/bundles/org.openhab.binding.mycroft/README.md b/bundles/org.openhab.binding.mycroft/README.md index bf5d00c20f37c..12fa4c622906b 100644 --- a/bundles/org.openhab.binding.mycroft/README.md +++ b/bundles/org.openhab.binding.mycroft/README.md @@ -1,8 +1,8 @@ # Mycroft Binding -This binding will connect to Mycroft A.I. in order to control it or react to events by listening on the message bus. +This binding connects to Mycroft A.I. in order to control it or react to events by listening on the message bus. -Possibilies include : +Possibilies include: - Press a button in openHAB to wake Mycroft without using a wake word. - Simulate a voice command to launch a skill, as if you just spoke it @@ -10,7 +10,7 @@ Possibilies include : - Control the music player - Mute or duck the sound volume of Mycroft - React to all the aforementioned events ... -- ... And send/receive all other kind of messages on the message bus +- ... and send/receive any other kind of messages on the message bus ## Supported Things @@ -26,7 +26,7 @@ There is no discovery service, as Mycroft doesn't announce itself on the network ## Thing Configuration The configuration is simple, as you just need to give the IP/hostname of the Mycroft instance accessible on the network. -The default port is 8181, but you could change it if you want. +The default port is 8181, which can be changed. ``` Thing mycroft:mycroft:myMycroft "Mycroft A.I." @ "Living Room" [host="192.168.X.X"] @@ -40,7 +40,7 @@ Thing mycroft:mycroft:myMycroft "Mycroft A.I." @ "Living Room" [host="192.168.X. ## Channels -The Mycroft thing supports the following channels : +A Mycroft thing has the following channels: | channel type id | Item type | description | @@ -54,7 +54,7 @@ The Mycroft thing supports the following channels : | full_message | String | The last message (full json) seen on the Mycroft Bus. Filtered by the messageTypes properties | -The channel 'full_message' has the following configuration available : +The channel 'full_message' has the following configuration available: | property | type | description | mandatory | |---------------|---------------------------------|-------------------------------------------------------------------------|-----------| @@ -76,7 +76,7 @@ Thing mycroft:mycroft:myMycroft "Mycroft A.I." @ "Living Room" [host="192.168.X. ### Item Configuration -The `mycroft.item` file : +The `mycroft.item` file: ```java Switch myMycroft_mute "Mute" { channel="mycroft:mycroft:myMycroft:volume_mute" } @@ -90,7 +90,7 @@ String myMycroft_fullmessage "Full JSON message" { channel="my ### Sitemap Configuration -A `demo.sitemap` file : +A `demo.sitemap` file: ``` sitemap demo label="myMycroft" @@ -107,7 +107,6 @@ sitemap demo label="myMycroft" } ``` -## Full Example ### Ask Mycroft to say something From e39603cd447cbe9762c32948226f263a663fdd5d Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Mon, 20 Dec 2021 16:59:31 +0100 Subject: [PATCH 22/39] Apply suggestion from code review : thing type id in readme Signed-off-by: Gwendal Roulleau --- bundles/org.openhab.binding.mycroft/README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.mycroft/README.md b/bundles/org.openhab.binding.mycroft/README.md index 12fa4c622906b..73ccbcbeb4ec4 100644 --- a/bundles/org.openhab.binding.mycroft/README.md +++ b/bundles/org.openhab.binding.mycroft/README.md @@ -15,7 +15,12 @@ Possibilies include: ## Supported Things -The only thing managed by this binding is a Mycroft instance. +The only thing managed by this binding is a Mycroft instance + +| Thing Type ID | Description | +|--------------------|----------------------------------------------------------------------------| +| mycroft | A Mark I/II, a Picroft, or any other variant exposing the message bus | + ## Discovery From acf15475faa0cc97dd7393fa0ddb0c3b1e445783 Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Mon, 20 Dec 2021 17:00:31 +0100 Subject: [PATCH 23/39] Apply suggestion from code review : last name refactor Signed-off-by: Gwendal Roulleau --- .../binding/mycroft/internal/MycroftBindingConstants.java | 2 +- .../binding/mycroft/internal/MycroftConfiguration.java | 2 +- .../org/openhab/binding/mycroft/internal/MycroftHandler.java | 2 +- .../binding/mycroft/internal/MycroftHandlerFactory.java | 4 ++-- .../org/openhab/binding/mycroft/internal/api/MessageType.java | 2 +- .../binding/mycroft/internal/api/MycroftConnection.java | 2 +- .../openhab/binding/mycroft/internal/api/dto/BaseMessage.java | 2 +- .../binding/mycroft/internal/api/dto/MessageAudioNext.java | 2 +- .../binding/mycroft/internal/api/dto/MessageAudioPause.java | 2 +- .../binding/mycroft/internal/api/dto/MessageAudioPlay.java | 2 +- .../binding/mycroft/internal/api/dto/MessageAudioPrev.java | 2 +- .../binding/mycroft/internal/api/dto/MessageAudioResume.java | 2 +- .../binding/mycroft/internal/api/dto/MessageAudioStop.java | 2 +- .../mycroft/internal/api/dto/MessageAudioTrackInfo.java | 2 +- .../mycroft/internal/api/dto/MessageAudioTrackInfoReply.java | 2 +- .../binding/mycroft/internal/api/dto/MessageMicListen.java | 2 +- .../internal/api/dto/MessageRecognizerLoopRecordBegin.java | 2 +- .../internal/api/dto/MessageRecognizerLoopRecordEnd.java | 2 +- .../internal/api/dto/MessageRecognizerLoopUtterance.java | 2 +- .../binding/mycroft/internal/api/dto/MessageSpeak.java | 2 +- .../mycroft/internal/api/dto/MessageVolumeDecrease.java | 2 +- .../binding/mycroft/internal/api/dto/MessageVolumeDuck.java | 2 +- .../binding/mycroft/internal/api/dto/MessageVolumeGet.java | 2 +- .../mycroft/internal/api/dto/MessageVolumeGetResponse.java | 2 +- .../mycroft/internal/api/dto/MessageVolumeIncrease.java | 2 +- .../binding/mycroft/internal/api/dto/MessageVolumeMute.java | 2 +- .../binding/mycroft/internal/api/dto/MessageVolumeSet.java | 2 +- .../binding/mycroft/internal/api/dto/MessageVolumeUnduck.java | 2 +- .../binding/mycroft/internal/api/dto/MessageVolumeUnmute.java | 2 +- .../binding/mycroft/internal/channels/AudioPlayerChannel.java | 2 +- .../mycroft/internal/channels/ChannelCommandHandler.java | 2 +- .../binding/mycroft/internal/channels/DuckChannel.java | 2 +- .../binding/mycroft/internal/channels/FullMessageChannel.java | 2 +- .../binding/mycroft/internal/channels/ListenChannel.java | 2 +- .../binding/mycroft/internal/channels/MuteChannel.java | 2 +- .../binding/mycroft/internal/channels/MycroftChannel.java | 2 +- .../binding/mycroft/internal/channels/SpeakChannel.java | 2 +- .../binding/mycroft/internal/channels/UtteranceChannel.java | 2 +- .../binding/mycroft/internal/channels/VolumeChannel.java | 2 +- .../src/main/resources/OH-INF/binding/binding.xml | 2 +- 40 files changed, 41 insertions(+), 41 deletions(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftBindingConstants.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftBindingConstants.java index 611da2a258808..289fd297050d9 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftBindingConstants.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftBindingConstants.java @@ -19,7 +19,7 @@ * The {@link MycroftBindingConstants} class defines common constants, which are * used across the whole binding. * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ @NonNullByDefault public class MycroftBindingConstants { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftConfiguration.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftConfiguration.java index 6c22b52653522..02fa90c00265a 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftConfiguration.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftConfiguration.java @@ -17,7 +17,7 @@ /** * The {@link MycroftConfiguration} class contains fields mapping thing configuration parameters. * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ @NonNullByDefault public class MycroftConfiguration { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java index c0dc27f5557fe..0d04dfed3a35e 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java @@ -53,7 +53,7 @@ * The {@link MycroftHandler} is responsible for handling commands, which are * sent to one of the channels. * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ @NonNullByDefault public class MycroftHandler extends BaseThingHandler implements MycroftConnectionListener { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandlerFactory.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandlerFactory.java index ed2fd2ccf2125..80e907aa87f5a 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandlerFactory.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandlerFactory.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ package org.openhab.binding.mycroft.internal; @@ -32,7 +32,7 @@ * The {@link MycroftHandlerFactory} is responsible for creating things and thing * handlers. * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ @NonNullByDefault @Component(configurationPid = "binding.mycroft", service = ThingHandlerFactory.class) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageType.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageType.java index eb28cd4115b04..108687c96100e 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageType.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageType.java @@ -44,7 +44,7 @@ /** * All message type of interest, issued by Mycroft, are referenced here * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ @NonNullByDefault public enum MessageType { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java index ab2bcba042f2d..db7b2dfd3d6a8 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java @@ -43,7 +43,7 @@ /** * Establishes and keeps a websocket connection to the Mycroft bus * - * @author Gwendal ROULLEAU - Initial contribution. Inspired by the deconz binding. + * @author Gwendal Roulleau - Initial contribution. Inspired by the deconz binding. */ @WebSocket @NonNullByDefault diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/BaseMessage.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/BaseMessage.java index 649cdc96ca4d7..2eee6b29abf5e 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/BaseMessage.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/BaseMessage.java @@ -16,7 +16,7 @@ /** * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ public class BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioNext.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioNext.java index 062316c9f0c3f..389ad6d4d466d 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioNext.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioNext.java @@ -16,7 +16,7 @@ /** * - * @author Gwendal ROULLEAU - Initial Contribution + * @author Gwendal Roulleau - Initial Contribution * */ public class MessageAudioNext extends BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPause.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPause.java index 27c614944088f..03569dd44bef9 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPause.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPause.java @@ -16,7 +16,7 @@ /** * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ public class MessageAudioPause extends BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPlay.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPlay.java index b9f1e0335980a..bfcecd2f9a360 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPlay.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPlay.java @@ -16,7 +16,7 @@ /** * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution * */ public class MessageAudioPlay extends BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPrev.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPrev.java index 76d03fabdb8a3..1286f039673dc 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPrev.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPrev.java @@ -16,7 +16,7 @@ /** * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution * */ public class MessageAudioPrev extends BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioResume.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioResume.java index 9de316e87dc61..ef6d7143f3c03 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioResume.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioResume.java @@ -16,7 +16,7 @@ /** * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution * */ public class MessageAudioResume extends BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioStop.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioStop.java index 17d42dd3f48ab..0300acb9e9cbf 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioStop.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioStop.java @@ -16,7 +16,7 @@ /** * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ public class MessageAudioStop extends BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfo.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfo.java index 8415f8ad022e5..babc8bc95bc9f 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfo.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfo.java @@ -16,7 +16,7 @@ /** * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ public class MessageAudioTrackInfo extends BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfoReply.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfoReply.java index 1ea96c6891f7b..bf26698db547c 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfoReply.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfoReply.java @@ -16,7 +16,7 @@ /** * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ public class MessageAudioTrackInfoReply extends BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageMicListen.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageMicListen.java index da2267cc47849..ef6e243d7fe62 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageMicListen.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageMicListen.java @@ -16,7 +16,7 @@ /** * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ public class MessageMicListen extends BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordBegin.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordBegin.java index 28468bbcc5518..51bd5e438abb5 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordBegin.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordBegin.java @@ -16,7 +16,7 @@ /** * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ public class MessageRecognizerLoopRecordBegin extends BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordEnd.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordEnd.java index abf92e9e293b9..a13de2fce8461 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordEnd.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordEnd.java @@ -16,7 +16,7 @@ /** * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ public class MessageRecognizerLoopRecordEnd extends BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopUtterance.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopUtterance.java index 1937af97e7fab..8b2f89ac73ccf 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopUtterance.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopUtterance.java @@ -19,7 +19,7 @@ /** * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ public class MessageRecognizerLoopUtterance extends BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageSpeak.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageSpeak.java index e307e3d8c1996..36dd421185827 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageSpeak.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageSpeak.java @@ -19,7 +19,7 @@ /** * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ public class MessageSpeak extends BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDecrease.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDecrease.java index f2f4239c64f49..f465e6aab6cbe 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDecrease.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDecrease.java @@ -16,7 +16,7 @@ /** * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ public class MessageVolumeDecrease extends BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDuck.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDuck.java index cce27468e9f24..372e79b93d00a 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDuck.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDuck.java @@ -16,7 +16,7 @@ /** * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ public class MessageVolumeDuck extends BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGet.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGet.java index 8ef06cce84916..d82892c1044cb 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGet.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGet.java @@ -16,7 +16,7 @@ /** * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ public class MessageVolumeGet extends BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGetResponse.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGetResponse.java index 6792e5c68f8ec..b2d9587551b34 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGetResponse.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGetResponse.java @@ -16,7 +16,7 @@ /** * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ public class MessageVolumeGetResponse extends BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeIncrease.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeIncrease.java index 466208e283b61..f8faeda32ae6c 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeIncrease.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeIncrease.java @@ -16,7 +16,7 @@ /** * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ public class MessageVolumeIncrease extends BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeMute.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeMute.java index e28b631287ba2..c153c2115fa7c 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeMute.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeMute.java @@ -16,7 +16,7 @@ /** * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ public class MessageVolumeMute extends BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeSet.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeSet.java index 9872bf77b30f9..6974c1c6121aa 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeSet.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeSet.java @@ -16,7 +16,7 @@ /** * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ public class MessageVolumeSet extends BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnduck.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnduck.java index eb3ca059bc7f8..094505ce4b25b 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnduck.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnduck.java @@ -16,7 +16,7 @@ /** * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ public class MessageVolumeUnduck extends BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnmute.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnmute.java index 79525eba55e2d..8f309bbc0d491 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnmute.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnmute.java @@ -16,7 +16,7 @@ /** * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ public class MessageVolumeUnmute extends BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/AudioPlayerChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/AudioPlayerChannel.java index 14ef3d70e88e3..c0a2d6cac959c 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/AudioPlayerChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/AudioPlayerChannel.java @@ -34,7 +34,7 @@ * This channel handles the Mycroft capability to act as a music player * (depending on common play music skills installed) * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ @NonNullByDefault public class AudioPlayerChannel extends MycroftChannel { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ChannelCommandHandler.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ChannelCommandHandler.java index 98831fbd23a81..28555fc869ef2 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ChannelCommandHandler.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ChannelCommandHandler.java @@ -18,7 +18,7 @@ /** * Interface for channel which can handle command * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ @NonNullByDefault public interface ChannelCommandHandler { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/DuckChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/DuckChannel.java index 22e95cd24ab51..8893e2850e615 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/DuckChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/DuckChannel.java @@ -28,7 +28,7 @@ /** * The channel responsible for triggering STT recognition * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ @NonNullByDefault public class DuckChannel extends MycroftChannel { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/FullMessageChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/FullMessageChannel.java index bbc3a95ef4ade..f5e4c3dd54eba 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/FullMessageChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/FullMessageChannel.java @@ -27,7 +27,7 @@ /** * The channel responsible for sending/receiving raw message * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ @NonNullByDefault public class FullMessageChannel extends MycroftChannel { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ListenChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ListenChannel.java index ba654dd650574..23ee494f95ae2 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ListenChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ListenChannel.java @@ -27,7 +27,7 @@ /** * The channel responsible for triggering STT recognition * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ @NonNullByDefault public class ListenChannel extends MycroftChannel { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MuteChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MuteChannel.java index f99aa1150c020..55e3ee578fe73 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MuteChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MuteChannel.java @@ -28,7 +28,7 @@ /** * The channel responsible for muting the Mycroft speaker * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ @NonNullByDefault public class MuteChannel extends MycroftChannel { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MycroftChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MycroftChannel.java index b8452d535b0a6..418e70f074320 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MycroftChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MycroftChannel.java @@ -26,7 +26,7 @@ /** * A helper method for channel handling * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ @NonNullByDefault public abstract class MycroftChannel diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/SpeakChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/SpeakChannel.java index 3244e7ad282bd..08985ad5669c8 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/SpeakChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/SpeakChannel.java @@ -27,7 +27,7 @@ /** * The channel responsible for TSS * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ @NonNullByDefault public class SpeakChannel extends MycroftChannel { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/UtteranceChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/UtteranceChannel.java index 2e3519c19d83e..ed6e9290f963f 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/UtteranceChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/UtteranceChannel.java @@ -27,7 +27,7 @@ /** * This channel handle the full utterance send or received by Mycroft, before any intent recognition * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution * */ @NonNullByDefault diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java index 9ee45dc5acfc8..ad38fb5a87f89 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java @@ -37,7 +37,7 @@ * NOT FUNCTIONAL * (see https://community.mycroft.ai/t/openhab-plugin-development-audio-volume-message-types-missing/10576) * - * @author Gwendal ROULLEAU - Initial contribution + * @author Gwendal Roulleau - Initial contribution */ @NonNullByDefault public class VolumeChannel extends MycroftChannel { diff --git a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml index 1668cccbd2f9a..6b7e4a6ea1a95 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml +++ b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml @@ -7,6 +7,6 @@ Connect to the Mycroft message bus in order to receive information from, and send commands to Mycroft. Typical usage includes triggering Mycroft to listen (as if a wake word was detected), sending text for Mycroft to speak, reacting on some specific intent, command skills by faking a spoken utterance, etc. - Gwendal ROULLEAU + Gwendal Roulleau From 6ada9f141c4d4154903a4c20eff659f6ab44bb5c Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Mon, 20 Dec 2021 17:28:57 +0100 Subject: [PATCH 24/39] Apply suggestion from code review: websocket creation not in constructor Signed-off-by: Gwendal Roulleau --- .../mycroft/internal/MycroftHandler.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java index 0d04dfed3a35e..7244996813b02 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java @@ -60,7 +60,8 @@ public class MycroftHandler extends BaseThingHandler implements MycroftConnectio private final Logger logger = LoggerFactory.getLogger(MycroftHandler.class); - protected final MycroftConnection connection; + private final WebSocketFactory webSocketFactory; + private @NonNullByDefault({}) MycroftConnection connection; private @Nullable ScheduledFuture scheduledFuture; private MycroftConfiguration config = new MycroftConfiguration(); private boolean thingDisposing = false; @@ -72,14 +73,7 @@ public class MycroftHandler extends BaseThingHandler implements MycroftConnectio public MycroftHandler(Thing thing, WebSocketFactory webSocketFactory) { super(thing); - String websocketID = thing.getUID().getAsString().replace(':', '-'); - if (websocketID.length() < 4) { - websocketID = "mycroft-" + websocketID; - } - if (websocketID.length() > 20) { - websocketID = websocketID.substring(websocketID.length() - 20); - } - this.connection = new MycroftConnection(this, webSocketFactory.createWebSocketClient(websocketID)); + this.webSocketFactory = webSocketFactory; } /** @@ -135,6 +129,15 @@ public void initialize() { config = getConfigAs(MycroftConfiguration.class); + String websocketID = thing.getUID().getAsString().replace(':', '-'); + if (websocketID.length() < 4) { + websocketID = "mycroft-" + websocketID; + } + if (websocketID.length() > 20) { + websocketID = websocketID.substring(websocketID.length() - 20); + } + this.connection = new MycroftConnection(this, webSocketFactory.createWebSocketClient(websocketID)); + scheduledFuture = scheduler.scheduleWithFixedDelay(this::startWebsocket, 0, POLL_FREQUENCY_SEC, TimeUnit.SECONDS); From 897af70075e8919e8878b5a3bca64b731caea882 Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Mon, 20 Dec 2021 17:29:33 +0100 Subject: [PATCH 25/39] Apply suggestion from code review: websocket creation not in constructor Signed-off-by: Gwendal Roulleau --- .../openhab/binding/mycroft/internal/MycroftHandler.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java index 7244996813b02..299556a4989ac 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java @@ -89,9 +89,9 @@ private void stopTimer() { /** * Starts the websocket connection. - * sometimes send a get volume request to fully test the connection / refresh volume. + * It sometimes also sends a get volume request to check the connection and refresh the volume. */ - private void startWebsocket() { + private void checkOrstartWebsocket() { if (thingDisposing) { return; } @@ -138,7 +138,7 @@ public void initialize() { } this.connection = new MycroftConnection(this, webSocketFactory.createWebSocketClient(websocketID)); - scheduledFuture = scheduler.scheduleWithFixedDelay(this::startWebsocket, 0, POLL_FREQUENCY_SEC, + scheduledFuture = scheduler.scheduleWithFixedDelay(this::checkOrstartWebsocket, 0, POLL_FREQUENCY_SEC, TimeUnit.SECONDS); registerChannel(new ListenChannel(this)); From 84b467d9b9f5f94951221ace271b83b665442753 Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Mon, 20 Dec 2021 17:55:41 +0100 Subject: [PATCH 26/39] Apply suggestion from code review: check host and port from conf Signed-off-by: Gwendal Roulleau --- .../binding/mycroft/internal/MycroftHandler.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java index 299556a4989ac..1f0491605cac5 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java @@ -127,8 +127,6 @@ public void initialize() { logger.debug("Start initializing Mycroft {}", thing.getUID()); - config = getConfigAs(MycroftConfiguration.class); - String websocketID = thing.getUID().getAsString().replace(':', '-'); if (websocketID.length() < 4) { websocketID = "mycroft-" + websocketID; @@ -138,6 +136,15 @@ public void initialize() { } this.connection = new MycroftConnection(this, webSocketFactory.createWebSocketClient(websocketID)); + config = getConfigAs(MycroftConfiguration.class); + if (config.host.isBlank()) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_PENDING, "No host defined"); + return; + } else if (config.port < 0 || config.port > 0xFFFF) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, + "Port should be between 0 and 65536"); + return; + } scheduledFuture = scheduler.scheduleWithFixedDelay(this::checkOrstartWebsocket, 0, POLL_FREQUENCY_SEC, TimeUnit.SECONDS); From 6dcc66c0cf2a01a6ff3f4b413eabf8df2c711d57 Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Mon, 20 Dec 2021 18:13:54 +0100 Subject: [PATCH 27/39] Apply suggestion from code review: debug level for network issue Signed-off-by: Gwendal Roulleau --- .../org/openhab/binding/mycroft/internal/MycroftHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java index 1f0491605cac5..85b347801829f 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java @@ -227,7 +227,7 @@ public boolean sendMessage(BaseMessage message) { connection.sendMessage(message); return true; } catch (IOException e) { - logger.warn("Cannot send message of type {}, for reason {}", message.getClass().getName(), e.getMessage()); + logger.debug("Cannot send message of type {}, for reason {}", message.getClass().getName(), e.getMessage()); return false; } } @@ -237,7 +237,7 @@ public boolean sendMessage(String message) { connection.sendMessage(message); return true; } catch (IOException e) { - logger.warn("Cannot send message of type {}, for reason {}", message.getClass().getName(), e.getMessage()); + logger.debug("Cannot send message of type {}, for reason {}", message.getClass().getName(), e.getMessage()); return false; } } From 1aa522c68362acd7204116ce2b1b46013a39b50a Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Mon, 20 Dec 2021 18:14:40 +0100 Subject: [PATCH 28/39] Apply suggestion from code review: improve comments Signed-off-by: Gwendal Roulleau --- .../openhab/binding/mycroft/internal/api/MessageType.java | 4 ++-- .../binding/mycroft/internal/api/MycroftConnection.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageType.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageType.java index 108687c96100e..fefd988e3ea0e 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageType.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageType.java @@ -90,9 +90,9 @@ public enum MessageType { } /** - * get the expected message type for this message + * Get the expected message type for this message * - * @return + * @return The message type class associated with this type */ public @NotNull Class getMessageTypeClass() { return messageTypeClass; diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java index db7b2dfd3d6a8..cc060d10b6412 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java @@ -116,10 +116,10 @@ public void close() { /** * The listener registered in this method will be called when a corresponding message will be detected - * on the mycroft bus + * on the Mycroft bus. * - * @param messageType - * @param listener + * @param messageType The message type to listen to. + * @param listener The listener will receive a callback when the requested message type will be detected on the bus. */ public void registerListener(MessageType messageType, MycroftMessageListener listener) { Set> messageTypeListeners = listeners.get(messageType); From e9a999c05a63ae64cc7128615c0e49de6c739630 Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Mon, 20 Dec 2021 18:20:03 +0100 Subject: [PATCH 29/39] Apply suggestion from code review: debug log for network issue Signed-off-by: Gwendal Roulleau --- .../openhab/binding/mycroft/internal/api/MycroftConnection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java index cc060d10b6412..eca66bd72ccfc 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java @@ -209,7 +209,7 @@ public void onError(@Nullable Session session, Throwable cause) { handleWrongSession(session, "Connection error: " + cause.getMessage()); return; } - logger.warn("{} connection error, closing: {}", socketName, cause.getMessage()); + logger.debug("{} connection error, closing: {}", socketName, cause.getMessage()); Session storedSession = this.session; if (storedSession != null && storedSession.isOpen()) { From 61874183ddfb0003f55ae4bd15e02fe9f59cdfbb Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Mon, 20 Dec 2021 18:24:14 +0100 Subject: [PATCH 30/39] Apply suggestion from code review: improve comments Signed-off-by: Gwendal Roulleau --- .../openhab/binding/mycroft/internal/api/dto/BaseMessage.java | 1 + 1 file changed, 1 insertion(+) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/BaseMessage.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/BaseMessage.java index 2eee6b29abf5e..e3eafeaf53673 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/BaseMessage.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/BaseMessage.java @@ -15,6 +15,7 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** + * This is the base message class for all messages circulating on the Mycroft bus. * * @author Gwendal Roulleau - Initial contribution */ From 57d42ed1f3b5c89d87b292fd3dd72bd01b5b7969 Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Tue, 28 Dec 2021 11:25:54 +0100 Subject: [PATCH 31/39] Bump version Signed-off-by: Gwendal Roulleau --- bundles/org.openhab.binding.mycroft/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.mycroft/pom.xml b/bundles/org.openhab.binding.mycroft/pom.xml index c06a12e3f4f6c..c64f7f086a7c9 100644 --- a/bundles/org.openhab.binding.mycroft/pom.xml +++ b/bundles/org.openhab.binding.mycroft/pom.xml @@ -7,7 +7,7 @@ org.openhab.addons.bundles org.openhab.addons.reactor.bundles - 3.2.0-SNAPSHOT + 3.3.0-SNAPSHOT org.openhab.binding.mycroft From a829e11312d7232c4e6785c92073cd505288784f Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Thu, 30 Dec 2021 18:30:28 +0100 Subject: [PATCH 32/39] Apply suggestion from code review : javadoc on messages classes Signed-off-by: Gwendal Roulleau --- .../binding/mycroft/internal/api/dto/MessageAudioNext.java | 2 ++ .../binding/mycroft/internal/api/dto/MessageAudioPause.java | 2 ++ .../binding/mycroft/internal/api/dto/MessageAudioPlay.java | 2 ++ .../binding/mycroft/internal/api/dto/MessageAudioPrev.java | 2 ++ .../binding/mycroft/internal/api/dto/MessageAudioResume.java | 2 ++ .../binding/mycroft/internal/api/dto/MessageAudioStop.java | 2 ++ .../mycroft/internal/api/dto/MessageAudioTrackInfo.java | 5 ++++- .../mycroft/internal/api/dto/MessageAudioTrackInfoReply.java | 3 +++ .../binding/mycroft/internal/api/dto/MessageMicListen.java | 2 ++ .../internal/api/dto/MessageRecognizerLoopRecordBegin.java | 2 ++ .../internal/api/dto/MessageRecognizerLoopRecordEnd.java | 2 ++ .../internal/api/dto/MessageRecognizerLoopUtterance.java | 2 ++ .../binding/mycroft/internal/api/dto/MessageSpeak.java | 2 ++ .../mycroft/internal/api/dto/MessageVolumeDecrease.java | 1 + .../binding/mycroft/internal/api/dto/MessageVolumeDuck.java | 2 ++ .../binding/mycroft/internal/api/dto/MessageVolumeGet.java | 3 +++ .../mycroft/internal/api/dto/MessageVolumeGetResponse.java | 4 ++++ .../mycroft/internal/api/dto/MessageVolumeIncrease.java | 1 + .../binding/mycroft/internal/api/dto/MessageVolumeMute.java | 1 + .../binding/mycroft/internal/api/dto/MessageVolumeSet.java | 2 ++ .../mycroft/internal/api/dto/MessageVolumeUnduck.java | 2 ++ .../mycroft/internal/api/dto/MessageVolumeUnmute.java | 1 + 22 files changed, 46 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioNext.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioNext.java index 389ad6d4d466d..f3b9cdc8c8958 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioNext.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioNext.java @@ -15,6 +15,8 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** + * This message asks Mycroft to play the next title in + * its underlying player. * * @author Gwendal Roulleau - Initial Contribution * diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPause.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPause.java index 03569dd44bef9..7b911cb8f8db2 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPause.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPause.java @@ -15,6 +15,8 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** + * This message asks Mycroft to pause + * its underlying player. * * @author Gwendal Roulleau - Initial contribution */ diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPlay.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPlay.java index bfcecd2f9a360..8f25c86187a1f 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPlay.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPlay.java @@ -15,6 +15,8 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** + * This message asks Mycroft to send the play command to + * its underlying player. * * @author Gwendal Roulleau - Initial contribution * diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPrev.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPrev.java index 1286f039673dc..5cc8041a5051d 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPrev.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPrev.java @@ -15,6 +15,8 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** + * This message asks Mycroft to play the previous title in + * its underlying player. * * @author Gwendal Roulleau - Initial contribution * diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioResume.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioResume.java index ef6d7143f3c03..80e052b2413b5 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioResume.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioResume.java @@ -15,6 +15,8 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** + * This message asks Mycroft to send resume command to + * its underlying player * * @author Gwendal Roulleau - Initial contribution * diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioStop.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioStop.java index 0300acb9e9cbf..51b424e2cd091 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioStop.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioStop.java @@ -15,6 +15,8 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** + * This message asks Mycroft to stop + * its underlying player. * * @author Gwendal Roulleau - Initial contribution */ diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfo.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfo.java index babc8bc95bc9f..7cb1ae3848a39 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfo.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfo.java @@ -15,7 +15,10 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** - * + * This message asks Mycroft to give information about + * the title played on its underlying player. + * Work in progress + * * @author Gwendal Roulleau - Initial contribution */ public class MessageAudioTrackInfo extends BaseMessage { diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfoReply.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfoReply.java index bf26698db547c..67a06d5da90d2 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfoReply.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfoReply.java @@ -15,6 +15,9 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** + * This message is sent by Mycroft to give information about + * the title played on its underlying player. + * Work in progress * * @author Gwendal Roulleau - Initial contribution */ diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageMicListen.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageMicListen.java index ef6e243d7fe62..3f5939d925f11 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageMicListen.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageMicListen.java @@ -15,6 +15,8 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** + * This message asks Mycroft to begin to listen to the mic + * and to try to do STT and intent recognition. * * @author Gwendal Roulleau - Initial contribution */ diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordBegin.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordBegin.java index 51bd5e438abb5..ba871d7b48d83 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordBegin.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordBegin.java @@ -15,6 +15,8 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** + * This message informs the bus clients that Mycroft + * is actively listening and trying to do STT. * * @author Gwendal Roulleau - Initial contribution */ diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordEnd.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordEnd.java index a13de2fce8461..d96e260bfb9ab 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordEnd.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordEnd.java @@ -15,6 +15,8 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** + * This message informs the bus clients that Mycroft + * finished listening to the mic. * * @author Gwendal Roulleau - Initial contribution */ diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopUtterance.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopUtterance.java index 8b2f89ac73ccf..610b0d93ff0f2 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopUtterance.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopUtterance.java @@ -18,6 +18,8 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** + * This message is sent to the skills + * module to trigger an intent from a text. * * @author Gwendal Roulleau - Initial contribution */ diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageSpeak.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageSpeak.java index 36dd421185827..52f97eb6ec71c 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageSpeak.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageSpeak.java @@ -18,6 +18,8 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** + * This message is sent to the Mycroft audio module + * to trigger a TTS action. * * @author Gwendal Roulleau - Initial contribution */ diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDecrease.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDecrease.java index f465e6aab6cbe..ab25c648cca62 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDecrease.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDecrease.java @@ -15,6 +15,7 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** + * This message asks Mycroft to decrease the volume by 10% * * @author Gwendal Roulleau - Initial contribution */ diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDuck.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDuck.java index 372e79b93d00a..84ce3aeed680b 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDuck.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDuck.java @@ -15,6 +15,8 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** + * This message is sent by Mycroft to signal that the volume + * is ducked during a STT recognition process. * * @author Gwendal Roulleau - Initial contribution */ diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGet.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGet.java index d82892c1044cb..a68b67666f3cb 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGet.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGet.java @@ -15,6 +15,9 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** + * This message asks Mycroft to answer with the current volume + * NOT FUNCTIONAL + * (see https://community.mycroft.ai/t/openhab-plugin-development-audio-volume-message-types-missing/10576) * * @author Gwendal Roulleau - Initial contribution */ diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGetResponse.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGetResponse.java index b2d9587551b34..69285827b7bad 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGetResponse.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGetResponse.java @@ -15,6 +15,10 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** + * This message is sent in response to a VolumeGet message + * with the current volume in Mycroft + * NOT FUNCTIONAL + * (see https://community.mycroft.ai/t/openhab-plugin-development-audio-volume-message-types-missing/10576) * * @author Gwendal Roulleau - Initial contribution */ diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeIncrease.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeIncrease.java index f8faeda32ae6c..f962ee2c751bc 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeIncrease.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeIncrease.java @@ -15,6 +15,7 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** + * This message asks Mycroft to increase the volume by 10% * * @author Gwendal Roulleau - Initial contribution */ diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeMute.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeMute.java index c153c2115fa7c..18fd68e47ab72 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeMute.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeMute.java @@ -15,6 +15,7 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** + * This message asks Mycroft to mute the volume * * @author Gwendal Roulleau - Initial contribution */ diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeSet.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeSet.java index 6974c1c6121aa..ea7b885990ade 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeSet.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeSet.java @@ -15,6 +15,8 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** + * This message asks Mycroft to set the volume to an amount + * specified in the data payload * * @author Gwendal Roulleau - Initial contribution */ diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnduck.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnduck.java index 094505ce4b25b..0cc0b4a0c02be 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnduck.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnduck.java @@ -15,6 +15,8 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** + * This message is sent by Mycroft to signal that the volume + * is no longer ducked after a STT recognition process. * * @author Gwendal Roulleau - Initial contribution */ diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnmute.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnmute.java index 8f309bbc0d491..f1e07256b1a4c 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnmute.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnmute.java @@ -15,6 +15,7 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** + * This message asks Mycroft to unmute the volume * * @author Gwendal Roulleau - Initial contribution */ From 4dd61fa5774fc7e6778a2a9fda0b572dfec9282c Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Thu, 30 Dec 2021 18:44:06 +0100 Subject: [PATCH 33/39] Apply suggestion from code review : javadoc Signed-off-by: Gwendal Roulleau --- .../mycroft/internal/channels/VolumeChannel.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java index ad38fb5a87f89..4e5de23e769df 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java @@ -87,10 +87,12 @@ protected final void updateAndSaveMyState(State state) { } /** - * Volume between 0 and 100 + * Protection method for volume with + * potentially wrong value. * - * @param volume - * @return + * @param volume The requested volume, on a scale from 0 to 100. + * Could be out of bond, then it will be corrected. + * @return A safe volume in PercentType between 0 and 100 */ private PercentType normalizeVolume(int volume) { if (volume >= 100) { @@ -103,10 +105,11 @@ private PercentType normalizeVolume(int volume) { } /** - * Volume between 0 and 1 + * Protection method for volume with + * potentially wrong value. * - * @param volume - * @return + * @param volume The requested volume, on a scale from 0 to 1. + * @return A safe volume in PercentType between 0 and 100 */ private PercentType normalizeVolume(float volume) { if (volume >= 1) { From b456248abb41875cecee1bb920c5e3bc7c861ea2 Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Thu, 30 Dec 2021 19:03:58 +0100 Subject: [PATCH 34/39] Apply suggestion from code review : description, and use system channel types Signed-off-by: Gwendal Roulleau --- .../main/resources/OH-INF/binding/binding.xml | 3 +- .../resources/OH-INF/thing/thing-types.xml | 28 ++++--------------- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml index 6b7e4a6ea1a95..41ed59d5e1e8b 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml +++ b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml @@ -4,9 +4,8 @@ xsi:schemaLocation="https://openhab.org/schemas/binding/v1.0.0 https://openhab.org/schemas/binding-1.0.0.xsd"> Mycroft Binding - Connect to the Mycroft message bus in order to receive information from, and send commands to Mycroft. + Connects to a Mycroft instance in order to receive information from, and send commands to it. Typical usage includes triggering Mycroft to listen (as if a wake word was detected), sending text for Mycroft to speak, reacting on some specific intent, command skills by faking a spoken utterance, etc. - Gwendal Roulleau diff --git a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml index 3bf4b1a7121b0..bd913506c1c2e 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml @@ -12,21 +12,21 @@ - - - + + + - + This is the host to connect to (ip or hostname) network-address - + This is the port to connect to. 8181 @@ -65,24 +65,6 @@ - - Player - - The music player Mycroft is currently controlling. - - - - - - Switch - - Mute the Mycroft speaker - - Switch From 57d023a84c7d82590b915564ee88b4812b6b8be0 Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Thu, 30 Dec 2021 21:51:31 +0100 Subject: [PATCH 35/39] Refactor message parsing to be easier to read Signed-off-by: Gwendal Roulleau --- .../internal/api/MycroftConnection.java | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java index eca66bd72ccfc..bfe5d642aef31 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java @@ -23,6 +23,7 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -173,27 +174,22 @@ public void onMessage(Session session, String message) { logger.trace("{} received raw data: {}", socketName, message); try { - // listeners on message type : + // get the base message information : BaseMessage mycroftMessage = gson.fromJson(message, BaseMessage.class); Objects.requireNonNull(mycroftMessage); - mycroftMessage.message = message; - - // special listener : to any messages - Set> listenersAnyToNotify = listeners.get(MessageType.any); - if (listenersAnyToNotify != null && !listenersAnyToNotify.isEmpty()) { - for (MycroftMessageListener listener : listenersAnyToNotify) { - listener.baseMessageReceived(mycroftMessage); - } + // now that we have the message type, we can use a second and more precise parsing: + if (mycroftMessage.type != MessageType.any) { + mycroftMessage = gson.fromJson(message, mycroftMessage.type.getMessageTypeClass()); + Objects.requireNonNull(mycroftMessage); } + // adding the raw message: + mycroftMessage.message = message; - // listener for specific message type - Set> listenersToNotify = listeners.get(mycroftMessage.type); - if (mycroftMessage.type != MessageType.any && listenersToNotify != null && !listenersToNotify.isEmpty()) { - BaseMessage fullMycroftMessage = gson.fromJson(message, mycroftMessage.type.getMessageTypeClass()); - mycroftMessage.message = message; - Objects.requireNonNull(fullMycroftMessage); - listenersToNotify.forEach(listener -> listener.baseMessageReceived(fullMycroftMessage)); - } + final BaseMessage finalMessage = mycroftMessage; + Stream.concat(listeners.getOrDefault(MessageType.any, new HashSet<>()).stream(), + listeners.getOrDefault(mycroftMessage.type, new HashSet<>()).stream()).forEach(listener -> { + listener.baseMessageReceived(finalMessage); + }); } catch (RuntimeException e) { // we need to catch all processing exceptions, otherwise they could affect the connection From 684149f5a760c7cdf2cc06cbc6fd35614a062b36 Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Fri, 31 Dec 2021 01:34:36 +0100 Subject: [PATCH 36/39] Refactor volume management Delete the duck channel Workaround for Mycroft bad management of volume. Signed-off-by: Gwendal Roulleau --- bundles/org.openhab.binding.mycroft/README.md | 14 ++-- .../internal/MycroftBindingConstants.java | 1 - .../internal/MycroftConfiguration.java | 1 + .../mycroft/internal/MycroftHandler.java | 4 +- .../internal/api/dto/MessageVolumeSet.java | 6 +- .../internal/channels/DuckChannel.java | 68 ------------------- .../internal/channels/MuteChannel.java | 49 +++++++++++-- .../internal/channels/VolumeChannel.java | 41 ++++++----- .../main/resources/OH-INF/binding/binding.xml | 10 ++- .../resources/OH-INF/thing/thing-types.xml | 15 ++-- 10 files changed, 94 insertions(+), 115 deletions(-) delete mode 100644 bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/DuckChannel.java diff --git a/bundles/org.openhab.binding.mycroft/README.md b/bundles/org.openhab.binding.mycroft/README.md index 73ccbcbeb4ec4..62c4dfc5987d7 100644 --- a/bundles/org.openhab.binding.mycroft/README.md +++ b/bundles/org.openhab.binding.mycroft/README.md @@ -8,7 +8,7 @@ Possibilies include: - Simulate a voice command to launch a skill, as if you just spoke it - Send some text that Mycroft will say (Using its Text To Speech service) - Control the music player -- Mute or duck the sound volume of Mycroft +- Mute the sound volume of Mycroft - React to all the aforementioned events ... - ... and send/receive any other kind of messages on the message bus @@ -37,10 +37,11 @@ The default port is 8181, which can be changed. Thing mycroft:mycroft:myMycroft "Mycroft A.I." @ "Living Room" [host="192.168.X.X"] ``` -| property | type | description | mandatory | -|---------------|---------------------------------|-------------------------------------------------------------------------|-----------| -| host | IP or string | IP address or hostname | Yes | -| port | integer | Port to reach Mycroft (default 8181) | No | +| property | type | description | mandatory | +|--------------------------|------------------------|------------------------------------------------------------------|-----------| +| host | IP or string | IP address or hostname | Yes | +| port | integer | Port to reach Mycroft (default 8181) | No | +| volume_restoration_level | integer | When unmuted, force Mycroft to restore volume to this value | No | ## Channels @@ -55,7 +56,6 @@ A Mycroft thing has the following channels: | utterance | String | The last utterance Mycroft receive | | player | Player | The music player Mycroft is currently controlling | | volume_mute | Switch | Mute the Mycroft speaker | -| volume_duck | Switch | Duck the volume of the Mycroft speaker | | full_message | String | The last message (full json) seen on the Mycroft Bus. Filtered by the messageTypes properties | @@ -85,7 +85,6 @@ The `mycroft.item` file: ```java Switch myMycroft_mute "Mute" { channel="mycroft:mycroft:myMycroft:volume_mute" } -Switch myMycroft_duck "Duck" { channel="mycroft:mycroft:myMycroft:volume_duck" } Player myMycroft_player "Control" { channel="mycroft:mycroft:myMycroft:player" } Switch myMycroft_listen "Wake and listen" { channel="mycroft:mycroft:myMycroft:listen" } String myMycroft_speak "Speak STT" { channel="mycroft:mycroft:myMycroft:speak" } @@ -102,7 +101,6 @@ sitemap demo label="myMycroft" { Frame label="myMycroft" { Switch item=myMycroft_mute - Switch item=myMycroft_duck Default item=myMycroft_player Switch item=myMycroft_listen Text item=myMycroft_speak diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftBindingConstants.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftBindingConstants.java index 289fd297050d9..b35bfe3ea6370 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftBindingConstants.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftBindingConstants.java @@ -35,7 +35,6 @@ public class MycroftBindingConstants { public static final String PLAYER_CHANNEL = "player"; public static final String VOLUME_CHANNEL = "volume"; public static final String VOLUME_MUTE_CHANNEL = "volume_mute"; - public static final String VOLUME_DUCK_CHANNEL = "volume_duck"; public static final String UTTERANCE_CHANNEL = "utterance"; public static final String FULL_MESSAGE_CHANNEL = "full_message"; diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftConfiguration.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftConfiguration.java index 02fa90c00265a..d80273e22e4b2 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftConfiguration.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftConfiguration.java @@ -24,4 +24,5 @@ public class MycroftConfiguration { public String host = ""; public int port = 8181; + public int volume_restoration_level = 0; } diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java index 85b347801829f..9b7566dfe4c70 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java @@ -29,7 +29,6 @@ import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeGet; import org.openhab.binding.mycroft.internal.channels.AudioPlayerChannel; import org.openhab.binding.mycroft.internal.channels.ChannelCommandHandler; -import org.openhab.binding.mycroft.internal.channels.DuckChannel; import org.openhab.binding.mycroft.internal.channels.FullMessageChannel; import org.openhab.binding.mycroft.internal.channels.ListenChannel; import org.openhab.binding.mycroft.internal.channels.MuteChannel; @@ -150,8 +149,7 @@ public void initialize() { registerChannel(new ListenChannel(this)); registerChannel(new VolumeChannel(this)); - registerChannel(new MuteChannel(this)); - registerChannel(new DuckChannel(this)); + registerChannel(new MuteChannel(this, config.volume_restoration_level)); registerChannel(new SpeakChannel(this)); registerChannel(new AudioPlayerChannel(this)); registerChannel(new UtteranceChannel(this)); diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeSet.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeSet.java index ea7b885990ade..541cfa858817c 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeSet.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeSet.java @@ -15,8 +15,10 @@ import org.openhab.binding.mycroft.internal.api.MessageType; /** - * This message asks Mycroft to set the volume to an amount - * specified in the data payload + * This message asks IN THEORY Mycroft to set the volume to an amount + * specified in the data payload. + * But it seems in fact to be a message to inform third party of a + * volume change * * @author Gwendal Roulleau - Initial contribution */ diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/DuckChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/DuckChannel.java deleted file mode 100644 index 8893e2850e615..0000000000000 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/DuckChannel.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Copyright (c) 2010-2021 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.mycroft.internal.channels; - -import java.util.Arrays; -import java.util.List; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.openhab.binding.mycroft.internal.MycroftBindingConstants; -import org.openhab.binding.mycroft.internal.MycroftHandler; -import org.openhab.binding.mycroft.internal.api.MessageType; -import org.openhab.binding.mycroft.internal.api.dto.BaseMessage; -import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeDuck; -import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeUnduck; -import org.openhab.core.library.types.OnOffType; -import org.openhab.core.types.Command; - -/** - * The channel responsible for triggering STT recognition - * - * @author Gwendal Roulleau - Initial contribution - */ -@NonNullByDefault -public class DuckChannel extends MycroftChannel { - - public DuckChannel(MycroftHandler handler) { - super(handler, MycroftBindingConstants.VOLUME_DUCK_CHANNEL); - } - - @Override - public List getMessageToListenTo() { - return Arrays.asList(MessageType.mycroft_volume_duck, MessageType.mycroft_volume_unduck); - } - - @Override - public void messageReceived(BaseMessage message) { - if (message.type == MessageType.mycroft_volume_duck) { - updateMyState(OnOffType.ON); - } else if (message.type == MessageType.mycroft_volume_unduck) { - updateMyState(OnOffType.OFF); - } - } - - @Override - public void handleCommand(Command command) { - if (command instanceof OnOffType) { - if (command == OnOffType.ON) { - if (handler.sendMessage(new MessageVolumeDuck())) { - updateMyState(OnOffType.ON); - } - } else if (command == OnOffType.OFF) { - if (handler.sendMessage(new MessageVolumeUnduck())) { - updateMyState(OnOffType.OFF); - } - } - } - } -} diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MuteChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MuteChannel.java index 55e3ee578fe73..f34a0aca8effa 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MuteChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MuteChannel.java @@ -21,6 +21,7 @@ import org.openhab.binding.mycroft.internal.api.MessageType; import org.openhab.binding.mycroft.internal.api.dto.BaseMessage; import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeMute; +import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeSet; import org.openhab.binding.mycroft.internal.api.dto.MessageVolumeUnmute; import org.openhab.core.library.types.OnOffType; import org.openhab.core.types.Command; @@ -33,24 +34,49 @@ @NonNullByDefault public class MuteChannel extends MycroftChannel { - public MuteChannel(MycroftHandler handler) { + private int volumeRestorationLevel; + + public MuteChannel(MycroftHandler handler, int volumeRestorationLevel) { super(handler, MycroftBindingConstants.VOLUME_MUTE_CHANNEL); + this.volumeRestorationLevel = volumeRestorationLevel; } @Override public List getMessageToListenTo() { - return Arrays.asList(MessageType.mycroft_volume_mute, MessageType.mycroft_volume_unmute); + // we don't listen to mute/unmute message because duck/unduck seems sufficient + // and we don't want to change state twice for the same event + // but it should be tested on mark I, as volume is handled differently + return Arrays.asList(MessageType.mycroft_volume_duck, MessageType.mycroft_volume_unduck, + MessageType.mycroft_volume_set, MessageType.mycroft_volume_increase); } @Override public void messageReceived(BaseMessage message) { - if (message.type == MessageType.mycroft_volume_mute) { - updateMyState(OnOffType.ON); - } else if (message.type == MessageType.mycroft_volume_unmute) { - updateMyState(OnOffType.OFF); + switch (message.type) { + case mycroft_volume_mute: + case mycroft_volume_duck: + updateMyState(OnOffType.ON); + break; + case mycroft_volume_unmute: + case mycroft_volume_unduck: + case mycroft_volume_increase: + updateMyState(OnOffType.OFF); + break; + case mycroft_volume_set: + if (((MessageVolumeSet) message).data.percent > 0) { + updateMyState(OnOffType.OFF); + } + break; + default: } } + private boolean sendVolumeSetMessage(float volume) { + String messageToSend = VolumeChannel.VOLUME_SETTER_MESSAGE.replaceAll("\\$\\$VOLUME", + Float.valueOf(volume).toString()); + return handler.sendMessage(messageToSend); + } + @Override public void handleCommand(Command command) { if (command instanceof OnOffType) { @@ -61,6 +87,17 @@ public void handleCommand(Command command) { } else if (command == OnOffType.OFF) { if (handler.sendMessage(new MessageVolumeUnmute())) { updateMyState(OnOffType.OFF); + // if configured, we can restore the volume to a fixed amount + // usefull as a workaround for the broken Mycroft volume behavior + if (volumeRestorationLevel > 0) { + // we must wait 100ms for Mycroft to handle the message and + // setting old volume before forcing to our value + try { + Thread.sleep(100); + } catch (InterruptedException e) { + } + sendVolumeSetMessage(Float.valueOf(volumeRestorationLevel)); + } } } } diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java index 4e5de23e769df..efcf2cb11e62d 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java @@ -34,14 +34,21 @@ /** * The channel responsible for handling the volume of the Mycroft speaker - * NOT FUNCTIONAL - * (see https://community.mycroft.ai/t/openhab-plugin-development-audio-volume-message-types-missing/10576) + * QUITE FUNCTIONAL but with workaround + * (see https://community.mycroft.ai/t/openhab-plugin-development-audio-volume-message-types-missing/10576 + * and https://github.com/MycroftAI/skill-volume/issues/53) * * @author Gwendal Roulleau - Initial contribution */ @NonNullByDefault public class VolumeChannel extends MycroftChannel { + /** + * As the MessageVolumeSet is, contrary to the documentation, not listened to by Mycroft, + * we use a workaround and send a message simulating an intent detection + */ + public static final String VOLUME_SETTER_MESSAGE = "{\"type\": \"mycroft-volume.mycroftai:SetVolume\", \"data\": {\"intent_type\": \"mycroft-volume.mycroftai:SetVolume\", \"mycroft_volume_mycroftaiVolume\": \"volume\", \"mycroft_volume_mycroftaiLevel\": \"$$VOLUME\", \"mycroft_volume_mycroftaiTo\": \"to\", \"target\": null, \"confidence\": 0.6000000000000001, \"__tags__\": [{\"match\": \"volume\", \"key\": \"volume\", \"start_token\": 1, \"entities\": [{\"key\": \"volume\", \"match\": \"volume\", \"data\": [[\"volume\", \"mycroft_volume_mycroftaiVolume\"]], \"confidence\": 1.0}], \"end_token\": 1, \"from_context\": false}, {\"match\": \"$$VOLUME\", \"key\": \"$$VOLUME\", \"start_token\": 3, \"entities\": [{\"key\": \"$$VOLUME\", \"match\": \"$$VOLUME\", \"data\": [[\"$$VOLUME\", \"mycroft_volume_mycroftaiLevel\"]], \"confidence\": 1.0}], \"end_token\": 3, \"from_context\": false}, {\"match\": \"to\", \"key\": \"to\", \"start_token\": 2, \"entities\": [{\"key\": \"to\", \"match\": \"to\", \"data\": [[\"to\", \"mycroft_volume_mycroftaiTo\"]], \"confidence\": 1.0}], \"end_token\": 2, \"from_context\": false}], \"utterance\": \"set volume to $$VOLUME\", \"utterances\": [\"set volume to X\"]}, \"context\": {\"client_name\": \"mycroft_cli\", \"source\": [\"skills\"], \"destination\": \"debug_cli\"}}"; + private PercentType lastVolume = new PercentType(50); private PercentType lastNonZeroVolume = new PercentType(50); @@ -51,9 +58,12 @@ public VolumeChannel(MycroftHandler handler) { @Override public List getMessageToListenTo() { + // we don't listen to mute/unmute message because duck/unduck seems sufficient + // and we don't want to change state twice for the same event + // but it should be tested on mark I, as volume is handled differently return Arrays.asList(MessageType.mycroft_volume_get_response, MessageType.mycroft_volume_set, - MessageType.mycroft_volume_mute, MessageType.mycroft_volume_unmute, MessageType.mycroft_volume_increase, - MessageType.mycroft_volume_decrease); + MessageType.mycroft_volume_increase, MessageType.mycroft_volume_decrease, + MessageType.mycroft_volume_duck, MessageType.mycroft_volume_unduck); } @Override @@ -65,9 +75,9 @@ public void messageReceived(BaseMessage message) { } else if (message.type == MessageType.mycroft_volume_set) { float volumeSet = ((MessageVolumeSet) message).data.percent; updateAndSaveMyState(normalizeVolume(volumeSet)); - } else if (message.type == MessageType.mycroft_volume_mute) { + } else if (message.type == MessageType.mycroft_volume_duck) { updateAndSaveMyState(new PercentType(0)); - } else if (message.type == MessageType.mycroft_volume_unmute) { + } else if (message.type == MessageType.mycroft_volume_unduck) { updateAndSaveMyState(lastNonZeroVolume); } else if (message.type == MessageType.mycroft_volume_increase) { updateAndSaveMyState(normalizeVolume(lastVolume.intValue() + 10)); @@ -122,27 +132,28 @@ private PercentType normalizeVolume(float volume) { } public float toMycroftVolume(PercentType percentType) { - return Float.valueOf(percentType.intValue() / 100f); + return Float.valueOf(percentType.intValue()); } public PercentType computeNewVolume(int valueAdded) { return new PercentType(lastVolume.intValue() + valueAdded); } + private boolean sendSetMessage(float volume) { + String messageToSend = VOLUME_SETTER_MESSAGE.replaceAll("\\$\\$VOLUME", Float.valueOf(volume).toString()); + return handler.sendMessage(messageToSend); + } + @Override public void handleCommand(Command command) { if (command instanceof OnOffType) { if (command == OnOffType.ON) { - MessageVolumeSet messageVolumeSet = new MessageVolumeSet(); - messageVolumeSet.data.percent = toMycroftVolume(lastNonZeroVolume); - if (handler.sendMessage(messageVolumeSet)) { + if (sendSetMessage(toMycroftVolume(lastNonZeroVolume))) { updateAndSaveMyState(lastNonZeroVolume); } } if (command == OnOffType.OFF) { - MessageVolumeSet messageVolumeSet = new MessageVolumeSet(); - messageVolumeSet.data.percent = 0; - if (handler.sendMessage(messageVolumeSet)) { + if (sendSetMessage(0)) { updateAndSaveMyState(PercentType.ZERO); } } @@ -157,9 +168,7 @@ public void handleCommand(Command command) { updateAndSaveMyState(computeNewVolume(-10)); } } else if (command instanceof PercentType) { - MessageVolumeSet messageVolumeSet = new MessageVolumeSet(); - messageVolumeSet.data.percent = toMycroftVolume((PercentType) command); - handler.sendMessage(messageVolumeSet); + sendSetMessage(toMycroftVolume((PercentType) command)); updateAndSaveMyState((PercentType) command); } else if (command instanceof RefreshType) { handler.sendMessage(new MessageVolumeGet()); diff --git a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml index 41ed59d5e1e8b..03d6cb09a67c5 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml +++ b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/binding/binding.xml @@ -4,8 +4,12 @@ xsi:schemaLocation="https://openhab.org/schemas/binding/v1.0.0 https://openhab.org/schemas/binding-1.0.0.xsd"> Mycroft Binding - Connects to a Mycroft instance in order to receive information from, and send commands to it. - Typical usage includes triggering Mycroft to listen (as if a wake word was detected), sending text for Mycroft to - speak, reacting on some specific intent, command skills by faking a spoken utterance, etc. + + Connects to a Mycroft instance in order to receive information from, and send commands to it. Typical + usage includes + triggering Mycroft to listen (as if a wake word was detected), sending text for Mycroft to speak, + reacting on some + specific intent, command skills by faking a spoken utterance, etc. + diff --git a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml index bd913506c1c2e..26e384f46647c 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml @@ -13,9 +13,8 @@ - + - @@ -30,6 +29,12 @@ This is the port to connect to. 8181 + + true + + When unmuted, force Mycroft to restore volume to this value + + @@ -65,10 +70,4 @@ - - Switch - - Duck the volume of the Mycroft speaker - - From b11d9da50b9af9bcda371e6950897bf4da9f55ff Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Thu, 6 Jan 2022 19:20:27 +0100 Subject: [PATCH 37/39] Add french i18n Signed-off-by: Gwendal Roulleau --- .../OH-INF/i18n/mycroft_fr.properties | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/i18n/mycroft_fr.properties diff --git a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/i18n/mycroft_fr.properties b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/i18n/mycroft_fr.properties new file mode 100644 index 0000000000000..8f05dbb08bdee --- /dev/null +++ b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/i18n/mycroft_fr.properties @@ -0,0 +1,34 @@ +# binding + +binding.mycroft.name = Extension Mycroft +binding.mycroft.description = Cette extension se connecte à une enceinte Mycroft pour recevoir des informations et envoyer des commandes. Parmi les usages typiques : déclencher l'écoute de Mycroft (comme si le mot de réveil avait été détecté), envoyer un texte pour qu'il soit énoncé, réagir à un Intent, commander à des Skills comme si une phrase avait été prononcée, etc. + +# thing types + +thing-type.mycroft.mycroft.label = Mycroft +thing-type.mycroft.mycroft.description = Une instance de Mycroft (Mark I/II, Picroft). + +# thing types config + +thing-type.config.mycroft.mycroft.host.label = Nom d'hôte +thing-type.config.mycroft.mycroft.host.description = Nom d'hôte de l'instance. +thing-type.config.mycroft.mycroft.port.label = Port +thing-type.config.mycroft.mycroft.port.description = Port du bus de message. +thing-type.config.mycroft.mycroft.volume_restoration_level.label = Niveau du volume de restauration +thing-type.config.mycroft.mycroft.volume_restoration_level.description = Quand le volume est restauré, force Mycroft a le régler à cette valeur. + +# channel types + +channel-type.mycroft.full-message-channel.label = Message complet +channel-type.mycroft.full-message-channel.description = Le dernier message qui a été vu sur le bus de message. +channel-type.mycroft.listen-channel.label = État de l'écoute +channel-type.mycroft.listen-channel.description = Allumé quand Mycroft écoute activement. Peut du coup simuler le mot de réveil. +channel-type.mycroft.speak-channel.label = Synthèse vocale +channel-type.mycroft.speak-channel.description = Phrase énoncée par Mycroft. +channel-type.mycroft.utterance-channel.label = Commande vocale +channel-type.mycroft.utterance-channel.description = Commande vocale reçue par Mycroft. + +# channel types config + +channel-type.config.mycroft.full-message-channel.messageTypes.label = Filtre du canal Message complet +channel-type.config.mycroft.full-message-channel.messageTypes.description = Le canal Message complet sera mis à jour uniquement pour ces types de messages (liste séparée par une virgule) From 345123447e5ac228fd662d109ed4cc1d41429545 Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Thu, 6 Jan 2022 21:33:11 +0100 Subject: [PATCH 38/39] Code analysis tools fix --> 2010-2022 Signed-off-by: Gwendal Roulleau --- .../binding/mycroft/internal/MycroftBindingConstants.java | 2 +- .../openhab/binding/mycroft/internal/MycroftConfiguration.java | 2 +- .../org/openhab/binding/mycroft/internal/MycroftHandler.java | 2 +- .../openhab/binding/mycroft/internal/MycroftHandlerFactory.java | 2 +- .../org/openhab/binding/mycroft/internal/api/MessageType.java | 2 +- .../binding/mycroft/internal/api/MessageTypeConverter.java | 2 +- .../openhab/binding/mycroft/internal/api/MycroftConnection.java | 2 +- .../binding/mycroft/internal/api/MycroftConnectionListener.java | 2 +- .../binding/mycroft/internal/api/MycroftMessageListener.java | 2 +- .../openhab/binding/mycroft/internal/api/dto/BaseMessage.java | 2 +- .../binding/mycroft/internal/api/dto/MessageAudioNext.java | 2 +- .../binding/mycroft/internal/api/dto/MessageAudioPause.java | 2 +- .../binding/mycroft/internal/api/dto/MessageAudioPlay.java | 2 +- .../binding/mycroft/internal/api/dto/MessageAudioPrev.java | 2 +- .../binding/mycroft/internal/api/dto/MessageAudioResume.java | 2 +- .../binding/mycroft/internal/api/dto/MessageAudioStop.java | 2 +- .../binding/mycroft/internal/api/dto/MessageAudioTrackInfo.java | 2 +- .../mycroft/internal/api/dto/MessageAudioTrackInfoReply.java | 2 +- .../binding/mycroft/internal/api/dto/MessageMicListen.java | 2 +- .../internal/api/dto/MessageRecognizerLoopRecordBegin.java | 2 +- .../internal/api/dto/MessageRecognizerLoopRecordEnd.java | 2 +- .../internal/api/dto/MessageRecognizerLoopUtterance.java | 2 +- .../openhab/binding/mycroft/internal/api/dto/MessageSpeak.java | 2 +- .../binding/mycroft/internal/api/dto/MessageVolumeDecrease.java | 2 +- .../binding/mycroft/internal/api/dto/MessageVolumeDuck.java | 2 +- .../binding/mycroft/internal/api/dto/MessageVolumeGet.java | 2 +- .../mycroft/internal/api/dto/MessageVolumeGetResponse.java | 2 +- .../binding/mycroft/internal/api/dto/MessageVolumeIncrease.java | 2 +- .../binding/mycroft/internal/api/dto/MessageVolumeMute.java | 2 +- .../binding/mycroft/internal/api/dto/MessageVolumeSet.java | 2 +- .../binding/mycroft/internal/api/dto/MessageVolumeUnduck.java | 2 +- .../binding/mycroft/internal/api/dto/MessageVolumeUnmute.java | 2 +- .../binding/mycroft/internal/channels/AudioPlayerChannel.java | 2 +- .../mycroft/internal/channels/ChannelCommandHandler.java | 2 +- .../binding/mycroft/internal/channels/FullMessageChannel.java | 2 +- .../binding/mycroft/internal/channels/ListenChannel.java | 2 +- .../openhab/binding/mycroft/internal/channels/MuteChannel.java | 2 +- .../binding/mycroft/internal/channels/MycroftChannel.java | 2 +- .../openhab/binding/mycroft/internal/channels/SpeakChannel.java | 2 +- .../binding/mycroft/internal/channels/UtteranceChannel.java | 2 +- .../binding/mycroft/internal/channels/VolumeChannel.java | 2 +- .../binding/mycroft/internal/api/MycroftConnectionTest.java | 2 +- 42 files changed, 42 insertions(+), 42 deletions(-) diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftBindingConstants.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftBindingConstants.java index b35bfe3ea6370..cec1aabacfb58 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftBindingConstants.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftBindingConstants.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftConfiguration.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftConfiguration.java index d80273e22e4b2..efe76fc85db76 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftConfiguration.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftConfiguration.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java index 9b7566dfe4c70..d086274dc88c5 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandler.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandlerFactory.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandlerFactory.java index 80e907aa87f5a..a403fb8a23add 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandlerFactory.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/MycroftHandlerFactory.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageType.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageType.java index fefd988e3ea0e..29320d95bcff0 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageType.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageType.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageTypeConverter.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageTypeConverter.java index 3efa6688527bc..4c476b94b6fff 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageTypeConverter.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MessageTypeConverter.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java index bfe5d642aef31..d7fbc623a5226 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnection.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnectionListener.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnectionListener.java index c6256a39e6344..6990de076a792 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnectionListener.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftConnectionListener.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftMessageListener.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftMessageListener.java index f8d549cf62246..86a8ca79a7f83 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftMessageListener.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/MycroftMessageListener.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/BaseMessage.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/BaseMessage.java index e3eafeaf53673..94b366e3c2cf4 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/BaseMessage.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/BaseMessage.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioNext.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioNext.java index f3b9cdc8c8958..5bef6536ea74a 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioNext.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioNext.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPause.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPause.java index 7b911cb8f8db2..6775e8d948e11 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPause.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPause.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPlay.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPlay.java index 8f25c86187a1f..3fd2f360d96c3 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPlay.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPlay.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPrev.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPrev.java index 5cc8041a5051d..c3df5061dca6c 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPrev.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioPrev.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioResume.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioResume.java index 80e052b2413b5..6db55a43e9a0d 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioResume.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioResume.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioStop.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioStop.java index 51b424e2cd091..9b989670bb9a1 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioStop.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioStop.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfo.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfo.java index 7cb1ae3848a39..91ae000d8b7c3 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfo.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfo.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfoReply.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfoReply.java index 67a06d5da90d2..71055a6ed757f 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfoReply.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageAudioTrackInfoReply.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageMicListen.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageMicListen.java index 3f5939d925f11..26f130a096eab 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageMicListen.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageMicListen.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordBegin.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordBegin.java index ba871d7b48d83..b31104de5d648 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordBegin.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordBegin.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordEnd.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordEnd.java index d96e260bfb9ab..c00ec55e02d24 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordEnd.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopRecordEnd.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopUtterance.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopUtterance.java index 610b0d93ff0f2..a8fb2a359b0aa 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopUtterance.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageRecognizerLoopUtterance.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageSpeak.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageSpeak.java index 52f97eb6ec71c..1f34a46f68aae 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageSpeak.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageSpeak.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDecrease.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDecrease.java index ab25c648cca62..15281a860c40c 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDecrease.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDecrease.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDuck.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDuck.java index 84ce3aeed680b..42cc439f8c0d6 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDuck.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeDuck.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGet.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGet.java index a68b67666f3cb..d62e0ddaf79fa 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGet.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGet.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGetResponse.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGetResponse.java index 69285827b7bad..cbbbbb992a646 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGetResponse.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeGetResponse.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeIncrease.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeIncrease.java index f962ee2c751bc..48b1a47c0422a 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeIncrease.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeIncrease.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeMute.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeMute.java index 18fd68e47ab72..b35b674f98eef 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeMute.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeMute.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeSet.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeSet.java index 541cfa858817c..8f4738da4a460 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeSet.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeSet.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnduck.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnduck.java index 0cc0b4a0c02be..933d8026b97ca 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnduck.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnduck.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnmute.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnmute.java index f1e07256b1a4c..94a3d86a45985 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnmute.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/api/dto/MessageVolumeUnmute.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/AudioPlayerChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/AudioPlayerChannel.java index c0a2d6cac959c..13fd7e4de2ee4 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/AudioPlayerChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/AudioPlayerChannel.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ChannelCommandHandler.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ChannelCommandHandler.java index 28555fc869ef2..2cba16d02ba73 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ChannelCommandHandler.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ChannelCommandHandler.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/FullMessageChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/FullMessageChannel.java index f5e4c3dd54eba..9a650ecb0bae4 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/FullMessageChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/FullMessageChannel.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ListenChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ListenChannel.java index 23ee494f95ae2..b1264438565ad 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ListenChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/ListenChannel.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MuteChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MuteChannel.java index f34a0aca8effa..2681723f1dac8 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MuteChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MuteChannel.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MycroftChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MycroftChannel.java index 418e70f074320..22e5a7fa1eb8c 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MycroftChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/MycroftChannel.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/SpeakChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/SpeakChannel.java index 08985ad5669c8..6b83b11048fcf 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/SpeakChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/SpeakChannel.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/UtteranceChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/UtteranceChannel.java index ed6e9290f963f..a019ca7b5a817 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/UtteranceChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/UtteranceChannel.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java index efcf2cb11e62d..dccd359db7608 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java +++ b/bundles/org.openhab.binding.mycroft/src/main/java/org/openhab/binding/mycroft/internal/channels/VolumeChannel.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.mycroft/src/test/java/org/openhab/binding/mycroft/internal/api/MycroftConnectionTest.java b/bundles/org.openhab.binding.mycroft/src/test/java/org/openhab/binding/mycroft/internal/api/MycroftConnectionTest.java index b1bca2f524d7c..23d3ec052a8fe 100644 --- a/bundles/org.openhab.binding.mycroft/src/test/java/org/openhab/binding/mycroft/internal/api/MycroftConnectionTest.java +++ b/bundles/org.openhab.binding.mycroft/src/test/java/org/openhab/binding/mycroft/internal/api/MycroftConnectionTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2021 Contributors to the openHAB project + * Copyright (c) 2010-2022 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. From facd7be56e4317fb093f2a97ab13ae61beae4b16 Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Sun, 9 Jan 2022 18:53:12 +0100 Subject: [PATCH 39/39] Reactivation of the Mycroft volume channel Signed-off-by: Gwendal Roulleau --- bundles/org.openhab.binding.mycroft/README.md | 3 +++ .../src/main/resources/OH-INF/thing/thing-types.xml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.mycroft/README.md b/bundles/org.openhab.binding.mycroft/README.md index 62c4dfc5987d7..5ad2007c9c2cd 100644 --- a/bundles/org.openhab.binding.mycroft/README.md +++ b/bundles/org.openhab.binding.mycroft/README.md @@ -56,6 +56,7 @@ A Mycroft thing has the following channels: | utterance | String | The last utterance Mycroft receive | | player | Player | The music player Mycroft is currently controlling | | volume_mute | Switch | Mute the Mycroft speaker | +| volume | Dimmer | The volume of the Mycroft speaker. (Note : Value unreliable until a volume change occured) | | full_message | String | The last message (full json) seen on the Mycroft Bus. Filtered by the messageTypes properties | @@ -85,6 +86,7 @@ The `mycroft.item` file: ```java Switch myMycroft_mute "Mute" { channel="mycroft:mycroft:myMycroft:volume_mute" } +Dimmer myMycroft_volume "Volume [%d]" { channel="mycroft:mycroft:myMycroft:volume" } Player myMycroft_player "Control" { channel="mycroft:mycroft:myMycroft:player" } Switch myMycroft_listen "Wake and listen" { channel="mycroft:mycroft:myMycroft:listen" } String myMycroft_speak "Speak STT" { channel="mycroft:mycroft:myMycroft:speak" } @@ -101,6 +103,7 @@ sitemap demo label="myMycroft" { Frame label="myMycroft" { Switch item=myMycroft_mute + Slider item=myMycroft_volume Default item=myMycroft_player Switch item=myMycroft_listen Text item=myMycroft_speak diff --git a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml index 26e384f46647c..0f9106a6310dd 100644 --- a/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.mycroft/src/main/resources/OH-INF/thing/thing-types.xml @@ -13,7 +13,7 @@ - +