diff --git a/bundles/org.openhab.binding.squeezebox/README.md b/bundles/org.openhab.binding.squeezebox/README.md index 0d374bd4eefe2..539b4f6a58202 100644 --- a/bundles/org.openhab.binding.squeezebox/README.md +++ b/bundles/org.openhab.binding.squeezebox/README.md @@ -94,38 +94,38 @@ The Squeezebox server supports the following channel: All devices support some of the following channels: -| Channel Type ID | Item Type | Description | -| ---------------------- | --------- | -------------------------------------------------------------------------------------------- | -| power | Switch | Power on/off your device | -| mute | Switch | Mute/unmute your device | -| volume | Dimmer | Volume of your device | -| stop | Switch | Stop the current title | -| control | Player | Control the Zone Player, e.g. play/pause/next/previous/ffward/rewind | -| stream | String | Play the given HTTP or file stream (file:// or http://) | -| source | String | Shows the source of the currently playing playlist entry. (i.e. `http://radio.org/radio.mp3` | -| sync | String | Add another player to your device for synchronized playback (other player mac address) | -| playListIndex | Number | Playlist Index | -| currentPlayingTime | Number | Current Playing Time | -| duration | Number | Duration of currently playing track (in seconds) | -| currentPlaylistShuffle | Number | Current playlist shuffle mode (0 No Shuffle, 1 Shuffle Songs, 2 Shuffle Albums) | -| currentPlaylistRepeat | Number | Current playlist repeat Mode (0 No Repeat, 1 Repeat Song, 2 Repeat Playlist) | -| title | String | Title of the current song | -| remotetitle | String | Remote Title (Radio) of the current song | -| album | String | Album name of the current song | -| artist | String | Artist name of the current song | -| year | String | Release year of the current song | -| genre | String | Genre name of the current song | -| albumArtist | String | Main artist of the entire album | -| trackArtist | String | Main artist of the track | -| band | String | Band/orchestra that performed the work | -| composer | String | Original composer of the work | -| conductor | String | Person who conducted the performance | -| coverartdata | Image | Image data of cover art of the current song | -| 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) | -| rate | Switch | "Like" or "unlike" the currently playing song (if supported by the streaming service) | -| sleep | Number | Power off the player in the specified number of minutes. Sending 0 cancels the timer | +| Channel Type ID | Item Type | Description | +| ---------------------- | ----------- | -------------------------------------------------------------------------------------------- | +| power | Switch | Power on/off your device | +| mute | Switch | Mute/unmute your device | +| volume | Dimmer | Volume of your device | +| stop | Switch | Stop the current title | +| control | Player | Control the Zone Player, e.g. play/pause/next/previous/ffward/rewind | +| stream | String | Play the given HTTP or file stream (file:// or http://) | +| source | String | Shows the source of the currently playing playlist entry. (i.e. `http://radio.org/radio.mp3` | +| sync | String | Add another player to your device for synchronized playback (other player mac address) | +| playListIndex | Number | Playlist Index | +| currentPlayingTime | Number:Time | Current Playing Time | +| duration | Number:Time | Duration of currently playing track (in seconds) | +| currentPlaylistShuffle | Number | Current playlist shuffle mode (0 No Shuffle, 1 Shuffle Songs, 2 Shuffle Albums) | +| currentPlaylistRepeat | Number | Current playlist repeat Mode (0 No Repeat, 1 Repeat Song, 2 Repeat Playlist) | +| title | String | Title of the current song | +| remotetitle | String | Remote Title (Radio) of the current song | +| album | String | Album name of the current song | +| artist | String | Artist name of the current song | +| year | String | Release year of the current song | +| genre | String | Genre name of the current song | +| albumArtist | String | Main artist of the entire album | +| trackArtist | String | Main artist of the track | +| band | String | Band/orchestra that performed the work | +| composer | String | Original composer of the work | +| conductor | String | Person who conducted the performance | +| coverartdata | Image | Image data of cover art of the current song | +| 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) | +| rate | Switch | "Like" or "unlike" the currently playing song (if supported by the streaming service) | +| sleep | Number | Power off the player in the specified number of minutes. Sending 0 cancels the timer | ## Example .Items File diff --git a/bundles/org.openhab.binding.squeezebox/src/main/java/org/openhab/binding/squeezebox/internal/handler/SqueezeBoxPlayerHandler.java b/bundles/org.openhab.binding.squeezebox/src/main/java/org/openhab/binding/squeezebox/internal/handler/SqueezeBoxPlayerHandler.java index e87043514b9e0..263dab869fc0b 100644 --- a/bundles/org.openhab.binding.squeezebox/src/main/java/org/openhab/binding/squeezebox/internal/handler/SqueezeBoxPlayerHandler.java +++ b/bundles/org.openhab.binding.squeezebox/src/main/java/org/openhab/binding/squeezebox/internal/handler/SqueezeBoxPlayerHandler.java @@ -39,9 +39,11 @@ import org.openhab.core.library.types.OnOffType; import org.openhab.core.library.types.PercentType; import org.openhab.core.library.types.PlayPauseType; +import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.types.RawType; import org.openhab.core.library.types.RewindFastforwardType; import org.openhab.core.library.types.StringType; +import org.openhab.core.library.unit.Units; import org.openhab.core.thing.ChannelUID; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingStatus; @@ -297,7 +299,14 @@ public void handleCommand(ChannelUID channelUID, Command command) { squeezeBoxServerHandler.playPlaylistItem(mac, ((DecimalType) command).intValue()); break; case CHANNEL_CURRENT_PLAYING_TIME: - squeezeBoxServerHandler.setPlayingTime(mac, ((DecimalType) command).intValue()); + if (command instanceof DecimalType decimalCommand) { + squeezeBoxServerHandler.setPlayingTime(mac, decimalCommand.intValue()); + } else if (command instanceof QuantityType quantityCommand) { + QuantityType quantitySeconds = quantityCommand.toUnit(Units.SECOND); + if (quantitySeconds != null) { + squeezeBoxServerHandler.setPlayingTime(mac, quantitySeconds.intValue()); + } + } break; case CHANNEL_CURRENT_PLAYLIST_SHUFFLE: squeezeBoxServerHandler.setShuffleMode(mac, ((DecimalType) command).intValue()); @@ -390,7 +399,7 @@ public void currentPlaylistIndexEvent(String mac, int index) { @Override public void currentPlayingTimeEvent(String mac, int time) { - updateChannel(mac, CHANNEL_CURRENT_PLAYING_TIME, new DecimalType(time)); + updateChannel(mac, CHANNEL_CURRENT_PLAYING_TIME, new QuantityType<>(time, Units.SECOND)); if (isMe(mac)) { currentTime = time; } @@ -402,7 +411,7 @@ public void durationEvent(String mac, int duration) { logger.debug("Channel 'duration' does not exist. Delete and readd player thing to pick up channel."); return; } - updateChannel(mac, CHANNEL_DURATION, new DecimalType(duration)); + updateChannel(mac, CHANNEL_DURATION, new QuantityType<>(duration, Units.SECOND)); } @Override @@ -646,7 +655,15 @@ private boolean cachedStateAsBoolean(String key, @NonNull State activeState) { private int cachedStateAsInt(String key) { State state = stateMap.get(key); - return state instanceof DecimalType decimalValue ? decimalValue.intValue() : 0; + if (state instanceof DecimalType decimalValue) { + return decimalValue.intValue(); + } else if (state instanceof QuantityType quantityValue) { + QuantityType quantitySeconds = quantityValue.toUnit(Units.SECOND); + if (quantitySeconds != null) { + return quantitySeconds.intValue(); + } + } + return 0; } /** @@ -655,7 +672,7 @@ private int cachedStateAsInt(String key) { private void timeCounter() { timeCounterJob = scheduler.scheduleWithFixedDelay(() -> { if (playing) { - updateChannel(mac, CHANNEL_CURRENT_PLAYING_TIME, new DecimalType(currentTime++)); + updateChannel(mac, CHANNEL_CURRENT_PLAYING_TIME, new QuantityType<>(currentTime++, Units.SECOND)); } }, 0, 1, TimeUnit.SECONDS); } diff --git a/bundles/org.openhab.binding.squeezebox/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.squeezebox/src/main/resources/OH-INF/thing/thing-types.xml index b381f5138d6d4..3d6824747bcf6 100644 --- a/bundles/org.openhab.binding.squeezebox/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.squeezebox/src/main/resources/OH-INF/thing/thing-types.xml @@ -98,6 +98,7 @@ + 1 mac @@ -216,14 +217,18 @@ Playlist index - Number + Number:Time Current Playing Time + Time + - Number + Number:Time Duration of Current Track (in seconds) + Time + Number diff --git a/bundles/org.openhab.binding.squeezebox/src/main/resources/OH-INF/update/instructions.xml b/bundles/org.openhab.binding.squeezebox/src/main/resources/OH-INF/update/instructions.xml new file mode 100644 index 0000000000000..31729b5099438 --- /dev/null +++ b/bundles/org.openhab.binding.squeezebox/src/main/resources/OH-INF/update/instructions.xml @@ -0,0 +1,16 @@ + + + + + + squeezebox:currentPlayingTime + + + squeezebox:duration + + + + +