From de50c5634f60c715bc3d5f1e303357ee221b87a4 Mon Sep 17 00:00:00 2001 From: Hilbrand Bouwkamp Date: Thu, 16 Apr 2020 17:20:47 +0200 Subject: [PATCH] [Spotify] Added channel to display if track is explicit (#7388) Closes #7377 Signed-off-by: Hilbrand Bouwkamp Signed-off-by: CSchlipp --- .../spotify/internal/SpotifyBindingConstants.java | 1 + .../openhab/binding/spotify/internal/api/model/Item.java | 4 ++-- .../spotify/internal/handler/SpotifyBridgeHandler.java | 1 + .../src/main/resources/ESH-INF/thing/thing-types.xml | 9 ++++++++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.binding.spotify/src/main/java/org/openhab/binding/spotify/internal/SpotifyBindingConstants.java b/bundles/org.openhab.binding.spotify/src/main/java/org/openhab/binding/spotify/internal/SpotifyBindingConstants.java index 76bccc6cb7d54..7f40dc64a516d 100644 --- a/bundles/org.openhab.binding.spotify/src/main/java/org/openhab/binding/spotify/internal/SpotifyBindingConstants.java +++ b/bundles/org.openhab.binding.spotify/src/main/java/org/openhab/binding/spotify/internal/SpotifyBindingConstants.java @@ -64,6 +64,7 @@ public class SpotifyBindingConstants { public static final String CHANNEL_PLAYED_TRACKNUMBER = "trackNumber"; public static final String CHANNEL_PLAYED_TRACKDISCNUMBER = "trackDiscNumber"; public static final String CHANNEL_PLAYED_TRACKPOPULARITY = "trackPopularity"; + public static final String CHANNEL_PLAYED_TRACKEXPLICIT = "trackExplicit"; public static final String CHANNEL_PLAYED_TRACKDURATION_MS = "trackDurationMs"; public static final String CHANNEL_PLAYED_TRACKPROGRESS_MS = "trackProgressMs"; public static final String CHANNEL_PLAYED_TRACKDURATION_FMT = "trackDuration"; diff --git a/bundles/org.openhab.binding.spotify/src/main/java/org/openhab/binding/spotify/internal/api/model/Item.java b/bundles/org.openhab.binding.spotify/src/main/java/org/openhab/binding/spotify/internal/api/model/Item.java index 4b689d302216b..ed53fc7af2610 100644 --- a/bundles/org.openhab.binding.spotify/src/main/java/org/openhab/binding/spotify/internal/api/model/Item.java +++ b/bundles/org.openhab.binding.spotify/src/main/java/org/openhab/binding/spotify/internal/api/model/Item.java @@ -27,7 +27,7 @@ public class Item { private List availableMarkets; private Integer discNumber; private long durationMs; - private Boolean explicit; + private boolean explicit; private ExternalIds externalIds; private ExternalUrl externalUrls; private String href; @@ -59,7 +59,7 @@ public long getDurationMs() { return durationMs; } - public Boolean getExplicit() { + public boolean isExplicit() { return explicit; } diff --git a/bundles/org.openhab.binding.spotify/src/main/java/org/openhab/binding/spotify/internal/handler/SpotifyBridgeHandler.java b/bundles/org.openhab.binding.spotify/src/main/java/org/openhab/binding/spotify/internal/handler/SpotifyBridgeHandler.java index 5f301d91c38a4..420bba11d042b 100644 --- a/bundles/org.openhab.binding.spotify/src/main/java/org/openhab/binding/spotify/internal/handler/SpotifyBridgeHandler.java +++ b/bundles/org.openhab.binding.spotify/src/main/java/org/openhab/binding/spotify/internal/handler/SpotifyBridgeHandler.java @@ -473,6 +473,7 @@ private void updatePlayerInfo(CurrentlyPlayingContext playerInfo, List updateChannelState(CHANNEL_PLAYED_TRACKNUMBER, valueOrZero(item.getTrackNumber())); updateChannelState(CHANNEL_PLAYED_TRACKDISCNUMBER, valueOrZero(item.getDiscNumber())); updateChannelState(CHANNEL_PLAYED_TRACKPOPULARITY, valueOrZero(item.getPopularity())); + updateChannelState(CHANNEL_PLAYED_TRACKEXPLICIT, OnOffType.from(item.isExplicit())); final boolean hasAlbum = hasItem && item.getAlbum() != null; final Album album = hasAlbum ? item.getAlbum() : EMPTY_ALBUM; diff --git a/bundles/org.openhab.binding.spotify/src/main/resources/ESH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.spotify/src/main/resources/ESH-INF/thing/thing-types.xml index 96d42e670b35d..3d61d3c2f3602 100644 --- a/bundles/org.openhab.binding.spotify/src/main/resources/ESH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.spotify/src/main/resources/ESH-INF/thing/thing-types.xml @@ -37,6 +37,7 @@ register a bridge for each account. Go to http://your openHAB address::8080/conn + @@ -245,7 +246,13 @@ bridge you have configured. Number - The populatiry of the currently played track + The popularity of the currently played track + + + + Switch + + Whether or not the track has explicit lyrics (On it does; Off it does not OR unknown)