From b9fe3bef048bab06c1ab28d85e0039c21d26eb11 Mon Sep 17 00:00:00 2001 From: Nathan Prins Date: Wed, 31 Mar 2021 12:50:42 -0700 Subject: [PATCH] [pioneeravr] Added channel for changing MCACC Memory profile on AVR (#10329) Signed-off-by: Nathan Prins --- .../internal/PioneerAvrBindingConstants.java | 1 + .../internal/handler/AbstractAvrHandler.java | 27 +++++++++++++ .../protocol/ParameterizedCommand.java | 12 +++++- .../protocol/RequestResponseFactory.java | 40 ++++++++++++++++++- .../internal/protocol/Response.java | 3 +- .../internal/protocol/SimpleCommand.java | 16 +++++++- .../protocol/StreamAvrConnection.java | 22 ++++++++++ .../internal/protocol/avr/AvrCommand.java | 6 +++ .../internal/protocol/avr/AvrConnection.java | 16 ++++++++ .../resources/OH-INF/thing/thing-types.xml | 36 ++++++++++++++++- 10 files changed, 174 insertions(+), 5 deletions(-) diff --git a/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/PioneerAvrBindingConstants.java b/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/PioneerAvrBindingConstants.java index eaa7d7770..ac152daae 100644 --- a/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/PioneerAvrBindingConstants.java +++ b/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/PioneerAvrBindingConstants.java @@ -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])#.*"); diff --git a/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/handler/AbstractAvrHandler.java b/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/handler/AbstractAvrHandler.java index cd950ace3..11c04f94b 100644 --- a/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/handler/AbstractAvrHandler.java +++ b/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/handler/AbstractAvrHandler.java @@ -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. * diff --git a/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/ParameterizedCommand.java b/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/ParameterizedCommand.java index 8502eef1c..ab3f55e37 100644 --- a/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/ParameterizedCommand.java +++ b/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/ParameterizedCommand.java @@ -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(); diff --git a/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/RequestResponseFactory.java b/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/RequestResponseFactory.java index 130df2b48..56258ef12 100644 --- a/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/RequestResponseFactory.java +++ b/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/RequestResponseFactory.java @@ -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 diff --git a/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/Response.java b/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/Response.java index e3b64497b..1ca045c6f 100644 --- a/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/Response.java +++ b/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/Response.java @@ -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; diff --git a/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/SimpleCommand.java b/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/SimpleCommand.java index 839a4a160..e04f06e23 100644 --- a/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/SimpleCommand.java +++ b/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/SimpleCommand.java @@ -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"; } diff --git a/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/StreamAvrConnection.java b/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/StreamAvrConnection.java index df4893ad0..0c27977ae 100644 --- a/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/StreamAvrConnection.java +++ b/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/StreamAvrConnection.java @@ -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. * diff --git a/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/avr/AvrCommand.java b/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/avr/AvrCommand.java index 06a2e4ad4..e3ccb125e 100644 --- a/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/avr/AvrCommand.java +++ b/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/avr/AvrCommand.java @@ -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. diff --git a/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/avr/AvrConnection.java b/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/avr/AvrConnection.java index edcda5961..ca09045e1 100644 --- a/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/avr/AvrConnection.java +++ b/bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/avr/AvrConnection.java @@ -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 * diff --git a/bundles/org.openhab.binding.pioneeravr/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.pioneeravr/src/main/resources/OH-INF/thing/thing-types.xml index 982548115..24efc9365 100644 --- a/bundles/org.openhab.binding.pioneeravr/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.pioneeravr/src/main/resources/OH-INF/thing/thing-types.xml @@ -14,6 +14,7 @@ + @@ -44,6 +45,7 @@ Control a 2014 Pioneer AVR (SC-LX87, SC-LX77, SC-LX57, SC-2023, SC-1223, VSX-1123, VSX-923) over IP + @@ -80,6 +82,7 @@ + @@ -116,6 +119,7 @@ + @@ -152,6 +156,7 @@ + @@ -186,6 +191,7 @@ + @@ -220,6 +226,7 @@ + @@ -254,6 +261,7 @@ + @@ -290,6 +298,7 @@ + @@ -316,6 +325,7 @@ + @@ -338,6 +348,13 @@ + + + + + + + @@ -643,7 +660,7 @@ Set the volume level (dB) SoundVolume - + @@ -1378,4 +1395,21 @@ + + String + + Set the MCACC Memory profile + + + + + + + + + + + + +