From f431bfc013e2c0c92d0c293e9e4e2cabdaacd9d4 Mon Sep 17 00:00:00 2001 From: mlobstein Date: Mon, 10 Oct 2022 08:53:05 -0500 Subject: [PATCH] [nuvo] Add Image channel for album art (#13498) * Add Image channel for Album Art Signed-off-by: Michael Lobstein --- bundles/org.openhab.binding.nuvo/README.md | 16 ++++++++++++- .../nuvo/internal/NuvoBindingConstants.java | 1 + .../nuvo/internal/handler/NuvoHandler.java | 24 ++++++++++++++++++- .../resources/OH-INF/i18n/nuvo.properties | 2 ++ .../main/resources/OH-INF/thing/channels.xml | 8 +++++++ 5 files changed, 49 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.binding.nuvo/README.md b/bundles/org.openhab.binding.nuvo/README.md index 82718bf49f1..618b7b7ead9 100644 --- a/bundles/org.openhab.binding.nuvo/README.md +++ b/bundles/org.openhab.binding.nuvo/README.md @@ -113,6 +113,7 @@ The following channels are available: | sourceN#track_position (where N= 1-6)| Number:Time | The running time elapsed of the current playing track (ReadOnly) See rules example for updating | | sourceN#button_press (where N= 1-6) | String | Indicates the last button pressed on the keypad for a non NuvoNet source or openHAB NuvoNet source (ReadOnly) | | sourceN#art_url (where N= 1-6) | String | MPS4 Only! The URL of the Album Art JPG for this source that is displayed on a CTP-36. See *very advanced* rules (SendOnly) | +| sourceN#album_art (where N= 1-6) | Image | The Album Art loaded from the art_url channel for display in a UI widget (ReadOnly) | ## Full Example @@ -166,6 +167,7 @@ Number:Time nuvo_s1_track_length "Track Length: [%s s]" { channel="nuvo:amplifie Number:Time nuvo_s1_track_position "Track Position: [%s s]" { channel="nuvo:amplifier:myamp:source1#track_position" } String nuvo_s1_button_press "Button: [%s]" { channel="nuvo:amplifier:myamp:source1#button_press" } // String nuvo_s1_art_url "URL: [%s]" { channel="nuvo:amplifier:myamp:source1#art_url" } +// Image nuvo_s1_album_art { channel="nuvo:amplifier:myamp:source1#album_art" } String nuvo_s2_display_line1 "Line 1: [%s]" { channel="nuvo:amplifier:myamp:source2#display_line1" } String nuvo_s2_display_line2 "Line 2: [%s]" { channel="nuvo:amplifier:myamp:source2#display_line2" } @@ -176,6 +178,7 @@ Number:Time nuvo_s2_track_length "Track Length: [%s s]" { channel="nuvo:amplifie Number:Time nuvo_s2_track_position "Track Position: [%s s]" { channel="nuvo:amplifier:myamp:source2#track_position" } String nuvo_s2_button_press "Button: [%s]" { channel="nuvo:amplifier:myamp:source2#button_press" } // String nuvo_s2_art_url "URL: [%s]" { channel="nuvo:amplifier:myamp:source2#art_url" } +// Image nuvo_s2_album_art { channel="nuvo:amplifier:myamp:source2#album_art" } String nuvo_s3_display_line1 "Line 1: [%s]" { channel="nuvo:amplifier:myamp:source3#display_line1" } String nuvo_s3_display_line2 "Line 2: [%s]" { channel="nuvo:amplifier:myamp:source3#display_line2" } @@ -186,6 +189,7 @@ Number:Time nuvo_s3_track_length "Track Length: [%s s]" { channel="nuvo:amplifie Number:Time nuvo_s3_track_position "Track Position: [%s s]" { channel="nuvo:amplifier:myamp:source3#track_position" } String nuvo_s3_button_press "Button: [%s]" { channel="nuvo:amplifier:myamp:source3#button_press" } // String nuvo_s3_art_url "URL: [%s]" { channel="nuvo:amplifier:myamp:source3#art_url" } +// Image nuvo_s3_album_art { channel="nuvo:amplifier:myamp:source3#album_art" } String nuvo_s4_display_line1 "Line 1: [%s]" { channel="nuvo:amplifier:myamp:source4#display_line1" } String nuvo_s4_display_line2 "Line 2: [%s]" { channel="nuvo:amplifier:myamp:source4#display_line2" } @@ -196,6 +200,7 @@ Number:Time nuvo_s4_track_length "Track Length: [%s s]" { channel="nuvo:amplifie Number:Time nuvo_s4_track_position "Track Position: [%s s]" { channel="nuvo:amplifier:myamp:source4#track_position" } String nuvo_s4_button_press "Button: [%s]" { channel="nuvo:amplifier:myamp:source4#button_press" } // String nuvo_s4_art_url "URL: [%s]" { channel="nuvo:amplifier:myamp:source4#art_url" } +// Image nuvo_s4_album_art { channel="nuvo:amplifier:myamp:source4#album_art" } String nuvo_s5_display_line1 "Line 1: [%s]" { channel="nuvo:amplifier:myamp:source5#display_line1" } String nuvo_s5_display_line2 "Line 2: [%s]" { channel="nuvo:amplifier:myamp:source5#display_line2" } @@ -206,6 +211,7 @@ Number:Time nuvo_s5_track_length "Track Length: [%s s]" { channel="nuvo:amplifie Number:Time nuvo_s5_track_position "Track Position: [%s s]" { channel="nuvo:amplifier:myamp:source5#track_position" } String nuvo_s5_button_press "Button: [%s]" { channel="nuvo:amplifier:myamp:source5#button_press" } // String nuvo_s5_art_url "URL: [%s]" { channel="nuvo:amplifier:myamp:source5#art_url" } +// Image nuvo_s5_album_art { channel="nuvo:amplifier:myamp:source5#album_art" } String nuvo_s6_display_line1 "Line 1: [%s]" { channel="nuvo:amplifier:myamp:source6#display_line1" } String nuvo_s6_display_line2 "Line 2: [%s]" { channel="nuvo:amplifier:myamp:source6#display_line2" } @@ -216,6 +222,7 @@ Number:Time nuvo_s6_track_length "Track Length: [%s s]" { channel="nuvo:amplifie Number:Time nuvo_s6_track_position "Track Position: [%s s]" { channel="nuvo:amplifier:myamp:source6#track_position" } String nuvo_s6_button_press "Button: [%s]" { channel="nuvo:amplifier:myamp:source6#button_press" } // String nuvo_s6_art_url "URL: [%s]" { channel="nuvo:amplifier:myamp:source6#art_url" } +// Image nuvo_s6_album_art { channel="nuvo:amplifier:myamp:source6#album_art" } ``` @@ -301,8 +308,15 @@ sitemap nuvo label="Audio Control" { Switch item=nuvo_z1_party } Text item=nuvo_z1_lock label="Zone Locked: [%s]" icon="lock" visibility=[nuvo_z1_lock=="1"] + + // Image item=nuvo_s1_album_art visibility=[nuvo_z1_source=="1"] + // Image item=nuvo_s2_album_art visibility=[nuvo_z1_source=="2"] + // Image item=nuvo_s3_album_art visibility=[nuvo_z1_source=="3"] + // Image item=nuvo_s4_album_art visibility=[nuvo_z1_source=="4"] + // Image item=nuvo_s5_album_art visibility=[nuvo_z1_source=="5"] + // Image item=nuvo_s6_album_art visibility=[nuvo_z1_source=="6"] } - + // repeat for zones 2-20 (substitute z1) } diff --git a/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/NuvoBindingConstants.java b/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/NuvoBindingConstants.java index 3c5c240d678..c3cf2497c82 100644 --- a/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/NuvoBindingConstants.java +++ b/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/NuvoBindingConstants.java @@ -62,6 +62,7 @@ public class NuvoBindingConstants { public static final String CHANNEL_TRACK_POSITION = "track_position"; public static final String CHANNEL_BUTTON_PRESS = "button_press"; public static final String CHANNEL_ART_URL = "art_url"; + public static final String CHANNEL_ALBUM_ART = "album_art"; // Message types public static final String TYPE_VERSION = "version"; diff --git a/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/handler/NuvoHandler.java b/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/handler/NuvoHandler.java index 7e0bfefdd32..7869b787781 100644 --- a/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/handler/NuvoHandler.java +++ b/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/handler/NuvoHandler.java @@ -75,6 +75,7 @@ import org.openhab.core.library.types.OpenClosedType; 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.StringType; import org.openhab.core.library.unit.Units; import org.openhab.core.thing.Channel; @@ -566,14 +567,19 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis if (httpStatus == OK_200) { albumArtMap.put(target.getId(), NuvoImageResizer.resizeImage(contentResponse.getContent(), 80, 80)); + + updateChannelState(target, CHANNEL_ALBUM_ART, BLANK, + contentResponse.getContent()); } else { albumArtMap.put(target.getId(), NO_ART); albumArtIds.put(target.getId(), 0); + updateChannelState(target, CHANNEL_ALBUM_ART, UNDEF); return; } } catch (InterruptedException | TimeoutException | ExecutionException e) { albumArtMap.put(target.getId(), NO_ART); albumArtIds.put(target.getId(), 0); + updateChannelState(target, CHANNEL_ALBUM_ART, UNDEF); return; } albumArtIds.put(target.getId(), Math.abs(url.hashCode())); @@ -586,6 +592,7 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis } else { albumArtMap.put(target.getId(), NO_ART); albumArtIds.put(target.getId(), 0); + updateChannelState(target, CHANNEL_ALBUM_ART, UNDEF); } } } @@ -1229,13 +1236,25 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis } /** - * Update the state of a channel + * Update the state of a channel (original method signature) * * @param target the channel group * @param channelType the channel group item * @param value the value to be updated */ private void updateChannelState(NuvoEnum target, String channelType, String value) { + updateChannelState(target, channelType, value, NO_ART); + } + + /** + * Update the state of a channel (overloaded method to handle album_art channel) + * + * @param target the channel group + * @param channelType the channel group item + * @param value the value to be updated + * @param bytes the byte[] to load into the Image channel + */ + private void updateChannelState(NuvoEnum target, String channelType, String value, byte[] bytes) { String channel = target.name().toLowerCase() + CHANNEL_DELIMIT + channelType; if (!isLinked(channel)) { @@ -1288,6 +1307,9 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis case CHANNEL_TRACK_POSITION: state = new QuantityType