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

Fixes for Issues 30, 34, and 35 #41

Merged
merged 3 commits into from
Nov 14, 2014
Merged
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 @@ -117,7 +117,7 @@ public ZonePlayerHandler(Thing thing, UpnpIOService upnpIOService,
DiscoveryServiceRegistry discoveryServiceRegistry, String opmlPartnerID) {
super(thing);
this.opmlPartnerID = opmlPartnerID;

logger.debug("Creating a ZonePlayerHandler for thing '{}'", getThing()
.getUID());
if (upnpIOService != null) {
Expand All @@ -127,11 +127,7 @@ public ZonePlayerHandler(Thing thing, UpnpIOService upnpIOService,
this.discoveryServiceRegistry = discoveryServiceRegistry;
this.discoveryServiceRegistry.addDiscoveryListener(this);
}
if (!service.isRegistered(this)) {
logger.debug("Setting status for thing '{}' to OFFLINE", getThing()
.getUID());
getThing().setStatus(ThingStatus.OFFLINE);
}

}

@Override
Expand All @@ -142,6 +138,12 @@ public void dispose() {
pollingJob.cancel(true);
pollingJob = null;
}

if (getThing().getStatus() == ThingStatus.ONLINE) {
logger.debug("Setting status for thing '{}' to OFFLINE", getThing()
.getUID());
getThing().setStatus(ThingStatus.OFFLINE);
}
}

@Override
Expand All @@ -155,6 +157,12 @@ public void initialize() {
} else {
logger.warn("Cannot initalize the zoneplayer. UDN not set.");
}

if (getThing().getStatus() == ThingStatus.OFFLINE) {
logger.debug("Setting status for thing '{}' to ONLINE", getThing()
.getUID());
getThing().setStatus(ThingStatus.ONLINE);
}
}

@Override
Expand Down Expand Up @@ -573,18 +581,15 @@ public boolean isCoordinator() {
protected void updateCurrentURIFormatted() {

String currentURI = null;
SonosMetaData currentURIMetaData = null;
SonosMetaData currentTrack = null;
String coordinator = getCoordinator();
ZonePlayerHandler coordinatorHandler = getHandlerByName(coordinator);

if (!isGroupCoordinator() && coordinatorHandler != null) {
currentURI = coordinatorHandler.getCurrentURI();
currentURIMetaData = coordinatorHandler.getCurrentURIMetadata();
currentTrack = coordinatorHandler.getTrackMetadata();
} else {
currentURI = getCurrentURI();
currentURIMetaData = getCurrentURIMetadata();
currentTrack = getTrackMetadata();
}

Expand Down Expand Up @@ -628,13 +633,13 @@ protected void updateCurrentURIFormatted() {
if(response != null) {
List<String> fields = SonosXMLParser
.getRadioTimeFromXML(response);

if (fields != null) {

resultString = new String();
// radio name should be first field
title = fields.get(0);

Iterator<String> listIterator = fields.listIterator();
while (listIterator.hasNext()) {
String field = listIterator.next();
Expand Down Expand Up @@ -1263,7 +1268,11 @@ protected ZonePlayerHandler getHandlerByName(String remotePlayerName) {
}
}

return (ZonePlayerHandler) thing.getHandler();
if(thing != null) {
return (ZonePlayerHandler) thing.getHandler();
} else {
return null;
}

}

Expand Down