[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 <michael.lobstein@gmail.com>
This commit is contained in:
mlobstein
2020-10-01 22:41:58 -05:00
committed by GitHub
parent 003c3af985
commit 4c6d63df38
5 changed files with 69 additions and 26 deletions

View File

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

View File

@@ -40,6 +40,7 @@ public enum NuvoCommand {
ON("ON"),
OFF("OFF"),
SOURCE("SRC"),
FAVORITE("FAV"),
VOLUME("VOL"),
MUTE_ON("MUTEON"),
MUTE_OFF("MUTEOFF"),

View File

@@ -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<Integer> activeZones = new HashSet<>(1);
// A state option list for the source labels
List<StateOption> sourceLabels = new ArrayList<>();
// A tree map that maps the source ids to source labels
TreeMap<String, String> sourceLabels = new TreeMap<String, String>();
/**
* 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<StateOption> 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) {

View File

@@ -6,7 +6,7 @@
<!-- Nuvo Whole House Amplifier Thing -->
<thing-type id="amplifier">
<label>Whole House Amplifier</label>
<label>Nuvo Whole House Amplifier</label>
<description>
A Multi-zone Whole House Amplifier System
</description>
@@ -96,27 +96,27 @@
<label>Zone 20</label>
<description>The Controls for Zone 20</description>
</channel-group>
<channel-group id="source1" typeId="source">
<channel-group id="source1" typeId="source_info">
<label>Source 1</label>
<description>The Display Information for Source 1</description>
</channel-group>
<channel-group id="source2" typeId="source">
<channel-group id="source2" typeId="source_info">
<label>Source 2</label>
<description>The Display Information for Source 2</description>
</channel-group>
<channel-group id="source3" typeId="source">
<channel-group id="source3" typeId="source_info">
<label>Source 3</label>
<description>The Display Information for Source 3</description>
</channel-group>
<channel-group id="source4" typeId="source">
<channel-group id="source4" typeId="source_info">
<label>Source 4</label>
<description>The Display Information for Source 4</description>
</channel-group>
<channel-group id="source5" typeId="source">
<channel-group id="source5" typeId="source_info">
<label>Source 5</label>
<description>The Display Information for Source 5</description>
</channel-group>
<channel-group id="source6" typeId="source">
<channel-group id="source6" typeId="source_info">
<label>Source 6</label>
<description>The Display Information for Source 6</description>
</channel-group>
@@ -169,6 +169,7 @@
<channels>
<channel id="power" typeId="system.power"/>
<channel id="source" typeId="source"/>
<channel id="favorite" typeId="favorite"/>
<channel id="volume" typeId="system.volume"/>
<channel id="mute" typeId="system.mute"/>
<channel id="control" typeId="control"/>
@@ -182,7 +183,7 @@
</channels>
</channel-group-type>
<channel-group-type id="source">
<channel-group-type id="source_info">
<label>Source Info</label>
<description>The Display Information for the Source</description>
<channels>
@@ -215,6 +216,28 @@
<description>Select the Source Input for the Zone</description>
</channel-type>
<channel-type id="favorite">
<item-type>Number</item-type>
<label>Favorite</label>
<description>Select a Preset Favorite for the Zone</description>
<state>
<options>
<option value="1">Favorite 1</option>
<option value="2">Favorite 2</option>
<option value="3">Favorite 3</option>
<option value="4">Favorite 4</option>
<option value="5">Favorite 5</option>
<option value="6">Favorite 6</option>
<option value="7">Favorite 7</option>
<option value="8">Favorite 8</option>
<option value="9">Favorite 9</option>
<option value="10">Favorite 10</option>
<option value="11">Favorite 11</option>
<option value="12">Favorite 12</option>
</options>
</state>
</channel-type>
<channel-type id="control">
<item-type>Player</item-type>
<label>Control</label>