Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/bugfixes and tweaks #10

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public class ZoneCommandDispatcher implements IZoneCommandDispatcher {
/** The Constant INSTANCE. */
private static final ZoneCommandDispatcher INSTANCE = new ZoneCommandDispatcher();

private ZoneCommandDispatcher()
{

}

/**
* Gets the single instance of ZoneCommandDispatcher.
*
Expand Down Expand Up @@ -145,6 +150,7 @@ public ZoneCommandExecutor registerZoneExecutor(final String zoneName) {
ZoneCommandExecutor executor;
synchronized (executors) {
if (!executors.containsKey(zoneNameUppercase)) {
LOGGER.info("new ZoneCommandExecutor thread spawned: " + zoneNameUppercase);
executor = new ZoneCommandExecutor(zoneNameUppercase);
executor.start();
executors.put(zoneNameUppercase, executor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public static Service findService(final RemoteDevice device, final String servic
* the type
*/
public AbstractService(final UpnpService upnpService, final Service service, final String type) {
if (!service.getServiceType().toString().equals(type)) {
if (service != null && !service.getServiceType().toString().equals(type)) {
throw new IllegalArgumentException("service must be " + type + ", not " + service.getServiceType());
}

Expand Down
10 changes: 10 additions & 0 deletions sonos-java/src/main/java/org/tensin/sonos/control/ZonePlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.net.UnknownHostException;

import org.teleal.cling.UpnpService;
import org.teleal.cling.model.meta.Device;
import org.teleal.cling.model.meta.RemoteDevice;
import org.tensin.sonos.SonosException;
import org.tensin.sonos.model.Entry;
Expand Down Expand Up @@ -325,4 +326,13 @@ public void playQueueEntry(final int index) throws SonosException {
serv.play();
}
}

@Override
public String toString() {

return String.format("%s ZonePlayer[%s, ip = %s]",
dev.getDetails().getModelDetails().getModelNumber(),
dev.getDisplayString(),
ip);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.tensin.sonos.helpers;

import org.teleal.cling.model.meta.Action;
import org.teleal.cling.model.meta.Device;
import org.teleal.cling.model.meta.RemoteDevice;
import org.teleal.cling.model.meta.Service;
import org.teleal.cling.model.types.ServiceType;
Expand All @@ -19,6 +20,9 @@ public class RemoteDeviceHelper {
* @return the string
*/
public static String dumpRemoteDevice(final RemoteDevice device) {
return dumpDevice(device);
}
public static String dumpDevice(final Device device) {
final StringBuilder sb = new StringBuilder();
sb.append(device.toString()).append(SonosConstants.NEWLINE);

Expand All @@ -38,18 +42,24 @@ public static String dumpRemoteDevice(final RemoteDevice device) {
sb.append(" Model Number [").append(device.getDetails().getModelDetails().getModelNumber()).append("]").append(SonosConstants.NEWLINE);
sb.append(" Model URI [").append(device.getDetails().getModelDetails().getModelURI()).append("]").append(SonosConstants.NEWLINE);

sb.append(" Identity :").append(SonosConstants.NEWLINE);
sb.append(" UDN [").append(device.getIdentity().getUdn()).append("]").append(SonosConstants.NEWLINE);
sb.append(" Descriptor URL [").append(device.getIdentity().getDescriptorURL()).append("]").append(SonosConstants.NEWLINE);
sb.append(" Discovered on local address [").append(device.getIdentity().getDiscoveredOnLocalAddress()).append("]").append(SonosConstants.NEWLINE);
sb.append(" Interface MAC addresss [").append(device.getIdentity().getInterfaceMacAddress()).append("]").append(SonosConstants.NEWLINE);
sb.append(" Max age (seconds) [").append(device.getIdentity().getMaxAgeSeconds()).append("]").append(SonosConstants.NEWLINE);
sb.append(" WoL bytes [").append(device.getIdentity().getWakeOnLANBytes()).append("]").append(SonosConstants.NEWLINE);

if(device instanceof RemoteDevice){
RemoteDevice rdevice = (RemoteDevice)device;
sb.append(" Identity :").append(SonosConstants.NEWLINE);
sb.append(" UDN [").append(device.getIdentity().getUdn()).append("]").append(SonosConstants.NEWLINE);
sb.append(" Descriptor URL [").append(rdevice.getIdentity().getDescriptorURL()).append("]").append(SonosConstants.NEWLINE);
sb.append(" Discovered on local address [").append(rdevice.getIdentity().getDiscoveredOnLocalAddress()).append("]").append(SonosConstants.NEWLINE);
sb.append(" Interface MAC addresss [").append(rdevice.getIdentity().getInterfaceMacAddress()).append("]").append(SonosConstants.NEWLINE);
sb.append(" Max age (seconds) [").append(rdevice.getIdentity().getMaxAgeSeconds()).append("]").append(SonosConstants.NEWLINE);
sb.append(" WoL bytes [").append(rdevice.getIdentity().getWakeOnLANBytes()).append("]").append(SonosConstants.NEWLINE);
}else{
sb.append(" Identity :").append(SonosConstants.NEWLINE);
sb.append(" UDN [").append(device.getIdentity().getUdn()).append("]").append(SonosConstants.NEWLINE);
sb.append(" Max age (seconds) [").append(device.getIdentity().getMaxAgeSeconds()).append("]").append(SonosConstants.NEWLINE);
}
sb.append(" Identity [").append(device.getVersion().toString()).append("]").append(SonosConstants.NEWLINE);

sb.append(" Embedded devices :").append(SonosConstants.NEWLINE);
for (final RemoteDevice remoteDevice : device.findEmbeddedDevices()) {
for (final Device remoteDevice : device.findEmbeddedDevices()) {
sb.append(" - ").append(remoteDevice.toString()).append(SonosConstants.NEWLINE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ public ZonePlayerModel() {

}

/**
* Checks if is zone player already defined.
*
* @param UDN
* the udn
* @return true, if is zone player already defined
*/
public boolean containsZonePlayer(final String UDN) {
ZonePlayer other = null;
for (final ZonePlayer zone : getAllZones()) {
if (zone.getRootDevice().getIdentity().getUdn().getIdentifierString().equals(UDN)) {
other = zone;
break;
}
}
return (other != null);
}

/**
* Adds the given zone player to the list in a sorted order.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
/**
* The Class CLITestCase.
*/
public class CLITestCase {
public class ClientIT {

/** The zone command dispatcher. */
private final ZoneCommandDispatcher zoneCommandDispatcher = ZoneCommandDispatcher.getInstance();

private static final String TEST_ROOM_ONE = "salon";
private static final String TEST_ROOM_TWO = "chambre";
/**
* Sets the up.
*/
Expand Down Expand Up @@ -82,7 +84,7 @@ public void testDummyCommand() throws SonosException {
*/
@Test
public void testList() throws SonosException {
CLIController.main(new String[] { "--command", "list", "A:", "--zone", "salon" });
CLIController.main(new String[] { "--command", "list", "A:", "--zone", TEST_ROOM_ONE});
}

/**
Expand All @@ -93,13 +95,13 @@ public void testList() throws SonosException {
*/
@Test
public void testMute() throws SonosException {
CLIController.main(new String[] { "--command", "mute", "--zone", "salon" });
CLIController.main(new String[] { "--command", "mute", "--zone",TEST_ROOM_ONE });

ZoneCommandExecutor executor = zoneCommandDispatcher.getZoneCommandExecutor("SALON");
ZoneCommandExecutor executor = zoneCommandDispatcher.getZoneCommandExecutor(TEST_ROOM_ONE.toUpperCase());
Assert.assertTrue(executor != null);
Assert.assertEquals(1, executor.getExecutedCommandsCount());

executor = zoneCommandDispatcher.getZoneCommandExecutor("CHAMBRE");
executor = zoneCommandDispatcher.getZoneCommandExecutor(TEST_ROOM_TWO.toUpperCase());
Assert.assertTrue(executor != null);
Assert.assertEquals(0, executor.getExecutedCommandsCount());
}
Expand All @@ -112,7 +114,7 @@ public void testMute() throws SonosException {
*/
@Test
public void testNext() throws SonosException {
CLIController.main(new String[] { "--command", "next", "--zone", "chambre" });
CLIController.main(new String[] { "--command", "next", "--zone", TEST_ROOM_TWO });
}

/**
Expand All @@ -134,7 +136,7 @@ public void testPause() throws SonosException {
*/
@Test
public void testPlay() throws SonosException {
CLIController.main(new String[] { "--command", "play", "--zone", "salon" });
CLIController.main(new String[] { "--command", "play", "--zone", TEST_ROOM_ONE });
}

/**
Expand Down Expand Up @@ -182,7 +184,7 @@ public void testUnknownZone() throws SonosException {
*/
@Test
public void testUnmute() throws SonosException {
CLIController.main(new String[] { "--command", "unmute", "--zone", "salon" });
CLIController.main(new String[] { "--command", "unmute", "--zone", TEST_ROOM_ONE });
}

/**
Expand All @@ -204,7 +206,7 @@ public void testUsage() throws SonosException {
*/
@Test
public void testVolume() throws SonosException {
CLIController.main(new String[] { "--command", "volume", "--zone", "chambre" });
CLIController.main(new String[] { "--command", "volume", "--zone", TEST_ROOM_TWO });
}

/**
Expand All @@ -215,7 +217,7 @@ public void testVolume() throws SonosException {
*/
@Test
public void testVolumeDown() throws SonosException {
CLIController.main(new String[] { "--command", "down", "--zone", "chambre" });
CLIController.main(new String[] { "--command", "down", "--zone", TEST_ROOM_TWO });
}

/**
Expand All @@ -226,7 +228,7 @@ public void testVolumeDown() throws SonosException {
*/
@Test
public void testVolumeSet() throws SonosException {
CLIController.main(new String[] { "--command", "volume", "25", "--zone", "chambre" });
CLIController.main(new String[] { "--command", "volume", "25", "--zone", TEST_ROOM_TWO });
}

/**
Expand All @@ -237,7 +239,7 @@ public void testVolumeSet() throws SonosException {
*/
@Test
public void testVolumeUp() throws SonosException {
CLIController.main(new String[] { "--command", "up", "--zone", "chambre" });
CLIController.main(new String[] { "--command", "up", "--zone", TEST_ROOM_TWO });
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* The Class ClingTestCase.
*/
public class ClingTestCase {
public class ClingIT {

/**
* Test discovery.
Expand Down
14 changes: 13 additions & 1 deletion sonos-root/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,19 @@
<includeScope>compile</includeScope>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12.4</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public class SonosState implements ISonosState {

/** The zone command dispatcher. */
private final ZoneCommandDispatcher zoneCommandDispatcher = new ZoneCommandDispatcher();
private final ZoneCommandDispatcher zoneCommandDispatcher = ZoneCommandDispatcher.getInstance();

/** The Constant LOGGER. */
private static final Logger LOGGER = LoggerFactory.getLogger(SonosState.class);
Expand Down