Skip to content

Commit

Permalink
Merge pull request openhab#141 from kgoderis/sonos
Browse files Browse the repository at this point in the history
Sonos : implementation of new commands
  • Loading branch information
kaikreuzer committed Feb 21, 2015
2 parents 232b275 + 491f7f2 commit df79093
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<channel id="mute" typeId="mute" />
<channel id="playlinein" typeId="playlinein" />
<channel id="playlist" typeId="playlist" />
<channel id="playqueue" typeId="playqueue" />
<channel id="playtrack" typeId="playtrack" />
<channel id="playuri" typeId="playuri" />
<channel id="publicaddress" typeId="publicaddress" />
<channel id="radio" typeId="radio" />
Expand Down Expand Up @@ -150,6 +152,18 @@
<description>Play the given playlist. The playlist has to predefined in the Sonos Controller app</description>
</channel-type>

<channel-type id="playqueue" advanced="true">
<item-type>Switch</item-type>
<label>Play Queue</label>
<description>Play the songs from the current queue</description>
</channel-type>

<channel-type id="playtrack" advanced="true">
<item-type>Number</item-type>
<label>Play Track</label>
<description>Play the given track number from the current queue</description>
</channel-type>

<channel-type id="playuri" advanced="true">
<item-type>String</item-type>
<label>Play URI</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class SonosBindingConstants {
public final static String MUTE = "mute";
public final static String PLAYLINEIN = "playlinein";
public final static String PLAYLIST = "playlist";
public final static String PLAYQUEUE = "playqueue";
public final static String PLAYTRACK = "playtrack";
public final static String PLAYURI = "playuri";
public final static String PUBLICADDRESS = "publicaddress";
public final static String RADIO = "radio";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ public void handleCommand(ChannelUID channelUID, Command command) {
case PLAYLIST:
playPlayList(command);
break;
case PLAYQUEUE:
playQueue(command);
break;
case PLAYTRACK:
playTrack(command);
break;
case PLAYURI:
playURI(command);
break;
Expand Down Expand Up @@ -653,7 +659,7 @@ protected void updateCurrentURIFormatted(String URI) {
// currentURI = getCurrentURI();
currentTrack = getTrackMetadata();
}

if (currentURI != null) {
String title = stateMap.get("CurrentTitle");
String resultString = stateMap.get("CurrentURIFormatted");
Expand Down Expand Up @@ -1204,6 +1210,10 @@ public void setPosition(String relTime) {
public void setPositionTrack(long tracknr) {
seek("TRACK_NR", Long.toString(tracknr));
}

public void setPositionTrack(String tracknr) {
seek("TRACK_NR", tracknr);
}

protected void seek(String unit, String target) {
if (unit != null && target != null) {
Expand Down Expand Up @@ -1639,6 +1649,19 @@ public void playURI(Command command) {

}

public void playQueue(Command command) {
ZonePlayerHandler coordinator = getHandlerByName(getCoordinator());

// set the current playlist to our new queue
coordinator.setCurrentURI("x-rincon-queue:" + getUDN() + "#0", "");

// take the system off mute
coordinator.setMute(OnOffType.OFF);

// start jammin'
coordinator.play();
}

public void setLed(Command command) {
if (command != null) {
if (command instanceof OnOffType
Expand Down Expand Up @@ -1723,6 +1746,25 @@ public void playRadio(Command command) {

}

public void playTrack(Command command) {

if(command != null && command instanceof DecimalType) {
ZonePlayerHandler coordinator = getHandlerByName(getCoordinator());

String trackNumber = command.toString();

// seek the track - warning, we do not check if the tracknumber falls in the boundary of the queue
setPositionTrack(trackNumber);

// take the system off mute
coordinator.setMute(OnOffType.OFF);

// start jammin'
coordinator.play();
}

}

public void playPlayList(Command command) {
List<SonosEntry> playlists = getPlayLists();
SonosEntry theEntry = null;
Expand Down

0 comments on commit df79093

Please sign in to comment.