From 9722272a2af239cf8e4a7d85ef0d3f1b0a00da17 Mon Sep 17 00:00:00 2001 From: mlobstein Date: Sat, 13 Jul 2024 02:46:13 -0500 Subject: [PATCH] Fix display of album art for streaming media (#17044) Signed-off-by: Michael Lobstein --- .../communication/NuvoDefaultConnector.java | 41 ------------------- .../communication/NuvoIpConnector.java | 9 ++++ .../nuvo/internal/handler/NuvoHandler.java | 33 +++++++-------- 3 files changed, 24 insertions(+), 59 deletions(-) delete mode 100644 bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/communication/NuvoDefaultConnector.java diff --git a/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/communication/NuvoDefaultConnector.java b/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/communication/NuvoDefaultConnector.java deleted file mode 100644 index bd01e4cc8cd5a..0000000000000 --- a/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/communication/NuvoDefaultConnector.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright (c) 2010-2024 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.nuvo.internal.communication; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.openhab.binding.nuvo.internal.NuvoException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Class to create a default NuvoDefaultConnector before initialization is complete. - * - * @author Laurent Garnier - Initial contribution - * @author Michael Lobstein - Adapted for the Nuvo binding - */ -@NonNullByDefault -public class NuvoDefaultConnector extends NuvoConnector { - - private final Logger logger = LoggerFactory.getLogger(NuvoDefaultConnector.class); - - @Override - public void open() throws NuvoException { - logger.warn("Nuvo binding incorrectly configured. Please configure for Serial or IP over serial connection"); - setConnected(false); - } - - @Override - public void close() { - setConnected(false); - } -} diff --git a/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/communication/NuvoIpConnector.java b/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/communication/NuvoIpConnector.java index d96d1b7d7535e..194c56e5d2654 100644 --- a/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/communication/NuvoIpConnector.java +++ b/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/communication/NuvoIpConnector.java @@ -55,6 +55,15 @@ public NuvoIpConnector(@Nullable String address, int port, String uid) { this.uid = uid; } + /** + * Default constructor for temporary connector object that gets replaced during initialize() + */ + public NuvoIpConnector() { + this.address = ""; + this.port = -1; + this.uid = ""; + } + @Override public synchronized void open() throws NuvoException { logger.debug("Opening IP connection on IP {} port {}", this.address, this.port); diff --git a/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/handler/NuvoHandler.java b/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/handler/NuvoHandler.java index 413418dbd34a9..a7b0060935571 100644 --- a/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/handler/NuvoHandler.java +++ b/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/handler/NuvoHandler.java @@ -55,7 +55,6 @@ import org.openhab.binding.nuvo.internal.NuvoThingActions; import org.openhab.binding.nuvo.internal.communication.NuvoCommand; import org.openhab.binding.nuvo.internal.communication.NuvoConnector; -import org.openhab.binding.nuvo.internal.communication.NuvoDefaultConnector; import org.openhab.binding.nuvo.internal.communication.NuvoEnum; import org.openhab.binding.nuvo.internal.communication.NuvoImageResizer; import org.openhab.binding.nuvo.internal.communication.NuvoIpConnector; @@ -150,7 +149,7 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis private @Nullable ScheduledFuture clockSyncJob; private @Nullable ScheduledFuture pingJob; - private NuvoConnector connector = new NuvoDefaultConnector(); + private NuvoConnector connector = new NuvoIpConnector(); private long lastEventReceived = System.currentTimeMillis(); private int numZones = 1; private String versionString = BLANK; @@ -241,10 +240,7 @@ public void initialize() { nuvoNetSrcMap.put(NuvoEnum.SOURCE5, config.nuvoNetSrc5); nuvoNetSrcMap.put(NuvoEnum.SOURCE6, config.nuvoNetSrc6); - nuvoGroupMap.put("1", new HashSet<>()); - nuvoGroupMap.put("2", new HashSet<>()); - nuvoGroupMap.put("3", new HashSet<>()); - nuvoGroupMap.put("4", new HashSet<>()); + IntStream.range(1, 5).forEach(i -> nuvoGroupMap.put(String.valueOf(i), new HashSet<>())); if (this.isMps4) { logger.debug("Port set to {} configuring binding for MPS4 compatability", MPS4_PORT); @@ -305,13 +301,13 @@ public void initialize() { this.numZones = numZones; } - activeZones = IntStream.range((1), (this.numZones + 1)).boxed().collect(Collectors.toSet()); + activeZones = IntStream.range(1, this.numZones + 1).boxed().collect(Collectors.toSet()); // remove the channels for the zones we are not using if (this.numZones < MAX_ZONES) { List channels = new ArrayList<>(this.getThing().getChannels()); - List zonesToRemove = IntStream.range((this.numZones + 1), (MAX_ZONES + 1)).boxed() + List zonesToRemove = IntStream.range(this.numZones + 1, MAX_ZONES + 1).boxed() .collect(Collectors.toList()); zonesToRemove.forEach(zone -> channels.removeIf(c -> (c.getUID().getId().contains("zone" + zone)))); @@ -321,25 +317,25 @@ public void initialize() { // Build a list of State options for the global favorites using user config values (if supplied) String[] favoritesArr = !config.favoriteLabels.isEmpty() ? config.favoriteLabels.split(COMMA) : new String[0]; List favoriteLabelsStateOptions = new ArrayList<>(); - for (int i = 0; i < MAX_FAV; i++) { - if (favoritesArr.length > i) { - favoriteLabelsStateOptions.add(new StateOption(String.valueOf(i + 1), favoritesArr[i])); + IntStream.range(1, MAX_FAV + 1).forEach(i -> { + if (favoritesArr.length >= i) { + favoriteLabelsStateOptions.add(new StateOption(String.valueOf(i), favoritesArr[i - 1])); } else if (favoritesArr.length == 0) { - favoriteLabelsStateOptions.add(new StateOption(String.valueOf(i + 1), "Favorite " + (i + 1))); + favoriteLabelsStateOptions.add(new StateOption(String.valueOf(i), "Favorite " + (i))); } - } + }); // Also add any openHAB NuvoNet source favorites to the list - for (int src = 1; src <= MAX_SRC; src++) { + IntStream.range(1, MAX_SRC + 1).forEach(src -> { NuvoEnum source = NuvoEnum.valueOf(SOURCE + src); String[] favorites = favoriteMap.get(source); if (favorites != null) { - for (int fav = 0; fav < favorites.length; fav++) { + IntStream.range(0, favorites.length).forEach(fav -> { favoriteLabelsStateOptions.add(new StateOption(String.valueOf(src * 100 + fav), favPrefixMap.get(source) + favorites[fav])); - } + }); } - } + }); // Put the global favorites labels on all active zones activeZones.forEach(zoneNum -> { @@ -1531,7 +1527,8 @@ private void getMps4AlbumArt(NuvoEnum source) { logger.debug("Using MCS instance '{}' for source {}", instance, source); final String json = getMcsJson(String.format(GET_MCS_STATUS, mps4Host, instance, clientId), clientId); - if (json.contains("\"name\":\"PlayState\",\"value\":3}")) { + if (json.contains("\"name\":\"PlayState\",\"value\":1}") + || json.contains("\"name\":\"PlayState\",\"value\":3}")) { Matcher matcher = ART_GUID_PATTERN.matcher(json); if (matcher.find()) { final String nowPlayingGuid = matcher.group(1);