Skip to content

Commit

Permalink
Fix display of album art for streaming media (openhab#17044)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Lobstein <[email protected]>
  • Loading branch information
mlobstein authored and matchews committed Oct 18, 2024
1 parent 9b1ca91 commit 251ec2f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 59 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<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))));
Expand All @@ -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<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 -> {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 251ec2f

Please sign in to comment.