]> git.basschouten.com Git - openhab-addons.git/commitdiff
[yamahareceiver] Add possiblity to switch HDMI outputs on and off on Yamaha receivers...
authorfragger42 <58386643+fragger42@users.noreply.github.com>
Sat, 31 Jul 2021 09:52:45 +0000 (11:52 +0200)
committerGitHub <noreply@github.com>
Sat, 31 Jul 2021 09:52:45 +0000 (11:52 +0200)
* Add possiblity to switch HDMI outputs on and off on Yamaha receivers
(openhab#6327)

Signed-off-by: Bernhard Gruber <b-gruber@gmx.de>
bundles/org.openhab.binding.yamahareceiver/README.md
bundles/org.openhab.binding.yamahareceiver/src/main/java/org/openhab/binding/yamahareceiver/internal/YamahaReceiverBindingConstants.java
bundles/org.openhab.binding.yamahareceiver/src/main/java/org/openhab/binding/yamahareceiver/internal/handler/YamahaZoneThingHandler.java
bundles/org.openhab.binding.yamahareceiver/src/main/java/org/openhab/binding/yamahareceiver/internal/protocol/ZoneControl.java
bundles/org.openhab.binding.yamahareceiver/src/main/java/org/openhab/binding/yamahareceiver/internal/protocol/xml/ZoneControlXML.java
bundles/org.openhab.binding.yamahareceiver/src/main/java/org/openhab/binding/yamahareceiver/internal/state/ZoneControlState.java
bundles/org.openhab.binding.yamahareceiver/src/main/resources/OH-INF/thing/thing-types.xml

index d72e9834e7a0248c7518e001b3d503e822486316..b4656f8323632b825e48a7ef87a33943eea42b10 100644 (file)
@@ -79,6 +79,8 @@ Zone control channels are:
 | `zone_channels#surroundProgram`               | `String`     | Sets the surround mode. Examples: `2ch Stereo`, `7ch Stereo`, `Hall in Munic`, `Straight`, `Surround Decoder`.                                                                                                                                                                                                                                                                                                                          |
 | `zone_channels#scene`                         | `String`     | Sets the scene. Examples: `Scene 1`, `Scene 2`, `Scene 3`, `Scene 4`. Write only (state updates are not available). May not be supported on all models (e.g. RX-V3900).                                                                                                                                                                                                                                                                 |
 | `zone_channels#dialogueLevel`                 | `Number`     | Sets the receivers dialogue level. May not be supported on all models.                                                                                                                                                                                                                                                                                                                                                                  |
+| `zone_channels#hdmi1Out`                      | `Number`     | Switches the HDMI1 Output ON or OFF (channel in desc.xml is placed in Main_Zone but in fact it is more some kind of system parameter). May not be supported on all models.                                                                                                                                                                                                                                                              |
+| `zone_channels#hdmi2Out`                      | `Number`     | Switches the HDMI2 Output ON or OFF (channel is desc.xml is placed in Main_Zone but in fact it is more some kind of system parameter). May not be supported on all models.                                                                                                                                                                                                                                                              |
 | `playback_channels#preset`                    | `Number`     | Set a preset. Not supported by `Spotify` input. For `NET RADIO` input there is no way to get current preset (tested on RX-S601D, RX-V3900), so the preset is write only. For RX-V3900 the presets are alphanumeric `A1`,`A2`,`B1`,`B2` thus you need to use numbers grater than 100 that represent these presets as follows: 101, 102, 201, 202.                                                                                        |
 | `playback_channels#playback`                  | `String`     | Set a play mode or get the current play mode. Values supported: `Previous`, `Play`, `Pause`, `Stop`, `Next`. Applies for inputs which support playback (`Spotify`, `SERVER`, `NET RADIO`, `Bluetooth`). Note that some values may not be supported on certain input type and AVR model combination. For `Spotify` and `Bluetooth` all values work, but for `NET RADIO` input only `Play` and `Stop` are supported (tested on RX-S601D). |
 | `playback_channels#playback_station`          | `String`     | Get the current played station (radio). Applies to `TUNER` and `NET RADIO` inputs only.                                                                                                                                                                                                                                                                                                                                                 |
@@ -134,6 +136,8 @@ String      Yamaha_Input           "Input [%s]"                <video>
 String      Yamaha_Surround        "Surround [%s]"             <video>              { channel="yamahareceiver:zone:96a40ba9:Main_Zone:zone_channels#surroundProgram" }
 String      Yamaha_Scene           "Scene []"                  <video>              { channel="yamahareceiver:zone:96a40ba9:Main_Zone:zone_channels#scene" }
 Switch      Yamaha_Dialogue_Level  "Dialogue Level [%d]"       <soundvolume>        { channel="yamahareceiver:zone:96a40ba9:Main_Zone:zone_channels#dialogueLevel" }
+Switch      Yamaha_HDMI1_Output    "HDMI1 Output [%s]"          <switch>             { channel="yamahareceiver:zone:96a40ba9:Main_Zone:zone_channels#hdmi1Out" }
+Switch      Yamaha_HDMI2_Output    "HDMI2 Output [%s]"          <switch>             { channel="yamahareceiver:zone:96a40ba9:Main_Zone:zone_channels#hdmi2Out" }
 
 Switch      Yamaha_PartyMode       "Party mode [%s]"           <switch>             { channel="yamahareceiver:yamahaAV:96a40ba9:party_mode" }
 Switch      Yamaha_PartyModeMute   "Party mode mute [%s]"      <soundvolume_mute>   { channel="yamahareceiver:yamahaAV:96a40ba9:party_mode_mute" }
@@ -150,6 +154,8 @@ Selection   item=Yamaha_Input            mappings=[HDMI1="Kodi",HDMI2="PC",AUDIO
 Selection   item=Yamaha_Surround         mappings=["2ch Stereo"="2ch Stereo","5ch Stereo"="5ch Stereo","Chamber"="Chamber","Sci-Fi"="Sci-Fi","Adventure"="Adventure"]
 Switch      item=Yamaha_Scene            mappings=["Scene 1"="Kodi","Scene 2"="TV","Scene 3"="NET","Scene 4"="Radio"]
 Setpoint    item=Yamaha_Dialogue_Level   minValue=0 maxValue=2 step=1
+Switch      item=Yamaha_HDMI1_Output
+Switch      item=Yamaha_HDMI2_Output
 
 Switch      item=Yamaha_PartyMode
 Switch      item=Yamaha_PartyModeMute
index 106819f64399be8b080f6390239c6aa002c0224c..f321811558fe667c2410dd31cad81bb4b17e19f9 100644 (file)
@@ -48,6 +48,8 @@ public class YamahaReceiverBindingConstants {
     public static final String CHANNEL_MUTE = "mute";
     public static final String CHANNEL_SCENE = "scene";
     public static final String CHANNEL_DIALOGUE_LEVEL = "dialogueLevel";
+    public static final String CHANNEL_HDMI1OUT = "hdmi1Out";
+    public static final String CHANNEL_HDMI2OUT = "hdmi2Out";
 
     public static final String CHANNEL_PARTY_MODE = "party_mode";
     public static final String CHANNEL_PARTY_MODE_MUTE = "party_mode_mute";
index 00758ee864a8849e9cf8784efb10803faabcfffb..7f1ea33d710c300340237b81c63a4a30cc59a540 100644 (file)
@@ -305,6 +305,14 @@ public class YamahaZoneThingHandler extends BaseThingHandler
                     zoneControl.setDialogueLevel(((DecimalType) command).intValue());
                     break;
 
+                case CHANNEL_HDMI1OUT:
+                    zoneControl.setHDMI1Out(((OnOffType) command) == OnOffType.ON);
+                    break;
+
+                case CHANNEL_HDMI2OUT:
+                    zoneControl.setHDMI2Out(((OnOffType) command) == OnOffType.ON);
+                    break;
+
                 case CHANNEL_NAVIGATION_MENU:
                     if (inputWithNavigationControl == null) {
                         logger.warn("Channel {} not working with {} input!", id, zoneState.inputID);
@@ -491,6 +499,10 @@ public class YamahaZoneThingHandler extends BaseThingHandler
             // no state updates available
         } else if (id.equals(grpZone(CHANNEL_DIALOGUE_LEVEL))) {
             updateState(channelUID, new DecimalType(zoneState.dialogueLevel));
+        } else if (id.equals(grpZone(CHANNEL_HDMI1OUT))) {
+            updateState(channelUID, zoneState.hdmi1Out ? OnOffType.ON : OnOffType.OFF);
+        } else if (id.equals(grpZone(CHANNEL_HDMI2OUT))) {
+            updateState(channelUID, zoneState.hdmi2Out ? OnOffType.ON : OnOffType.OFF);
 
         } else if (id.equals(grpPlayback(CHANNEL_PLAYBACK))) {
             updateState(channelUID, new StringType(playInfoState.playbackMode));
@@ -536,6 +548,8 @@ public class YamahaZoneThingHandler extends BaseThingHandler
         updateState(grpZone(CHANNEL_VOLUME), new PercentType((int) zoneConfig.getVolumePercentage(zoneState.volumeDB)));
         updateState(grpZone(CHANNEL_MUTE), zoneState.mute ? OnOffType.ON : OnOffType.OFF);
         updateState(grpZone(CHANNEL_DIALOGUE_LEVEL), new DecimalType(zoneState.dialogueLevel));
+        updateState(grpZone(CHANNEL_HDMI1OUT), zoneState.hdmi1Out ? OnOffType.ON : OnOffType.OFF);
+        updateState(grpZone(CHANNEL_HDMI2OUT), zoneState.hdmi2Out ? OnOffType.ON : OnOffType.OFF);
 
         // If the input changed
         if (inputChanged) {
index 6b3a7b32038582121e698988f26bb5eeb66140c9..b21b1295262b32f22d0136e3d35f6cca98fba7b1 100644 (file)
@@ -64,6 +64,26 @@ public interface ZoneControl extends IStateUpdatable {
 
     void setDialogueLevel(int level) throws IOException, ReceivedMessageParseException;
 
+    /**
+     * Switches the HDMI1 output on or off.
+     *
+     * @param on The new state
+     *
+     * @throws IOException
+     * @throws ReceivedMessageParseException
+     */
+    void setHDMI1Out(boolean on) throws IOException, ReceivedMessageParseException;
+
+    /**
+     * Switches the HDMI2 output on or off.
+     *
+     * @param on The new state
+     *
+     * @throws IOException
+     * @throws ReceivedMessageParseException
+     */
+    void setHDMI2Out(boolean on) throws IOException, ReceivedMessageParseException;
+
     /**
      * Sets the active scene for the zone.
      *
index 5a43d6f0ecf08a8be854c190203e7878ac88afca..36e97ba4d213e99fbadac2e7d264a02f432e191d 100644 (file)
@@ -77,7 +77,15 @@ public class ZoneControlXML implements ZoneControl {
     protected CommandTemplate dialogueLevel = new CommandTemplate(
             "<Sound_Video><Dialogue_Adjust><Dialogue_Lvl>%d</Dialogue_Lvl></Dialogue_Adjust></Sound_Video>",
             "Sound_Video/Dialogue_Adjust/Dialogue_Lvl");
+    protected CommandTemplate hdmi1Out = new CommandTemplate(
+            "<System><Sound_Video><HDMI><Output><OUT_1>%s</OUT_1></Output></HDMI></Sound_Video></System>",
+            "Sound_Video/HDMI/Output/OUT_1");
+    protected CommandTemplate hdmi2Out = new CommandTemplate(
+            "<System><Sound_Video><HDMI><Output><OUT_2>%s</OUT_2></Output></HDMI></Sound_Video></System>",
+            "Sound_Video/HDMI/Output/OUT_2");
     protected boolean dialogueLevelSupported = false;
+    protected boolean hdmi1OutSupported = false;
+    protected boolean hdmi2OutSupported = false;
 
     public ZoneControlXML(AbstractConnection con, Zone zone, YamahaZoneConfig zoneSettings,
             ZoneControlStateListener observer, DeviceInformationState deviceInformationState,
@@ -118,6 +126,12 @@ public class ZoneControlXML implements ZoneControl {
             logger.debug("Zone {} - the {} channel is not supported on your model", getZone(), CHANNEL_DIALOGUE_LEVEL);
         }
 
+        hdmi1OutSupported = zoneDescriptor.hasCommandEnding("Sound_Video,HDMI,Output,OUT_1", () -> logger
+                .debug("Zone {} - the {} channel is not supported on your model", getZone(), CHANNEL_HDMI1OUT));
+
+        hdmi2OutSupported = zoneDescriptor.hasCommandEnding("Sound_Video,HDMI,Output,OUT_2", () -> logger
+                .debug("Zone {} - the {} channel is not supported on your model", getZone(), CHANNEL_HDMI2OUT));
+
         // Note: Detection for RX-V3900, which uses <Vol> instead of <Volume>
         if (zoneDescriptor.hasCommandEnding("Vol,Lvl")) {
             volume = volume.replace("Volume", "Vol");
@@ -153,6 +167,10 @@ public class ZoneControlXML implements ZoneControl {
         comReference.get().send(XMLUtils.wrZone(zone, message));
     }
 
+    protected void sendCommandWithoutZone(String message) throws IOException {
+        comReference.get().send(message);
+    }
+
     /**
      * Return the zone
      */
@@ -253,6 +271,24 @@ public class ZoneControlXML implements ZoneControl {
         update();
     }
 
+    @Override
+    public void setHDMI1Out(boolean on) throws IOException, ReceivedMessageParseException {
+        if (!hdmi1OutSupported) {
+            return;
+        }
+        sendCommandWithoutZone(hdmi1Out.apply(on ? ON : OFF));
+        update();
+    }
+
+    @Override
+    public void setHDMI2Out(boolean on) throws IOException, ReceivedMessageParseException {
+        if (!hdmi2OutSupported) {
+            return;
+        }
+        sendCommandWithoutZone(hdmi2Out.apply(on ? ON : OFF));
+        update();
+    }
+
     @Override
     public void setScene(String scene) throws IOException, ReceivedMessageParseException {
         if (!sceneSelSupported) {
@@ -290,6 +326,12 @@ public class ZoneControlXML implements ZoneControl {
             throw new ReceivedMessageParseException("Expected inputID. Failed to read Input/Input_Sel");
         }
 
+        value = getNodeContentOrEmpty(statusNode, hdmi1Out.getPath());
+        state.hdmi1Out = ON.equalsIgnoreCase(value);
+
+        value = getNodeContentOrEmpty(statusNode, hdmi1Out.getPath());
+        state.hdmi2Out = ON.equalsIgnoreCase(value);
+
         // Some receivers may use Src_Name instead?
         value = getNodeContentOrEmpty(statusNode, inputSelNamePath);
         state.inputName = value;
index 22803f76008877eeefd5234093018d138663a2bc..58c343bb12d9255753353287009524552755e332 100644 (file)
@@ -30,4 +30,6 @@ public class ZoneControlState {
     public float volumeDB = 0.0f; // volume in dB
     public boolean mute = false;
     public int dialogueLevel = 0;
+    public boolean hdmi1Out = false;
+    public boolean hdmi2Out = false;
 }
index 3217a76a26e8b1c0597a5344ea77c1bb0656d557..c647e719b3dfc8f0f2a13d78b33fcdb1463a47f2 100644 (file)
                        <channel id="volume" typeId="volume"/>
                        <channel id="volumeDB" typeId="volumeDB"/>
                        <channel id="dialogueLevel" typeId="dialogueLevel"/>
+                       <channel id="hdmi1Out" typeId="hdmi1Out"/>
+                       <channel id="hdmi2Out" typeId="hdmi2Out"/>
                        <channel id="mute" typeId="mute"/>
                        <channel id="scene" typeId="scene"/>
                </channels>
                <state min="0" max="2" step="1" pattern="%d"/>
        </channel-type>
 
+       <channel-type id="hdmi1Out">
+               <item-type>Switch</item-type>
+               <label>HDMI1 Output</label>
+               <description>Switch the HDMI1 Output ON/OFF</description>
+               <category>switch</category>
+       </channel-type>
+
+       <channel-type id="hdmi2Out">
+               <item-type>Switch</item-type>
+               <label>HDMI2 Output</label>
+               <description>Switch the HDMI2 Output ON/OFF</description>
+               <category>switch</category>
+       </channel-type>
+
        <channel-type id="scene">
                <item-type>String</item-type>
                <label>Scene</label>