From 9bf194ad39498224308090b062b5fdd5039d9f50 Mon Sep 17 00:00:00 2001 From: lolodomo Date: Fri, 28 May 2021 15:04:14 +0200 Subject: [PATCH] [sonos] Add new channel heightlevel for Sonos ARC / ARC SL (#10759) Fix #9874 Signed-off-by: Laurent Garnier --- bundles/org.openhab.binding.sonos/README.md | 1 + .../sonos/internal/SonosBindingConstants.java | 1 + .../sonos/internal/SonosXMLParser.java | 1 + .../internal/handler/ZonePlayerHandler.java | 22 +++++++++++++++++++ .../src/main/resources/OH-INF/thing/Arc.xml | 1 + .../src/main/resources/OH-INF/thing/ArcSL.xml | 1 + .../main/resources/OH-INF/thing/channels.xml | 7 ++++++ 7 files changed, 34 insertions(+) diff --git a/bundles/org.openhab.binding.sonos/README.md b/bundles/org.openhab.binding.sonos/README.md index fb19d071f..ce04191f2 100644 --- a/bundles/org.openhab.binding.sonos/README.md +++ b/bundles/org.openhab.binding.sonos/README.md @@ -69,6 +69,7 @@ The devices support the following channels: | currenttrackuri | String | R | URI of the current track | all | | currenttransporturi | String | R | URI of the current AV transport | all | | favorite | String | W | Play the given favorite entry. The favorite entry has to be predefined in the Sonos Controller app | all | +| heightlevel | Number | RW | Set or get the height level adjustment (value in range -10 / 10) | Arc, Arc SL | | led | Switch | RW | Set or get the status of the white LED on the front of the Zone Player | all | | linein | Switch | R | Indicator set to ON when the line-in of the Zone Player is connected | PLAY5, CONNECT, CONNECTAMP, PLAYBAR, PLAYBASE, Beam, Port | | analoglinein | Switch | R | Indicator set to ON when the analog line-in of the Zone Player is connected | Amp | diff --git a/bundles/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/internal/SonosBindingConstants.java b/bundles/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/internal/SonosBindingConstants.java index bdde54877..b54dcdf9e 100644 --- a/bundles/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/internal/SonosBindingConstants.java +++ b/bundles/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/internal/SonosBindingConstants.java @@ -98,6 +98,7 @@ public class SonosBindingConstants { public static final String CURRENTTRACKURI = "currenttrackuri"; public static final String CURRENTTRANSPORTURI = "currenttransporturi"; public static final String FAVORITE = "favorite"; + public static final String HEIGHTLEVEL = "heightlevel"; public static final String LED = "led"; public static final String LINEIN = "linein"; public static final String ANALOGLINEIN = "analoglinein"; diff --git a/bundles/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/internal/SonosXMLParser.java b/bundles/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/internal/SonosXMLParser.java index c152c59b5..735a75258 100644 --- a/bundles/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/internal/SonosXMLParser.java +++ b/bundles/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/internal/SonosXMLParser.java @@ -877,6 +877,7 @@ public class SonosXMLParser { case "SurroundMode": case "SurroundLevel": case "MusicSurroundLevel": + case "HeightChannelLevel": val = attributes == null ? null : attributes.getValue("val"); if (val != null) { changes.put(qName, val); diff --git a/bundles/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/internal/handler/ZonePlayerHandler.java b/bundles/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/internal/handler/ZonePlayerHandler.java index e0043c208..10a52c983 100644 --- a/bundles/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/internal/handler/ZonePlayerHandler.java +++ b/bundles/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/internal/handler/ZonePlayerHandler.java @@ -162,6 +162,8 @@ public class ZonePlayerHandler extends BaseThingHandler implements UpnpIOPartici private static final int MAX_SUBWOOFER_GAIN = 15; private static final int MIN_SURROUND_LEVEL = -15; private static final int MAX_SURROUND_LEVEL = 15; + private static final int MIN_HEIGHT_LEVEL = -10; + private static final int MAX_HEIGHT_LEVEL = 10; private final Logger logger = LoggerFactory.getLogger(ZonePlayerHandler.class); @@ -338,6 +340,9 @@ public class ZonePlayerHandler extends BaseThingHandler implements UpnpIOPartici case SURROUNDTVLEVEL: setSurroundTvLevel(command); break; + case HEIGHTLEVEL: + setHeightLevel(command); + break; case ADD: addMember(command); break; @@ -596,6 +601,9 @@ public class ZonePlayerHandler extends BaseThingHandler implements UpnpIOPartici case "MusicSurroundLevel": updateChannel(SURROUNDMUSICLEVEL); break; + case "HeightChannelLevel": + updateChannel(HEIGHTLEVEL); + break; case "NightMode": updateChannel(NIGHTMODE); break; @@ -873,6 +881,12 @@ public class ZonePlayerHandler extends BaseThingHandler implements UpnpIOPartici newState = new DecimalType(value); } break; + case HEIGHTLEVEL: + value = getHeightLevel(); + if (value != null) { + newState = new DecimalType(value); + } + break; case NIGHTMODE: value = getNightMode(); if (value != null) { @@ -1462,6 +1476,10 @@ public class ZonePlayerHandler extends BaseThingHandler implements UpnpIOPartici return stateMap.get("SubGain"); } + public @Nullable String getHeightLevel() { + return stateMap.get("HeightChannelLevel"); + } + public @Nullable String getTransportState() { return stateMap.get("TransportState"); } @@ -2079,6 +2097,10 @@ public class ZonePlayerHandler extends BaseThingHandler implements UpnpIOPartici MAX_SURROUND_LEVEL); } + public void setHeightLevel(Command command) { + setEqualizerNumericSetting(command, "HeightChannelLevel", getHeightLevel(), MIN_HEIGHT_LEVEL, MAX_HEIGHT_LEVEL); + } + public void setNightMode(Command command) { setEqualizerBooleanSetting(command, "NightMode"); } diff --git a/bundles/org.openhab.binding.sonos/src/main/resources/OH-INF/thing/Arc.xml b/bundles/org.openhab.binding.sonos/src/main/resources/OH-INF/thing/Arc.xml index 571c3ae23..b3ac01b72 100644 --- a/bundles/org.openhab.binding.sonos/src/main/resources/OH-INF/thing/Arc.xml +++ b/bundles/org.openhab.binding.sonos/src/main/resources/OH-INF/thing/Arc.xml @@ -67,6 +67,7 @@ + diff --git a/bundles/org.openhab.binding.sonos/src/main/resources/OH-INF/thing/ArcSL.xml b/bundles/org.openhab.binding.sonos/src/main/resources/OH-INF/thing/ArcSL.xml index 38103bf8a..790560447 100644 --- a/bundles/org.openhab.binding.sonos/src/main/resources/OH-INF/thing/ArcSL.xml +++ b/bundles/org.openhab.binding.sonos/src/main/resources/OH-INF/thing/ArcSL.xml @@ -66,6 +66,7 @@ + diff --git a/bundles/org.openhab.binding.sonos/src/main/resources/OH-INF/thing/channels.xml b/bundles/org.openhab.binding.sonos/src/main/resources/OH-INF/thing/channels.xml index 1409838e4..1f27fc47a 100644 --- a/bundles/org.openhab.binding.sonos/src/main/resources/OH-INF/thing/channels.xml +++ b/bundles/org.openhab.binding.sonos/src/main/resources/OH-INF/thing/channels.xml @@ -100,6 +100,13 @@ Play the given favorite entry. The favorite entry has to be predefined in the Sonos Controller app + + Number + + Set or get the height level adjustment + + + Switch