]> git.basschouten.com Git - openhab-addons.git/commitdiff
[pioneeravr] Added channel for changing MCACC Memory profile on AVR (#10329)
authorNathan Prins <nathanprins@hotmail.com>
Wed, 31 Mar 2021 19:50:42 +0000 (12:50 -0700)
committerGitHub <noreply@github.com>
Wed, 31 Mar 2021 19:50:42 +0000 (21:50 +0200)
Signed-off-by: Nathan Prins <nathanprins@hotmail.com>
bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/PioneerAvrBindingConstants.java
bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/handler/AbstractAvrHandler.java
bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/ParameterizedCommand.java
bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/RequestResponseFactory.java
bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/Response.java
bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/SimpleCommand.java
bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/StreamAvrConnection.java
bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/avr/AvrCommand.java
bundles/org.openhab.binding.pioneeravr/src/main/java/org/openhab/binding/pioneeravr/internal/protocol/avr/AvrConnection.java
bundles/org.openhab.binding.pioneeravr/src/main/resources/OH-INF/thing/thing-types.xml

index eaa7d7770b18d84ca786a54468c78ed6bf1bbee4..ac152daae4c87e8f78a964fe937e1894efe08770 100644 (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])#.*");
index cd950ace3777fe3e37e1dc12afb1628a6e525850..11c04f94ba53abcfd801ee2dafdc8c058c8830e8 100644 (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.
      *
index 8502eef1cd286ccb61f0eda6e44f102b48e21962..ab3f55e371e77e33e34fca635f0eb84afcf64a6f 100644 (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();
index 130df2b48c77b3e666eb1aa948db0464f0fbaed2..56258ef124ace8f8f1139c4604affd89319a40f7 100644 (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
index e3b64497be23275417a53c3b5034bb7ce7832b98..1ca045c6fa71fbeaa86586735f09e01c29c99072 100644 (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;
 
index 839a4a160f32b81b231ba24ae4e78ea75bab4a1f..e04f06e239a9fde95d114c2ffd0a54338eb2f021 100644 (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";
     }
 
index df4893ad0eb1921cd81fff8cb344204a52882661..0c27977ae4d1438a676bbcf315905dcd000328e5 100644 (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.
      *
index 06a2e4ad40bff22832d88c9995bd4df261eba096..e3ccb125eaabe280d89c06de4c6c52dc98d9283d 100644 (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.
index edcda596121f7e09a799c1098315b1703d9cf0ed..ca09045e1fc805fc13acbd23a00d4483dee0d6e2 100644 (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
      *
index 982548115dd05ca4fc0df595dc22c5597ddb12d1..24efc93656023eb279095eafb56a3ed742d5c6fe 100644 (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>
 
                <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>
 
                <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>
 
                <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>
 
                <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>
 
                <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>
 
                <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"/>
 
                <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"/>
                </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>
                <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">
                <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>