]> git.basschouten.com Git - openhab-addons.git/commitdiff
[nuvo] Add Image channel for album art (#13498)
authormlobstein <michael.lobstein@gmail.com>
Mon, 10 Oct 2022 13:53:05 +0000 (08:53 -0500)
committerGitHub <noreply@github.com>
Mon, 10 Oct 2022 13:53:05 +0000 (15:53 +0200)
* Add Image channel for Album Art

Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
bundles/org.openhab.binding.nuvo/README.md
bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/NuvoBindingConstants.java
bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/handler/NuvoHandler.java
bundles/org.openhab.binding.nuvo/src/main/resources/OH-INF/i18n/nuvo.properties
bundles/org.openhab.binding.nuvo/src/main/resources/OH-INF/thing/channels.xml

index 82718bf49f109258115c0c8a36eadba7b7b99a64..618b7b7ead955ac8e369ae782f207dfe31316157 100644 (file)
@@ -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)
 }
 
index 3c5c240d67843c2c55b083736e4d74a0ced17ace..c3cf2497c825fb31c8a751803d550b6d1a3d26f0 100644 (file)
@@ -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";
index 7e0bfefdd321d2e61aa59dd9cb3e93c5e7d344bb..7869b78778185544738353c0ad7cc8bb3b25929e 100644 (file)
@@ -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<Time>(Integer.parseInt(value) / 10, NuvoHandler.API_SECOND_UNIT);
                 break;
+            case CHANNEL_ALBUM_ART:
+                state = new RawType(bytes, RawType.DEFAULT_MIME_TYPE);
+                break;
             default:
                 break;
         }
index 6c458243d6e16b39a153e91a885cc8b36491ec63..b882e74e53738a0ae00cf5ae78468bb813e7e449 100644 (file)
@@ -154,6 +154,8 @@ channel-group-type.nuvo.zone.description = The Controls for the Zone
 
 # channel types
 
+channel-type.nuvo.album_art.label = Album Art
+channel-type.nuvo.album_art.description = The Album Art loaded from the art_url channel for display in a UI widget
 channel-type.nuvo.alloff.label = All Off
 channel-type.nuvo.alloff.description = Turn All Zones Off
 channel-type.nuvo.art_url.label = Album Art URL
index 09b6febd2009f49f59fbb96924813c2f41a2a4a0..023af7f53dd5d7e5618694dc0f8d0a2e387aa383 100644 (file)
                        <channel id="track_position" typeId="track_position"/>
                        <channel id="button_press" typeId="button_press"/>
                        <channel id="art_url" typeId="art_url"/>
+                       <channel id="album_art" typeId="album_art"/>
                </channels>
        </channel-group-type>
 
                <description>The URL of the Album Art JPG for this source that is displayed on a CTP-36</description>
        </channel-type>
 
+       <channel-type id="album_art">
+               <item-type>Image</item-type>
+               <label>Album Art</label>
+               <description>The Album Art loaded from the art_url channel for display in a UI widget</description>
+               <state readOnly="true"/>
+       </channel-type>
+
 </thing:thing-descriptions>