From 4c6d63df387205737f747f974af9d5b5b4211d80 Mon Sep 17 00:00:00 2001 From: mlobstein Date: Thu, 1 Oct 2020 22:41:58 -0500 Subject: [PATCH] [nuvo] Add favorites selection channel and fix a few bugs (#8631) * Fix issue with All Mute and extra source options * Add channel to select preset favorite Signed-off-by: Michael Lobstein --- bundles/org.openhab.binding.nuvo/README.md | 23 ++++++----- .../nuvo/internal/NuvoBindingConstants.java | 1 + .../internal/communication/NuvoCommand.java | 1 + .../nuvo/internal/handler/NuvoHandler.java | 31 +++++++++++---- .../main/resources/OH-INF/thing/channels.xml | 39 +++++++++++++++---- 5 files changed, 69 insertions(+), 26 deletions(-) diff --git a/bundles/org.openhab.binding.nuvo/README.md b/bundles/org.openhab.binding.nuvo/README.md index 09a785a50..eaa82f9c7 100644 --- a/bundles/org.openhab.binding.nuvo/README.md +++ b/bundles/org.openhab.binding.nuvo/README.md @@ -70,6 +70,7 @@ The following channels are available: | zoneN#source (where N= 1-20) | Number | Select the source input for a zone (1-6) | | zoneN#volume (where N= 1-20) | Dimmer | Control the volume for a zone (0-100%) [translates to 0-79] | | zoneN#mute (where N= 1-20) | Switch | Mute or unmute a zone | +| zoneN#favorite (where N= 1-20) | Number | Select a preset Favorite for a zone (1-12) | | zoneN#control (where N= 1-20) | Player | Simulate pressing the transport control buttons on the keypad e.g. play/pause/next/previous | | zoneN#treble (where N= 1-20) | Number | Adjust the treble control for a zone (-18 to 18 [in increments of 2]) -18=none, 0=flat, 18=full | | zoneN#bass (where N= 1-20) | Number | Adjust the bass control for a zone (-18 to 18 [in increments of 2]) -18=none, 0=flat, 18=full | @@ -113,6 +114,7 @@ Switch nuvo_z1_power "Power" { channel="nuvo:amplifier:myamp:zone1#power" } Number nuvo_z1_source "Source Input [%s]" { channel="nuvo:amplifier:myamp:zone1#source" } Dimmer nuvo_z1_volume "Volume [%d %%]" { channel="nuvo:amplifier:myamp:zone1#volume" } Switch nuvo_z1_mute "Mute" { channel="nuvo:amplifier:myamp:zone1#mute" } +Number nuvo_z1_favorite "Favorite" { channel="nuvo:amplifier:myamp:zone1#favorite" } Player nuvo_z1_control "Control" { channel="nuvo:amplifier:myamp:zone1#control" } Number nuvo_z1_treble "Treble Adjustment [%s]" { channel="nuvo:amplifier:myamp:zone1#treble" } Number nuvo_z1_bass "Bass Adjustment [%s]" { channel="nuvo:amplifier:myamp:zone1#bass" } @@ -197,6 +199,8 @@ sitemap nuvo label="Audio Control" { //Volume can be a Setpoint also Slider item=nuvo_z1_volume minValue=0 maxValue=100 step=1 visibility=[nuvo_z1_power==ON] icon="soundvolume" Switch item=nuvo_z1_mute visibility=[nuvo_z1_power==ON] icon="soundvolume_mute" + // mappings is optional to override the default dropdown item labels + Selection item=nuvo_z1_favorite visibility=[nuvo_z1_power==ON] icon="player" //mappings=[1="WNYC", 2="BBC One", 2="My Playlist"] Default item=nuvo_z1_control visibility=[nuvo_z1_power==ON] Text item=nuvo_s1_display_line1 visibility=[nuvo_z1_source=="1"] icon="zoom" @@ -253,13 +257,15 @@ sitemap nuvo label="Audio Control" { Text item=nuvo_s6_track_position visibility=[nuvo_z1_source=="6"] Text item=nuvo_s6_button_press visibility=[nuvo_z1_source=="6"] icon="none" - Setpoint item=nuvo_z1_treble label="Treble Adjustment [%d]" minValue=-18 maxValue=18 step=2 visibility=[nuvo_z1_power==ON] - Setpoint item=nuvo_z1_bass label="Bass Adjustment [%d]" minValue=-18 maxValue=18 step=2 visibility=[nuvo_z1_power==ON] - Setpoint item=nuvo_z1_balance label="Balance Adjustment [%d]" minValue=-18 maxValue=18 step=2 visibility=[nuvo_z1_power==ON] - Switch item=nuvo_z1_loudness visibility=[nuvo_z1_power==ON] - Switch item=nuvo_z1_dnd visibility=[nuvo_z1_power==ON] - Text item=nuvo_z1_lock label="Zone Locked: [%s]" icon="lock" - Switch item=nuvo_z1_party visibility=[nuvo_z1_power==ON] + Text label="Advanced" icon="settings" visibility=[nuvo_z1_power==ON] { + Setpoint item=nuvo_z1_treble label="Treble Adjustment [%d]" minValue=-18 maxValue=18 step=2 + Setpoint item=nuvo_z1_bass label="Bass Adjustment [%d]" minValue=-18 maxValue=18 step=2 + Setpoint item=nuvo_z1_balance label="Balance Adjustment [%d]" minValue=-18 maxValue=18 step=2 + Switch item=nuvo_z1_loudness + Switch item=nuvo_z1_dnd + Switch item=nuvo_z1_party + } + Text item=nuvo_z1_lock label="Zone Locked: [%s]" icon="lock" visibility=[nuvo_z1_lock=="1"] } //repeat for zones 2-20 (substitute z1) @@ -294,9 +300,6 @@ then // Send a message to Zone 11 //actions.sendNuvoCommand("Z11MSG\"Hello World\",0,0") - // Select a Favorite (1-12) for Zone 2 - //actions.sendNuvoCommand("Z2FAV1") - end // In the below examples, a method for maintaing Metadata information 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 7b28a0f6b..08bdaa251 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 @@ -39,6 +39,7 @@ public class NuvoBindingConstants { // zone public static final String CHANNEL_TYPE_POWER = "power"; public static final String CHANNEL_TYPE_SOURCE = "source"; + public static final String CHANNEL_TYPE_FAVORITE = "favorite"; public static final String CHANNEL_TYPE_VOLUME = "volume"; public static final String CHANNEL_TYPE_MUTE = "mute"; public static final String CHANNEL_TYPE_CONTROL = "control"; diff --git a/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/communication/NuvoCommand.java b/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/communication/NuvoCommand.java index ac43e707e..4457570d0 100644 --- a/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/communication/NuvoCommand.java +++ b/bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/communication/NuvoCommand.java @@ -40,6 +40,7 @@ public enum NuvoCommand { ON("ON"), OFF("OFF"), SOURCE("SRC"), + FAVORITE("FAV"), VOLUME("VOL"), MUTE_ON("MUTEON"), MUTE_OFF("MUTEOFF"), 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 da710cc10..a4b8e5923 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 @@ -23,6 +23,7 @@ import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.TreeMap; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; @@ -98,6 +99,7 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis private static final int MAX_ZONES = 20; private static final int MAX_SRC = 6; + private static final int MAX_FAV = 12; private static final int MIN_VOLUME = 0; private static final int MAX_VOLUME = 79; private static final int MIN_EQ = -18; @@ -129,8 +131,8 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis Set activeZones = new HashSet<>(1); - // A state option list for the source labels - List sourceLabels = new ArrayList<>(); + // A tree map that maps the source ids to source labels + TreeMap sourceLabels = new TreeMap(); /** * Constructor @@ -274,6 +276,15 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis } } break; + case CHANNEL_TYPE_FAVORITE: + if (command instanceof DecimalType) { + int value = ((DecimalType) command).intValue(); + if (value >= 1 && value <= MAX_FAV) { + logger.debug("Got favorite command {} zone {}", value, target); + connector.sendCommand(target, NuvoCommand.FAVORITE, String.valueOf(value)); + } + } + break; case CHANNEL_TYPE_VOLUME: if (command instanceof PercentType) { int value = (MAX_VOLUME @@ -373,14 +384,13 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis break; case CHANNEL_TYPE_ALLMUTE: if (command instanceof OnOffType) { - connector.sendCommand(target, + connector.sendCommand( command == OnOffType.ON ? NuvoCommand.ALLMUTE_ON : NuvoCommand.ALLMUTE_OFF); } break; case CHANNEL_TYPE_PAGE: if (command instanceof OnOffType) { - connector.sendCommand(target, - command == OnOffType.ON ? NuvoCommand.PAGE_ON : NuvoCommand.PAGE_OFF); + connector.sendCommand(command == OnOffType.ON ? NuvoCommand.PAGE_ON : NuvoCommand.PAGE_OFF); } break; } @@ -484,10 +494,10 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis } else { logger.debug("no match on message: {}", updateData); } - } else if (updateData.contains(NAME_QUOTE) && sourceLabels.size() <= MAX_SRC) { + } else if (updateData.contains(NAME_QUOTE)) { // example: NAME"Ipod" String name = updateData.split("\"")[1]; - sourceLabels.add(new StateOption(key, name)); + sourceLabels.put(key, name); } break; case TYPE_ZONE_UPDATE: @@ -594,11 +604,16 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis if (prevUpdateTime == lastEventReceived) { error = "Controller not responding to status requests"; } else { + List sourceStateOptions = new ArrayList<>(); + sourceLabels.keySet().forEach(key -> { + sourceStateOptions.add(new StateOption(key, sourceLabels.get(key))); + }); + // Put the source labels on all active zones activeZones.forEach(zoneNum -> { stateDescriptionProvider.setStateOptions(new ChannelUID(getThing().getUID(), ZONE.toLowerCase() + zoneNum + CHANNEL_DELIMIT + CHANNEL_TYPE_SOURCE), - sourceLabels); + sourceStateOptions); }); } } catch (NuvoException e) { diff --git a/bundles/org.openhab.binding.nuvo/src/main/resources/OH-INF/thing/channels.xml b/bundles/org.openhab.binding.nuvo/src/main/resources/OH-INF/thing/channels.xml index d20a1772d..69eb80184 100644 --- a/bundles/org.openhab.binding.nuvo/src/main/resources/OH-INF/thing/channels.xml +++ b/bundles/org.openhab.binding.nuvo/src/main/resources/OH-INF/thing/channels.xml @@ -6,7 +6,7 @@ - + A Multi-zone Whole House Amplifier System @@ -96,27 +96,27 @@ The Controls for Zone 20 - + The Display Information for Source 1 - + The Display Information for Source 2 - + The Display Information for Source 3 - + The Display Information for Source 4 - + The Display Information for Source 5 - + The Display Information for Source 6 @@ -169,6 +169,7 @@ + @@ -182,7 +183,7 @@ - + The Display Information for the Source @@ -215,6 +216,28 @@ Select the Source Input for the Zone + + Number + + Select a Preset Favorite for the Zone + + + + + + + + + + + + + + + + + + Player