Skip to content

Commit

Permalink
Combine like/unlike to single rate channel
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Hilbush <mark@hilbush.com>
  • Loading branch information
mhilbush committed Jun 18, 2020
1 parent c594778 commit d0587d5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 31 deletions.
11 changes: 9 additions & 2 deletions bundles/org.openhab.binding.squeezebox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ All devices support some of the following channels:
| ircode | String | Received IR code |
| numberPlaylistTracks | Number | Number of playlist tracks |
| playFavorite | String | ID of Favorite to play (channel's state options contains available favorites) |
| like | Switch | "Like" the currently playing song (if supported by the streaming service) |
| unlike | Switch | "Unlike" the currently playing song (if supported by the streaming service) |
| rate | Switch | "Like" or "unlike" the currently playing song (if supported by the streaming service) |

## Playing Favorites

Expand Down Expand Up @@ -199,6 +198,14 @@ then
end
```

## Rating Songs

Some streaming services, such as Pandora and Slacker, all songs to be rated.
When playing from these streaming services, sending commands to the `rate` channel can be used to *like* or *unlike* the currently playing song.
Sending the ON command will *like* the song.
Sending the OFF command will *unlike* the song.
If the streaming service doesn't support rating, sending commands to the `rate` channel has no effect.

### Known Issues

- There are some versions of squeezelite that will not correctly play very short duration mp3 files.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,5 @@ public class SqueezeBoxBindingConstants {
public static final String CHANNEL_NAME = "name";
public static final String CHANNEL_MODEL = "model";
public static final String CHANNEL_FAVORITES_PLAY = "playFavorite";
public static final String CHANNEL_LIKE = "like";
public static final String CHANNEL_UNLIKE = "unlike";
public static final String CHANNEL_RATE = "rate";
}
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,11 @@ public void handleCommand(ChannelUID channelUID, Command command) {
case CHANNEL_FAVORITES_PLAY:
squeezeBoxServerHandler.playFavorite(mac, command.toString());
break;
case CHANNEL_LIKE:
if (likeCommand != null && command.equals(OnOffType.ON)) {
squeezeBoxServerHandler.like(mac, likeCommand);
}
break;
case CHANNEL_UNLIKE:
if (unlikeCommand != null && command.equals(OnOffType.ON)) {
squeezeBoxServerHandler.unlike(mac, unlikeCommand);
case CHANNEL_RATE:
if (command.equals(OnOffType.ON)) {
squeezeBoxServerHandler.rate(mac, likeCommand);
} else if (command.equals(OnOffType.OFF)) {
squeezeBoxServerHandler.rate(mac, unlikeCommand);
}
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,10 @@ public void playFavorite(String mac, String favorite) {
sendCommand(mac + " favorites playlist play item_id:" + favorite);
}

public void like(String mac, String command) {
sendCommand(mac + " " + command);
}

public void unlike(String mac, String command) {
sendCommand(mac + " " + command);
public void rate(String mac, String rateCommand) {
if (rateCommand != null) {
sendCommand(mac + " " + rateCommand);
}
}

/**
Expand Down Expand Up @@ -1024,9 +1022,7 @@ private void updateChannelFavoritesList(List<Favorite> favorites) {

private void scheduleRequestFavorites() {
// Delay the execution to give the player thing handlers a chance to initialize
scheduler.schedule(() -> {
requestFavorites();
}, 3L, TimeUnit.SECONDS);
scheduler.schedule(SqueezeBoxServerHandler.this::requestFavorites, 3L, TimeUnit.SECONDS);
}

private void updateCustomButtons(final String mac) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@
<channel id="ircode" typeId="ircode"/>
<channel id="numberPlaylistTracks" typeId="numberPlaylistTracks"/>
<channel id="playFavorite" typeId="playFavorite"/>
<channel id="like" typeId="like"/>
<channel id="unlike" typeId="unlike"/>
<channel id="rate" typeId="rate"/>
</channels>

<properties>
Expand Down Expand Up @@ -300,14 +299,9 @@
<description>Number of playlist tracks</description>
<state readOnly="true" pattern="%d"></state>
</channel-type>
<channel-type id="like" advanced="true">
<channel-type id="rate" advanced="true">
<item-type>Switch</item-type>
<label>Like Song</label>
<description>Likes the current song (if the service supports it)</description>
</channel-type>
<channel-type id="unlike" advanced="true">
<item-type>Switch</item-type>
<label>Unlike Song</label>
<description>Unlikes the current song (if the service supports it)</description>
<label>Like or Unlike Song</label>
<description>Likes or unlikes the current song (if the service supports it)</description>
</channel-type>
</thing:thing-descriptions>

0 comments on commit d0587d5

Please sign in to comment.