Fix display of album art for streaming media (#17044)

Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
mlobstein 2024-07-13 02:46:13 -05:00 committed by Ciprian Pascu
parent e5510f66bf
commit c5cfbe15b2
3 changed files with 24 additions and 59 deletions

View File

@ -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);
}
}

View File

@ -55,6 +55,15 @@ public class NuvoIpConnector extends NuvoConnector {
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);

View File

@ -55,7 +55,6 @@ import org.openhab.binding.nuvo.internal.NuvoStateDescriptionOptionProvider;
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 class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis
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 class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis
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<Channel> channels = new ArrayList<>(this.getThing().getChannels());
List<Integer> zonesToRemove = IntStream.range((this.numZones + 1), (MAX_ZONES + 1)).boxed()
List<Integer> 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 class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis
// 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<StateOption> 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 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis
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);