diff --git a/bundles/org.openhab.binding.sonos/README.md b/bundles/org.openhab.binding.sonos/README.md index 1b03e7af4..c3be76fa8 100644 --- a/bundles/org.openhab.binding.sonos/README.md +++ b/bundles/org.openhab.binding.sonos/README.md @@ -93,6 +93,12 @@ The devices support the following channels: | standalone | Switch | W | Make the Zone Player leave its Group and become a standalone Zone Player | all | | state | String | R | The State channel contains state of the Zone Player, e.g. PLAYING, STOPPED, ... | all | | stop | Switch | W | Write `ON` to this channel: Stops the Zone Player player. | all | +| subwoofer | Switch | RW | Enable or disable the subwoofer | Arc, Arc SL | +| subwoofergain | Number | RW | Set or get the subwoofer gain adjustment (value in range -15 / 15) | Arc, Arc SL | +| surround | Switch | RW | Enable or disable the surround audio | Arc, Arc SL | +| surroundmusicmode | String | RW | Set or get the surround playback mode for music, either 0 for Ambient or 1 for full | Arc, Arc SL | +| surroundmusiclevel | Number | RW | Set or get the surround level adjustment for music (value in range -15 / 15) | Arc, Arc SL | +| surroundtvlevel | Number | RW | Set or get the surround level adjustment for TV (value in range -15 / 15) | Arc, Arc SL | | tuneinstationid | String | RW | Provide the current TuneIn station id or play the TuneIn radio given by its station id | all | | volume | Dimmer | RW | Set or get the master volume of the Zone Player | all | | zonegroupid | String | R | Id of the Zone Group the Zone Player belongs to | all | 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 08d80138d..4cf948574 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 @@ -49,11 +49,13 @@ public class SonosBindingConstants { public static final ThingTypeUID CONNECTAMP_THING_TYPE_UID = new ThingTypeUID(BINDING_ID, "CONNECTAMP"); public static final ThingTypeUID AMP_THING_TYPE_UID = new ThingTypeUID(BINDING_ID, "Amp"); public static final ThingTypeUID SYMFONISK_THING_TYPE_UID = new ThingTypeUID(BINDING_ID, "SYMFONISK"); + public static final ThingTypeUID ARC_THING_TYPE_UID = new ThingTypeUID(BINDING_ID, "Arc"); + public static final ThingTypeUID ARC_SL_THING_TYPE_UID = new ThingTypeUID(BINDING_ID, "ArcSL"); public static final ThingTypeUID ZONEPLAYER_THING_TYPE_UID = new ThingTypeUID(BINDING_ID, "zoneplayer"); - public static final Set WITH_LINEIN_THING_TYPES_UIDS = Stream - .of(PLAY5_THING_TYPE_UID, PLAYBAR_THING_TYPE_UID, PLAYBASE_THING_TYPE_UID, BEAM_THING_TYPE_UID, - CONNECT_THING_TYPE_UID, CONNECTAMP_THING_TYPE_UID, PORT_THING_TYPE_UID) + public static final Set WITH_LINEIN_THING_TYPES_UIDS = Stream.of(PLAY5_THING_TYPE_UID, + PLAYBAR_THING_TYPE_UID, PLAYBASE_THING_TYPE_UID, BEAM_THING_TYPE_UID, CONNECT_THING_TYPE_UID, + CONNECTAMP_THING_TYPE_UID, PORT_THING_TYPE_UID, ARC_THING_TYPE_UID, ARC_SL_THING_TYPE_UID) .collect(Collectors.toSet()); public static final Set WITH_ANALOG_LINEIN_THING_TYPES_UIDS = Stream.of(AMP_THING_TYPE_UID) @@ -62,10 +64,11 @@ public class SonosBindingConstants { public static final Set WITH_DIGITAL_LINEIN_THING_TYPES_UIDS = Stream.of(AMP_THING_TYPE_UID) .collect(Collectors.toSet()); - public static final Set SUPPORTED_KNOWN_THING_TYPES_UIDS = Stream.of(ONE_THING_TYPE_UID, - ONE_SL_THING_TYPE_UID, PLAY1_THING_TYPE_UID, PLAY3_THING_TYPE_UID, PLAY5_THING_TYPE_UID, - PLAYBAR_THING_TYPE_UID, PLAYBASE_THING_TYPE_UID, BEAM_THING_TYPE_UID, CONNECT_THING_TYPE_UID, - CONNECTAMP_THING_TYPE_UID, PORT_THING_TYPE_UID, AMP_THING_TYPE_UID, SYMFONISK_THING_TYPE_UID) + public static final Set SUPPORTED_KNOWN_THING_TYPES_UIDS = Stream + .of(ONE_THING_TYPE_UID, ONE_SL_THING_TYPE_UID, PLAY1_THING_TYPE_UID, PLAY3_THING_TYPE_UID, + PLAY5_THING_TYPE_UID, PLAYBAR_THING_TYPE_UID, PLAYBASE_THING_TYPE_UID, BEAM_THING_TYPE_UID, + CONNECT_THING_TYPE_UID, CONNECTAMP_THING_TYPE_UID, PORT_THING_TYPE_UID, AMP_THING_TYPE_UID, + SYMFONISK_THING_TYPE_UID, ARC_THING_TYPE_UID, ARC_SL_THING_TYPE_UID) .collect(Collectors.toSet()); public static final Set SUPPORTED_THING_TYPES_UIDS = new HashSet<>(SUPPORTED_KNOWN_THING_TYPES_UIDS); @@ -120,6 +123,12 @@ public class SonosBindingConstants { public static final String STANDALONE = "standalone"; public static final String STATE = "state"; public static final String STOP = "stop"; + public static final String SUBWOOFER = "subwoofer"; + public static final String SUBWOOFERGAIN = "subwoofergain"; + public static final String SURROUND = "surround"; + public static final String SURROUNDMUSICMODE = "surroundmusicmode"; + public static final String SURROUNDMUSICLEVEL = "surroundmusiclevel"; + public static final String SURROUNDTVLEVEL = "surroundtvlevel"; public static final String TUNEINSTATIONID = "tuneinstationid"; public static final String VOLUME = "volume"; public static final String ZONEGROUPID = "zonegroupid"; diff --git a/bundles/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/internal/discovery/ZonePlayerDiscoveryParticipant.java b/bundles/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/internal/discovery/ZonePlayerDiscoveryParticipant.java index 4f6e27522..d4458d430 100644 --- a/bundles/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/internal/discovery/ZonePlayerDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/internal/discovery/ZonePlayerDiscoveryParticipant.java @@ -91,6 +91,9 @@ public class ZonePlayerDiscoveryParticipant implements UpnpDiscoveryParticipant case "One SL": modelName = "OneSL"; break; + case "Arc SL": + modelName = "ArcSL"; + break; default: break; } 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 15e87d0cc..bf1b9ad5c 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 @@ -111,6 +111,11 @@ public class ZonePlayerHandler extends BaseThingHandler implements UpnpIOPartici private static final int TUNEIN_DEFAULT_SERVICE_TYPE = 65031; + private static final int MIN_SUBWOOFER_GAIN = -15; + 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 final Logger logger = LoggerFactory.getLogger(ZonePlayerHandler.class); private final ThingRegistry localThingRegistry; @@ -259,6 +264,24 @@ public class ZonePlayerHandler extends BaseThingHandler implements UpnpIOPartici case VOLUME: setVolumeForGroup(command); break; + case SUBWOOFER: + setSubwoofer(command); + break; + case SUBWOOFERGAIN: + setSubwooferGain(command); + break; + case SURROUND: + setSurround(command); + break; + case SURROUNDMUSICMODE: + setSurroundMusicMode(command); + break; + case SURROUNDMUSICLEVEL: + setSurroundMusicLevel(command); + break; + case SURROUNDTVLEVEL: + setSurroundTvLevel(command); + break; case ADD: addMember(command); break; @@ -485,6 +508,24 @@ public class ZonePlayerHandler extends BaseThingHandler implements UpnpIOPartici case "MuteMaster": updateChannel(MUTE); break; + case "SubEnabled": + updateChannel(SUBWOOFER); + break; + case "SubGain": + updateChannel(SUBWOOFERGAIN); + break; + case "SurroundEnabled": + updateChannel(SURROUND); + break; + case "SurroundMode": + updateChannel(SURROUNDMUSICMODE); + break; + case "SurroundLevel": + updateChannel(SURROUNDTVLEVEL); + break; + case "MusicSurroundLevel": + updateChannel(SURROUNDMUSICLEVEL); + break; case "NightMode": updateChannel(NIGHTMODE); break; @@ -700,6 +741,42 @@ public class ZonePlayerHandler extends BaseThingHandler implements UpnpIOPartici newState = isMuted() ? OnOffType.ON : OnOffType.OFF; } break; + case SUBWOOFER: + value = getSubwooferEnabled(); + if (value != null) { + newState = OnOffType.from(value); + } + break; + case SUBWOOFERGAIN: + value = getSubwooferGain(); + if (value != null) { + newState = new DecimalType(value); + } + break; + case SURROUND: + value = getSurroundEnabled(); + if (value != null) { + newState = OnOffType.from(value); + } + break; + case SURROUNDMUSICMODE: + value = getSurroundMusicMode(); + if (value != null) { + newState = new StringType(value); + } + break; + case SURROUNDMUSICLEVEL: + value = getSurroundMusicLevel(); + if (value != null) { + newState = new DecimalType(value); + } + break; + case SURROUNDTVLEVEL: + value = getSurroundTvLevel(); + if (value != null) { + newState = new DecimalType(value); + } + break; case NIGHTMODE: value = getNightMode(); if (value != null) { @@ -1238,6 +1315,30 @@ public class ZonePlayerHandler extends BaseThingHandler implements UpnpIOPartici return stateMap.get("VolumeMaster"); } + public @Nullable String getSurroundEnabled() { + return stateMap.get("SurroundEnabled"); + } + + public @Nullable String getSurroundMusicMode() { + return stateMap.get("SurroundMode"); + } + + public @Nullable String getSurroundTvLevel() { + return stateMap.get("SurroundLevel"); + } + + public @Nullable String getSurroundMusicLevel() { + return stateMap.get("MusicSurroundLevel"); + } + + public @Nullable String getSubwooferEnabled() { + return stateMap.get("SubEnabled"); + } + + public @Nullable String getSubwooferGain() { + return stateMap.get("SubGain"); + } + public @Nullable String getTransportState() { return stateMap.get("TransportState"); } @@ -1844,17 +1945,65 @@ public class ZonePlayerHandler extends BaseThingHandler implements UpnpIOPartici } } + public void setSubwoofer(Command command) { + setEqualizerBooleanSetting(command, "SubEnabled"); + } + + public void setSubwooferGain(Command command) { + setEqualizerNumericSetting(command, "SubGain", getSubwooferGain(), MIN_SUBWOOFER_GAIN, MAX_SUBWOOFER_GAIN); + } + + public void setSurround(Command command) { + setEqualizerBooleanSetting(command, "SurroundEnabled"); + } + + public void setSurroundMusicMode(Command command) { + if (command instanceof StringType) { + setEQ("SurroundMode", command.toString()); + } + } + + public void setSurroundMusicLevel(Command command) { + setEqualizerNumericSetting(command, "MusicSurroundLevel", getSurroundMusicLevel(), MIN_SURROUND_LEVEL, + MAX_SURROUND_LEVEL); + } + + public void setSurroundTvLevel(Command command) { + setEqualizerNumericSetting(command, "SurroundLevel", getSurroundTvLevel(), MIN_SURROUND_LEVEL, + MAX_SURROUND_LEVEL); + } + public void setNightMode(Command command) { + setEqualizerBooleanSetting(command, "NightMode"); + } + + public void setSpeechEnhancement(Command command) { + setEqualizerBooleanSetting(command, "DialogLevel"); + } + + private void setEqualizerBooleanSetting(Command command, String eqType) { if (command instanceof OnOffType || command instanceof OpenClosedType || command instanceof UpDownType) { - setEQ("NightMode", (command.equals(OnOffType.ON) || command.equals(UpDownType.UP) + setEQ(eqType, (command.equals(OnOffType.ON) || command.equals(UpDownType.UP) || command.equals(OpenClosedType.OPEN)) ? "1" : "0"); } } - public void setSpeechEnhancement(Command command) { - if (command instanceof OnOffType || command instanceof OpenClosedType || command instanceof UpDownType) { - setEQ("DialogLevel", (command.equals(OnOffType.ON) || command.equals(UpDownType.UP) - || command.equals(OpenClosedType.OPEN)) ? "1" : "0"); + private void setEqualizerNumericSetting(Command command, String eqType, @Nullable String currentValue, int minValue, + int maxValue) { + if (command instanceof IncreaseDecreaseType || command instanceof DecimalType) { + String newValue = null; + if (command == IncreaseDecreaseType.INCREASE && currentValue != null) { + int i = Integer.valueOf(currentValue); + newValue = String.valueOf(Math.min(maxValue, i + 1)); + } else if (command == IncreaseDecreaseType.DECREASE && currentValue != null) { + int i = Integer.valueOf(currentValue); + newValue = String.valueOf(Math.max(minValue, i - 1)); + } else if (command instanceof DecimalType) { + newValue = String.valueOf(((DecimalType) command).intValue()); + } else { + return; + } + setEQ(eqType, newValue); } } 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 new file mode 100644 index 000000000..fa4cd8b90 --- /dev/null +++ b/bundles/org.openhab.binding.sonos/src/main/resources/OH-INF/thing/Arc.xml @@ -0,0 +1,77 @@ + + + + + + + Represents SONOS Arc soundbar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SONOS + Arc + + + udn + + + + 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 new file mode 100644 index 000000000..ea77c44eb --- /dev/null +++ b/bundles/org.openhab.binding.sonos/src/main/resources/OH-INF/thing/ArcSL.xml @@ -0,0 +1,77 @@ + + + + + + + Represents SONOS Arc SL soundbar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SONOS + Arc SL + + + udn + + + + 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 c6281e243..f826a671d 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 @@ -251,6 +251,51 @@ Stop the Zone Player. ON if the player is stopped. + + Switch + + Enable or disable the subwoofer + + + + Number + + Set or get the subwoofer gain adjustment + + + + + Switch + + Enable or disable the surround audio + + + + String + + Set or get the surround playback mode for music + + + + + + + + + + Number + + Set or get the surround level adjustment for music + + + + + Number + + Set or get the surround level adjustment for TV + + + String