[pioneeravr] Added channel for changing MCACC Memory profile on AVR (#10329)

Signed-off-by: Nathan Prins <nathanprins@hotmail.com>
This commit is contained in:
Nathan Prins 2021-03-31 12:50:42 -07:00 committed by GitHub
parent ec8f411774
commit b9fe3bef04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 174 additions and 5 deletions

View File

@ -92,6 +92,7 @@ public class PioneerAvrBindingConstants {
public static final String LISTENING_MODE_CHANNEL = "listeningMode";
public static final String PLAYING_LISTENING_MODE_CHANNEL = "playingListeningMode";
public static final String DISPLAY_INFORMATION_CHANNEL = "displayInformation#displayInformation";
public static final String MCACC_MEMORY_CHANNEL = "MCACCMemory#MCACCMemory";
public static final String GROUP_CHANNEL_PATTERN = "zone%s#%s";
public static final Pattern GROUP_CHANNEL_ZONE_PATTERN = Pattern.compile("zone([0-4])#.*");

View File

@ -123,6 +123,9 @@ public abstract class AbstractAvrHandler extends BaseThingHandler
connection.sendMuteQuery(zone);
connection.sendInputSourceQuery(zone);
connection.sendListeningModeQuery(zone);
// Channels which are not bound to any specific zone
connection.sendMCACCMemoryQuery();
}
/**
@ -136,6 +139,11 @@ public abstract class AbstractAvrHandler extends BaseThingHandler
updateState(getChannelUID(PioneerAvrBindingConstants.SET_INPUT_SOURCE_CHANNEL, zone), UnDefType.UNDEF);
updateState(getChannelUID(PioneerAvrBindingConstants.LISTENING_MODE_CHANNEL, zone), UnDefType.UNDEF);
updateState(getChannelUID(PioneerAvrBindingConstants.PLAYING_LISTENING_MODE_CHANNEL, zone), UnDefType.UNDEF);
// Channels which are not bound to any specific zone
if (zone == 1) {
updateState(PioneerAvrBindingConstants.MCACC_MEMORY_CHANNEL, UnDefType.UNDEF);
}
}
/**
@ -198,6 +206,12 @@ public abstract class AbstractAvrHandler extends BaseThingHandler
} else {
commandSent = connection.sendMuteCommand(command, getZoneFromChannelUID(channelUID.getId()));
}
} else if (channelUID.getId().contains(PioneerAvrBindingConstants.MCACC_MEMORY_CHANNEL)) {
if (command == RefreshType.REFRESH) {
commandSent = connection.sendMCACCMemoryQuery();
} else {
commandSent = connection.sendMCACCMemoryCommand(command);
}
} else {
unknownCommand = true;
}
@ -248,6 +262,10 @@ public abstract class AbstractAvrHandler extends BaseThingHandler
manageDisplayedInformationUpdate(response);
break;
case MCACC_MEMORY:
manageMCACCMemoryUpdate(response);
break;
default:
logger.debug("Unknown response type from AVR @{}. Response discarded: {}", event.getData(),
event.getConnection());
@ -354,6 +372,15 @@ public abstract class AbstractAvrHandler extends BaseThingHandler
new StringType(DisplayInformationConverter.convertMessageFromIpControl(response.getParameterValue())));
}
/**
* Notify an AVR MCACC Memory update to openHAB
*
* @param response
*/
private void manageMCACCMemoryUpdate(AvrResponse response) {
updateState(PioneerAvrBindingConstants.MCACC_MEMORY_CHANNEL, new StringType(response.getParameterValue()));
}
/**
* Build the channelUID from the channel name and the zone number.
*

View File

@ -30,7 +30,8 @@ public class ParameterizedCommand extends SimpleCommand {
VOLUME_SET("[0-9]{2,3}", "VL", "ZV", "YV", "HZV"),
INPUT_CHANNEL_SET("[0-9]{2}", "FN", "ZS", "ZT", "ZEA"),
LISTENING_MODE_SET("[0-9]{4}", "SR");
LISTENING_MODE_SET("[0-9]{4}", "SR"),
MCACC_MEMORY_SET("[1-6]{1}", "MC");
private String[] zoneCommands;
private String parameterPattern;
@ -40,6 +41,11 @@ public class ParameterizedCommand extends SimpleCommand {
this.parameterPattern = parameterPattern;
}
@Override
public String getCommand() {
return zoneCommands[0];
}
@Override
public String getCommand(int zone) {
return zoneCommands[zone - 1];
@ -54,6 +60,10 @@ public class ParameterizedCommand extends SimpleCommand {
private String parameterPattern;
protected ParameterizedCommand(ParameterizedCommandType command) {
this(command, 0);
}
protected ParameterizedCommand(ParameterizedCommandType command, int zone) {
super(command, zone);
this.parameterPattern = command.getParameterPattern();

View File

@ -34,6 +34,17 @@ public final class RequestResponseFactory {
return new IpAvrConnection(host, port);
}
/**
* Return a SimpleCommand of the type given in parameter.
*
* @param command
* @return
*/
public static SimpleCommand getIpControlCommand(SimpleCommandType command) {
SimpleCommand result = new SimpleCommand(command);
return result;
}
/**
* Return a ParameterizedCommand of the type given in parameter and for the given zone.
*
@ -46,6 +57,18 @@ public final class RequestResponseFactory {
return result;
}
/**
* Return a ParameterizedCommand of the type given in parameter. The
* parameter of the command has to be set before send.
*
* @param command
* @return
*/
public static ParameterizedCommand getIpControlCommand(ParameterizedCommandType command) {
ParameterizedCommand result = new ParameterizedCommand(command);
return result;
}
/**
* Return a ParameterizedCommand of the type given in parameter. The
* parameter of the command has to be set before send.
@ -61,7 +84,22 @@ public final class RequestResponseFactory {
/**
* Return a ParameterizedCommand of the type given in parameter. The
* parameter of the command is set with the given paramter value.
* parameter of the command is set with the given parameter value.
*
* @param command
* @param parameter
* @param zone
* @return
*/
public static ParameterizedCommand getIpControlCommand(ParameterizedCommandType command, String parameter) {
ParameterizedCommand result = getIpControlCommand(command);
result.setParameter(parameter);
return result;
}
/**
* Return a ParameterizedCommand of the type given in parameter. The
* parameter of the command is set with the given parameter value.
*
* @param command
* @param parameter

View File

@ -37,7 +37,8 @@ public class Response implements AvrResponse {
INPUT_SOURCE_CHANNEL("[0-9]{2}", "FN", "Z2F", "Z3F", "ZEA"),
LISTENING_MODE("[0-9]{4}", "SR"),
PLAYING_LISTENING_MODE("[0-9a-f]{4}", "LM"),
DISPLAY_INFORMATION("[0-9a-fA-F]{30}", "FL");
DISPLAY_INFORMATION("[0-9a-fA-F]{30}", "FL"),
MCACC_MEMORY("[1-6]{1}", "MC");
private String[] responsePrefixZone;

View File

@ -40,7 +40,9 @@ public class SimpleCommand implements AvrCommand {
INPUT_CHANGE_REVERSE("FD"),
LISTENING_MODE_CHANGE_CYCLIC("0010SR"),
LISTENING_MODE_QUERY("?S"),
INPUT_QUERY("?F", "?ZS", "?ZT", "?ZEA");
INPUT_QUERY("?F", "?ZS", "?ZT", "?ZEA"),
MCACC_MEMORY_CHANGE_CYCLIC("0MC"),
MCACC_MEMORY_QUERY("?MC");
private String zoneCommands[];
@ -48,6 +50,11 @@ public class SimpleCommand implements AvrCommand {
this.zoneCommands = command;
}
@Override
public String getCommand() {
return zoneCommands[0];
}
@Override
public String getCommand(int zone) {
return zoneCommands[zone - 1];
@ -62,8 +69,15 @@ public class SimpleCommand implements AvrCommand {
this.zone = zone;
}
public SimpleCommand(CommandType commandType) {
this(commandType, 0);
}
@Override
public String getCommand() {
if (zone == 0) {
return commandType.getCommand() + "\r";
}
return commandType.getCommand(zone) + "\r";
}

View File

@ -195,6 +195,11 @@ public abstract class StreamAvrConnection implements AvrConnection {
return sendCommand(RequestResponseFactory.getIpControlCommand(SimpleCommandType.LISTENING_MODE_QUERY, zone));
}
@Override
public boolean sendMCACCMemoryQuery() {
return sendCommand(RequestResponseFactory.getIpControlCommand(SimpleCommandType.MCACC_MEMORY_QUERY));
}
@Override
public boolean sendPowerCommand(Command command, int zone) throws CommandTypeNotSupportedException {
AvrCommand commandToSend = null;
@ -307,6 +312,23 @@ public abstract class StreamAvrConnection implements AvrConnection {
return sendCommand(commandToSend);
}
@Override
public boolean sendMCACCMemoryCommand(Command command) throws CommandTypeNotSupportedException {
AvrCommand commandToSend = null;
if (command == IncreaseDecreaseType.INCREASE) {
commandToSend = RequestResponseFactory.getIpControlCommand(SimpleCommandType.MCACC_MEMORY_CHANGE_CYCLIC);
} else if (command instanceof StringType) {
String MCACCMemoryValue = ((StringType) command).toString();
commandToSend = RequestResponseFactory.getIpControlCommand(ParameterizedCommandType.MCACC_MEMORY_SET)
.setParameter(MCACCMemoryValue);
} else {
throw new CommandTypeNotSupportedException("Command type not supported.");
}
return sendCommand(commandToSend);
}
/**
* Read incoming data from the AVR and notify listeners for dataReceived and disconnection.
*

View File

@ -23,6 +23,12 @@ public interface AvrCommand {
* Represent a CommandType of command requests
*/
public interface CommandType {
/**
* Return the command of this command type.
*
* @return
*/
public String getCommand();
/**
* Return the command of this command type for the given zone.

View File

@ -96,6 +96,13 @@ public interface AvrConnection {
*/
public boolean sendListeningModeQuery(int zone);
/**
* Send an MCACC Memory query to the AVR
*
* @return
*/
public boolean sendMCACCMemoryQuery();
/**
* Send a power command ot the AVR based on the openHAB command
*
@ -141,6 +148,15 @@ public interface AvrConnection {
*/
public boolean sendMuteCommand(Command command, int zone) throws CommandTypeNotSupportedException;
/**
* Send an MCACC Memory selection command to the AVR based on the openHAB command
*
* @param command
* @param zone
* @return
*/
public boolean sendMCACCMemoryCommand(Command command) throws CommandTypeNotSupportedException;
/**
* Return the connection name
*

View File

@ -14,6 +14,7 @@
<channel-groups>
<channel-group typeId="displayInformationGroup" id="displayInformation"/>
<channel-group typeId="MCACCMemoryGroup" id="MCACCMemory"/>
<channel-group typeId="zoneControls" id="zone1">
<label>Zone 1</label>
</channel-group>
@ -44,6 +45,7 @@
<description>Control a 2014 Pioneer AVR (SC-LX87, SC-LX77, SC-LX57, SC-2023, SC-1223, VSX-1123, VSX-923) over IP </description>
<channel-groups>
<channel-group typeId="displayInformationGroup" id="displayInformation"/>
<channel-group typeId="MCACCMemoryGroup" id="MCACCMemory"/>
<channel-group typeId="controls2014" id="zone1">
<label>Zone 1</label>
</channel-group>
@ -80,6 +82,7 @@
<channel-groups>
<channel-group typeId="displayInformationGroup" id="displayInformation"/>
<channel-group typeId="MCACCMemoryGroup" id="MCACCMemory"/>
<channel-group typeId="controls2015" id="zone1">
<label>Zone 1</label>
</channel-group>
@ -116,6 +119,7 @@
<channel-groups>
<channel-group typeId="displayInformationGroup" id="displayInformation"/>
<channel-group typeId="MCACCMemoryGroup" id="MCACCMemory"/>
<channel-group typeId="controls2016" id="zone1">
<label>Zone 1</label>
</channel-group>
@ -152,6 +156,7 @@
<channel-groups>
<channel-group typeId="displayInformationGroup" id="displayInformation"/>
<channel-group typeId="MCACCMemoryGroup" id="MCACCMemory"/>
<channel-group typeId="controls2017" id="zone1">
<label>Zone 1</label>
</channel-group>
@ -186,6 +191,7 @@
<channel-groups>
<channel-group typeId="displayInformationGroup" id="displayInformation"/>
<channel-group typeId="MCACCMemoryGroup" id="MCACCMemory"/>
<channel-group typeId="controls2018" id="zone1">
<label>Zone 1</label>
</channel-group>
@ -220,6 +226,7 @@
<channel-groups>
<channel-group typeId="displayInformationGroup" id="displayInformation"/>
<channel-group typeId="MCACCMemoryGroup" id="MCACCMemory"/>
<channel-group typeId="controls2019" id="zone1">
<label>Zone 1</label>
</channel-group>
@ -254,6 +261,7 @@
<channel-groups>
<channel-group typeId="displayInformationGroup" id="displayInformation"/>
<channel-group typeId="MCACCMemoryGroup" id="MCACCMemory"/>
<channel-group typeId="controls2020" id="zone1">
<label>Zone 1</label>
</channel-group>
@ -290,6 +298,7 @@
<channel-groups>
<channel-group typeId="displayInformationGroup" id="displayInformation"/>
<channel-group typeId="MCACCMemoryGroup" id="MCACCMemory"/>
<channel-group typeId="zoneControls" id="zone1"/>
<channel-group typeId="zoneControls" id="zone2"/>
<channel-group typeId="zoneControls" id="zone3"/>
@ -316,6 +325,7 @@
<channel-groups>
<channel-group typeId="displayInformationGroup" id="displayInformation"/>
<channel-group typeId="MCACCMemoryGroup" id="MCACCMemory"/>
<channel-group typeId="zone1Controls" id="zone1"/>
<channel-group typeId="zone2Controls" id="zone2"/>
<channel-group typeId="zone3Controls" id="zone3"/>
@ -338,6 +348,13 @@
</channels>
</channel-group-type>
<channel-group-type id="MCACCMemoryGroup">
<label>MCACC Memory</label>
<channels>
<channel id="MCACCMemory" typeId="setMCACCMemoryChannel"/>
</channels>
</channel-group-type>
<channel-group-type id="zoneControls">
<label>Zone Controls</label>
<channels>
@ -643,7 +660,7 @@
<label>Volume</label>
<description>Set the volume level (dB)</description>
<category>SoundVolume</category>
<state min="-80" max="12" step="0.5" pattern="%.1f dB"/>
<state min="-80" max="12" step="0.5" pattern="%.1f dB"></state>
</channel-type>
<channel-type id="muteChannel">
@ -1378,4 +1395,21 @@
<state readOnly="true"/>
</channel-type>
<channel-type id="setMCACCMemoryChannel">
<item-type>String</item-type>
<label>MCACC Memory</label>
<description>Set the MCACC Memory profile</description>
<state>
<options>
<option value="0000">MCACC MEMORY (cyclic)</option>
<option value="0001">MEMORY 1</option>
<option value="0002">MEMORY 2</option>
<option value="0003">MEMORY 3</option>
<option value="0004">MEMORY 4</option>
<option value="0005">MEMORY 5</option>
<option value="0006">MEMORY 6</option>
</options>
</state>
</channel-type>
</thing:thing-descriptions>