[nuvo] Add Image channel for album art (#13498)

* Add Image channel for Album Art

Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
This commit is contained in:
mlobstein 2022-10-10 08:53:05 -05:00 committed by GitHub
parent 507e714dd0
commit f431bfc013
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 2 deletions

View 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)
}

View 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";

View 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;
}

View 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

View File

@ -378,6 +378,7 @@
<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>
@ -527,4 +528,11 @@
<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>