SqueezeBox speak

Here: https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.squeezebox/src/main/java/org/openhab/binding/squeezebox/handler/SqueezeBoxServerHandler.java#L537

Look for messageType.equals(“mixer”), or “mixer”.equals(messageType), then a handleMixerMessage method that looks for the volume.

WDYT?

I´ll give it a go; do you mind if I change the statement there to a switch

Not at all.

That seems to do the trick :slight_smile: … shall I create a PR with this small change, so that you can have a look?

Excellent!

Or you can just post the code snippet and I’ll build it here locally. May not get to it for a couple hours though…

It’ll be good to get some runtime with it. I’ve found there are often unintended side-effects when dealing with the LMS…

From 922f02da7df2b5870537ffa311be70411610c688 Mon Sep 17 00:00:00 2001
From: Patrik Gfeller <patrik.gfeller@gmail.com>
Date: Mon, 25 Dec 2017 17:11:33 +0100
Subject: [PATCH] [Squeezebox] Timeout for TTS messages increased; support for
 mixer volume message added

Signed-off-by: Patrik Gfeller <patrik.gfeller@gmail.com>
---
 .../handler/SqueezeBoxPlayerHandler.java           |  3 +-
 .../handler/SqueezeBoxServerHandler.java           | 61 ++++++++++++++++------
 2 files changed, 47 insertions(+), 17 deletions(-)

diff --git a/addons/binding/org.openhab.binding.squeezebox/src/main/java/org/openhab/binding/squeezebox/handler/SqueezeBoxPlayerHandler.java b/addons/binding/org.openhab.binding.squeezebox/src/main/java/org/openhab/binding/squeezebox/handler/SqueezeBoxPlayerHandler.java
index 3f39f4218..2b743b3c1 100644
--- a/addons/binding/org.openhab.binding.squeezebox/src/main/java/org/openhab/binding/squeezebox/handler/SqueezeBoxPlayerHandler.java
+++ b/addons/binding/org.openhab.binding.squeezebox/src/main/java/org/openhab/binding/squeezebox/handler/SqueezeBoxPlayerHandler.java
@@ -52,6 +52,7 @@ import org.slf4j.LoggerFactory;
  * @author Mark Hilbush - Improved handling of player status, prevent REFRESH from causing exception
  * @author Mark Hilbush - Implement AudioSink and notifications
  * @author Mark Hilbush - Added duration channel
+ * @author Patrik Gfeller - Timeout for TTS messages increased from 30 to 90s.
  */
 public class SqueezeBoxPlayerHandler extends BaseThingHandler implements SqueezeBoxPlayerEventListener {
 
@@ -720,7 +721,7 @@ public class SqueezeBoxPlayerHandler extends BaseThingHandler implements Squeeze
      * Monitor the status of the notification so that we know when it has finished playing
      */
     private boolean waitForNotification() {
-        final int timeoutMaxCount = 300;
+        final int timeoutMaxCount = 900;
 
         SqueezeBoxNotificationListener listener = new SqueezeBoxNotificationListener(mac);
         squeezeBoxServerHandler.registerSqueezeBoxPlayerListener(listener);
diff --git a/addons/binding/org.openhab.binding.squeezebox/src/main/java/org/openhab/binding/squeezebox/handler/SqueezeBoxServerHandler.java b/addons/binding/org.openhab.binding.squeezebox/src/main/java/org/openhab/binding/squeezebox/handler/SqueezeBoxServerHandler.java
index 2a0618720..ffc340470 100644
--- a/addons/binding/org.openhab.binding.squeezebox/src/main/java/org/openhab/binding/squeezebox/handler/SqueezeBoxServerHandler.java
+++ b/addons/binding/org.openhab.binding.squeezebox/src/main/java/org/openhab/binding/squeezebox/handler/SqueezeBoxServerHandler.java
@@ -56,6 +56,7 @@ import org.slf4j.LoggerFactory;
  * @author Mark Hilbush - Added duration channel
  * @author Mark Hilbush - Added login/password authentication for LMS
  * @author Philippe Siem - Improve refresh of cover art url,remote title, artist, album, genre, year.
+ * @author Patrik Gfeller - Support for mixer volume message added
  */
 public class SqueezeBoxServerHandler extends BaseBridgeHandler {
     private Logger logger = LoggerFactory.getLogger(SqueezeBoxServerHandler.class);
@@ -527,23 +528,31 @@ public class SqueezeBoxServerHandler extends BaseBridgeHandler {
 
             // get the message type
             String messageType = messageParts[1];
+            switch (messageType) {
+                case "status":
+                    handleStatusMessage(mac, messageParts);
+                    break;
+                case "playlist":
+                    handlePlaylistMessage(mac, messageParts);
+                    break;
+                case "prefset":
+                    handlePrefsetMessage(mac, messageParts);
+                    break;
+                case "mixer":
+                    handleMixerMessage(mac, messageParts);
+                    break;
+                case "ir":
+                    final String ircode = messageParts[2];
+                    updatePlayer(new PlayerUpdateEvent() {
+                        @Override
+                        public void updateListener(SqueezeBoxPlayerEventListener listener) {
+                            listener.irCodeChangeEvent(mac, ircode);
+                        }
+                    });
+                    break;
+                default:
+                    logger.trace("Unhandled player update message type '{}'.", messageType);
 
-            if (messageType.equals("status")) {
-                handleStatusMessage(mac, messageParts);
-            } else if (messageType.equals("playlist")) {
-                handlePlaylistMessage(mac, messageParts);
-            } else if (messageType.equals("prefset")) {
-                handlePrefsetMessage(mac, messageParts);
-            } else if (messageType.equals("ir")) {
-                final String ircode = messageParts[2];
-                updatePlayer(new PlayerUpdateEvent() {
-                    @Override
-                    public void updateListener(SqueezeBoxPlayerEventListener listener) {
-                        listener.irCodeChangeEvent(mac, ircode);
-                    }
-                });
-            } else {
-                logger.trace("Unhandled player update message type '{}'.", messageType);
             }
         }
 
@@ -572,6 +581,26 @@ public class SqueezeBoxServerHandler extends BaseBridgeHandler {
             return fetchUrl(null, mac);
         }
 
+        private void handleMixerMessage(String mac, String[] messageParts) {
+            String action = messageParts[2];
+
+            switch (action) {
+                case "volume":
+                    String value = messageParts[3];
+                    updatePlayer(new PlayerUpdateEvent() {
+                        @Override
+                        public void updateListener(SqueezeBoxPlayerEventListener listener) {
+                            listener.volumeChangeEvent(mac, Integer.parseInt(value));
+                        }
+                    });
+                    break;
+                default:
+                    logger.trace("Unhandled mixer message type '{}'", Arrays.toString(messageParts));
+
+            }
+
+        }
+
         private void handleStatusMessage(final String mac, String[] messageParts) {
             String remoteTitle = "", artist = "", album = "", genre = "", year = "";
             String url = fetchUrl(mac);
-- 
2.14.1.windows.1


@patrik_gfeller Did this resolve all the timeouts you were having, or just the volume set timeouts?

@mhilbush
At the moment this seems to work fine :slight_smile: … just had to increase the message length to 90s; as my morning greeting (with weather and calendar summary takes a while).

Just compiled and installed. Working well so far. :crossed_fingers:

@mhilbush

Hi Mark,

as the file “SqueezeBoxPlayerHandler.java” is quite large I would like to do some refacturing; namely to move the “SqueezeBoxPlayerState” class into a separate file and to create a “SqueezeBoxNotificationPlayer” class to handle the notification play logic. Would that be ok with you?

Also let me know if I shall create a PR for the first change with the mixer volume handling.

with kind regards,
Patrik

Sure thing. That reorganization will help maintenance in the future. Would your refactoring also include a fix for the issue where the listener was being registered after the command was sent to the LMS?

FYI, note that as of this morning, there’s an open PR that touches SqueezeBoxPlayerHandler.
https://github.com/openhab/openhab2-addons/pull/3035

Yes, I think this would be a good fix to get in right away, as it solves a problem that will impact anyone with more than a couple players.

Yep :slight_smile:; I´ll also create a WIP PR for the refactoring; then you can see what I do and provide feedback if you do not agree with changes.

My PR has been merged. Happy refactoring. :wink: