Skip to content

Commit

Permalink
Fix Music handling
Browse files Browse the repository at this point in the history
Signed-off-by: Jan N. Klug <github@klug.nrw>
  • Loading branch information
J-N-K committed Oct 28, 2023
1 parent 3be08d7 commit b50ed2b
Show file tree
Hide file tree
Showing 14 changed files with 327 additions and 149 deletions.
6 changes: 6 additions & 0 deletions bundles/org.smarthomej.binding.amazonechocontrol/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
<version>2.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.annotation</artifactId>
<version>2.2.600</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.smarthomej.binding.amazonechocontrol.internal.dto.response;
package org.smarthomej.binding.amazonechocontrol.internal.dto;

import org.eclipse.jdt.annotation.NonNull;

import com.google.gson.annotations.SerializedName;

/**
* The {@link PlayerStateInfoTO} encapsulates the information about a player
*
Expand All @@ -22,18 +24,21 @@
public class PlayerStateInfoTO {
public String queueId;
public String mediaId;
@SerializedName(value = "state", alternate = { "playerState" })
public String state;
public PlayerStateInfoTextTO infoText = new PlayerStateInfoTextTO();
public PlayerStateInfoTextTO miniInfoText = new PlayerStateInfoTextTO();
public PlayerStateProviderTO provider = new PlayerStateProviderTO();
public PlayerStateVolumeTO volume = new PlayerStateVolumeTO();
public PlayerStateMainArtTO mainArt = new PlayerStateMainArtTO();
public PlayerStateProgressTO progress = new PlayerStateProgressTO();
public PlayerStateMediaReferenceTO mediaReference = new PlayerStateMediaReferenceTO();

@Override
public @NonNull String toString() {
return "PlayerStateInfoTO{queueId='" + queueId + "', mediaId='" + mediaId + "', state='" + state
+ "', infoText=" + infoText + ", miniInfoText=" + miniInfoText + ", provider=" + provider + ", volume="
+ volume + ", mainArt=" + mainArt + ", progress=" + progress + "}";
+ volume + ", mainArt=" + mainArt + ", progress=" + progress + ", mediaReference=" + mediaReference
+ "}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.smarthomej.binding.amazonechocontrol.internal.dto.response;
package org.smarthomej.binding.amazonechocontrol.internal.dto;

import org.eclipse.jdt.annotation.NonNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.smarthomej.binding.amazonechocontrol.internal.dto.response;
package org.smarthomej.binding.amazonechocontrol.internal.dto;

import org.eclipse.jdt.annotation.NonNull;

import com.google.gson.annotations.SerializedName;

/**
* The {@link PlayerStateMainArtTO} encapsulates the art section of a player info
*
Expand All @@ -23,6 +25,7 @@ public class PlayerStateMainArtTO {
public String altText;
public String artType;
public String contentType;
@SerializedName(value = "url", alternate = { "fullUrl" })
public String url;

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright (c) 2021-2023 Contributors to the SmartHome/J 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.smarthomej.binding.amazonechocontrol.internal.dto;

import org.eclipse.jdt.annotation.NonNull;

/**
* The {@link PlayerStateMediaReferenceTO} encapsulates the media reference / queue information of a Player info state
*
* @author Jan N. Klug - Initial contribution
*/
public class PlayerStateMediaReferenceTO {
public String namespace;
public String name;
public String value;

@Override
public @NonNull String toString() {
return "MediaReferenceTO{namespace='" + namespace + "', name='" + name + "', value='" + value + "'}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.smarthomej.binding.amazonechocontrol.internal.dto.response;
package org.smarthomej.binding.amazonechocontrol.internal.dto;

import org.eclipse.jdt.annotation.NonNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.smarthomej.binding.amazonechocontrol.internal.dto.response;
package org.smarthomej.binding.amazonechocontrol.internal.dto;

import org.eclipse.jdt.annotation.NonNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.smarthomej.binding.amazonechocontrol.internal.dto.response;
package org.smarthomej.binding.amazonechocontrol.internal.dto;

import org.eclipse.jdt.annotation.NonNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (c) 2021-2023 Contributors to the SmartHome/J 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.smarthomej.binding.amazonechocontrol.internal.dto.push;

import org.eclipse.jdt.annotation.NonNull;

/**
* The {@link NotifyNowPlayingUpdatedOuterUpdateTO} encapsulates the outer update section of NotifyNowPlayingUpdated
* messages
*
* @author Jan N. Klug - Initial contribution
*/
public class NotifyNowPlayingUpdatedOuterUpdateTO {

public String taskSessionId;

public NotifyNowPlayingUpdatedUpdateTO update;

public String type;

@Override
public @NonNull String toString() {
return "NotifyNowPlayingUpdatedOuterUpdateTO{taskSessionId='" + taskSessionId + "', update=" + update
+ ", type='" + type + "'}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (c) 2021-2023 Contributors to the SmartHome/J 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.smarthomej.binding.amazonechocontrol.internal.dto.push;

import org.eclipse.jdt.annotation.NonNull;

/**
* The {@link NotifyNowPlayingUpdatedTO} encapsulates NotifyNowPlayingUpdated messages
*
* @author Jan N. Klug - Initial contribution
*/
public class NotifyNowPlayingUpdatedTO {

public String customerId;

public String name;

public String messageId;

public NotifyNowPlayingUpdatedOuterUpdateTO update;

public boolean fallbackAllowed;

@Override
public @NonNull String toString() {
return "NotifyNowPlayingUpdatedTO{customerId='" + customerId + "', name='" + name + "'" + ", messageId='"
+ messageId + "', update=" + update + ", fallbackAllowed=" + fallbackAllowed + "}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (c) 2021-2023 Contributors to the SmartHome/J 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.smarthomej.binding.amazonechocontrol.internal.dto.push;

import org.eclipse.jdt.annotation.NonNull;
import org.smarthomej.binding.amazonechocontrol.internal.dto.PlayerStateInfoTO;

/**
* The {@link NotifyNowPlayingUpdatedUpdateTO} encapsulates the inner update section of NotifyNowPlayingUpdated messages
*
* @author Jan N. Klug - Initial contribution
*/
public class NotifyNowPlayingUpdatedUpdateTO {
public boolean playbackError;

public String errorMessage;

public String cause;

public String type;

public PlayerStateInfoTO nowPlayingData;

@Override
public @NonNull String toString() {
return "NotifyNowPlayingUpdatedUpdateTO{playbackError=" + playbackError + ", errorMessage='" + errorMessage
+ "', cause='" + cause + "', type='" + type + "', nowPlayingData=" + nowPlayingData + "}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.smarthomej.binding.amazonechocontrol.internal.dto.response;

import org.eclipse.jdt.annotation.NonNull;
import org.smarthomej.binding.amazonechocontrol.internal.dto.PlayerStateInfoTO;

/**
* The {@link PlayerStateTO} encapsulate the response of a request to /api/np/player
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import org.smarthomej.binding.amazonechocontrol.internal.dto.EnabledFeedTO;
import org.smarthomej.binding.amazonechocontrol.internal.dto.NotificationSoundTO;
import org.smarthomej.binding.amazonechocontrol.internal.dto.NotificationTO;
import org.smarthomej.binding.amazonechocontrol.internal.dto.push.NotifyNowPlayingUpdatedTO;
import org.smarthomej.binding.amazonechocontrol.internal.dto.push.PushCommandTO;
import org.smarthomej.binding.amazonechocontrol.internal.dto.push.PushDeviceTO;
import org.smarthomej.binding.amazonechocontrol.internal.dto.push.PushDopplerIdTO;
Expand Down Expand Up @@ -571,6 +572,7 @@ private EnabledFeedTO copyFeed(EnabledFeedTO feed) {
public void onPushCommandReceived(PushCommandTO pushCommand) {
logger.debug("Processing {}", pushCommand);
ScheduledFuture<?> refreshDataDelayed = this.refreshAfterCommandJob;
String payload = pushCommand.payload;
switch (pushCommand.command) {
case "PUSH_ACTIVITY":
// currently unused, seems to be removed, log a warning if it re-appears
Expand All @@ -588,13 +590,13 @@ public void onPushCommandReceived(PushCommandTO pushCommand) {
refreshNotifications();
break;
case "PUSH_AUDIO_PLAYER_STATE":
break;
case "PUSH_MEDIA_QUEUE_CHANGE":
case "PUSH_MEDIA_CHANGE":
case "PUSH_MEDIA_PROGRESS_CHANGE":
case "PUSH_VOLUME_CHANGE":
case "PUSH_CONTENT_FOCUS_CHANGE":
case "PUSH_EQUALIZER_STATE_CHANGE":
String payload = pushCommand.payload;
if (payload.startsWith("{") && payload.endsWith("}")) {
PushDeviceTO devicePayload = Objects.requireNonNull(gson.fromJson(payload, PushDeviceTO.class));
PushDopplerIdTO dopplerId = devicePayload.dopplerId;
Expand All @@ -613,7 +615,12 @@ public void onPushCommandReceived(PushCommandTO pushCommand) {
}
}
break;
case "NotifyMediaSessionsUpdatedTO":
case "NotifyNowPlayingUpdated":
NotifyNowPlayingUpdatedTO update = Objects
.requireNonNull(gson.fromJson(payload, NotifyNowPlayingUpdatedTO.class));
echoHandlers.forEach(e -> e.handleNowPlayingUpdated(update.update.update.nowPlayingData));
break;
case "NotifyMediaSessionsUpdated":
// currently unused
break;
default:
Expand Down
Loading

0 comments on commit b50ed2b

Please sign in to comment.