Skip to content

Commit

Permalink
[sonos] Add new channel codec for several models (openhab#10979)
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Rosenblum <[email protected]>
  • Loading branch information
morph166955 authored and thinkingstone committed Nov 7, 2021
1 parent f02414a commit 38f5bc1
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions bundles/org.openhab.binding.sonos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ The devices support the following channels:
| batterycharging | Switch | R | Indicator set to ON when the battery is charging | Move |
| batterylevel | Number | R | Current battery level | Move |
| clearqueue | Switch | W | Suppress all songs from the current queue | all |
| codec | String | R | Name of codec currently being decoded | Arc, Arc SL, PLAYBAR, PLAYBASE, Beam, Amp |
| control | Player | RW | Control the Zone Player, e.g. PLAY/PAUSE/NEXT/PREVIOUS | all |
| coordinator | String | R | UDN of the coordinator for the current group | all |
| currentalbum | String | R | Name of the album currently playing | all |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public class SonosBindingConstants {
public static final String BATTERYCHARGING = "batterycharging";
public static final String BATTERYLEVEL = "batterylevel";
public static final String CLEARQUEUE = "clearqueue";
public static final String CODEC = "codec";
public static final String CONTROL = "control";
public static final String COORDINATOR = "coordinator";
public static final String CURRENTALBUM = "currentalbum";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,7 @@ public void startElement(@Nullable String uri, @Nullable String localName, @Null
case "SurroundEnabled":
case "SurroundMode":
case "SurroundLevel":
case "HTAudioIn":
case "MusicSurroundLevel":
case "HeightChannelLevel":
val = attributes == null ? null : attributes.getValue("val");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,9 @@ public void onValueReceived(@Nullable String variable, @Nullable String value, @
case "SurroundLevel":
updateChannel(SURROUNDTVLEVEL);
break;
case "HTAudioIn":
updateChannel(CODEC);
break;
case "MusicSurroundLevel":
updateChannel(SURROUNDMUSICLEVEL);
break;
Expand Down Expand Up @@ -881,6 +884,12 @@ protected void updateChannel(String channelId) {
newState = new DecimalType(value);
}
break;
case CODEC:
value = getCodec();
if (value != null) {
newState = new StringType(value);
}
break;
case HEIGHTLEVEL:
value = getHeightLevel();
if (value != null) {
Expand Down Expand Up @@ -1468,6 +1477,47 @@ public boolean isOutputLevelFixed() {
return stateMap.get("MusicSurroundLevel");
}

public @Nullable String getCodec() {
String codec = stateMap.get("HTAudioIn");
if (codec != null) {
switch (codec) {
case "0":
case "21":
codec = "noSignal";
break;
case "22":
case "33554454":
codec = "silence";
break;
case "32":
codec = "DTS";
break;
case "59":
case "63":
codec = "dolbyAtmos";
break;
case "33554434":
codec = "DD20";
break;
case "33554494":
codec = "PCM20";
break;
case "84934713":
codec = "DD51";
break;
case "84934714":
codec = "DDPlus51";
break;
case "84934718":
codec = "PCM51";
break;
default:
codec = "Unknown - " + codec;
}
}
return codec;
}

public @Nullable String getSubwooferEnabled() {
return stateMap.get("SubEnabled");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<channel id="currenttrackuri" typeId="currenttrackuri"/>
<!-- Extended SONOS channels -->
<channel id="analoglinein" typeId="linein"/>
<channel id="codec" typeId="codec"/>
<channel id="publicanalogaddress" typeId="publicaddress"/>
<channel id="digitallinein" typeId="linein"/>
<channel id="publicdigitaladdress" typeId="publicaddress"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<channel id="currenttransporturi" typeId="currenttransporturi"/>
<channel id="currenttrackuri" typeId="currenttrackuri"/>
<!-- Extended SONOS channels -->
<channel id="codec" typeId="codec"/>
<channel id="linein" typeId="linein"/>
<channel id="microphone" typeId="microphone"/>
<channel id="nightmode" typeId="nightmode"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<channel id="currenttransporturi" typeId="currenttransporturi"/>
<channel id="currenttrackuri" typeId="currenttrackuri"/>
<!-- Extended SONOS channels -->
<channel id="codec" typeId="codec"/>
<channel id="linein" typeId="linein"/>
<channel id="nightmode" typeId="nightmode"/>
<channel id="speechenhancement" typeId="speechenhancement"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<channel id="currenttransporturi" typeId="currenttransporturi"/>
<channel id="currenttrackuri" typeId="currenttrackuri"/>
<!-- Extended SONOS channels -->
<channel id="codec" typeId="codec"/>
<channel id="linein" typeId="linein"/>
<channel id="microphone" typeId="microphone"/>
<channel id="nightmode" typeId="nightmode"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<channel id="currenttransporturi" typeId="currenttransporturi"/>
<channel id="currenttrackuri" typeId="currenttrackuri"/>
<!-- Extended SONOS channels -->
<channel id="codec" typeId="codec"/>
<channel id="linein" typeId="linein"/>
<channel id="nightmode" typeId="nightmode"/>
<channel id="speechenhancement" typeId="speechenhancement"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<channel id="currenttransporturi" typeId="currenttransporturi"/>
<channel id="currenttrackuri" typeId="currenttrackuri"/>
<!-- Extended SONOS channels -->
<channel id="codec" typeId="codec"/>
<channel id="linein" typeId="linein"/>
<channel id="nightmode" typeId="nightmode"/>
<channel id="speechenhancement" typeId="speechenhancement"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@
<description>Suppress all songs from the current queue</description>
</channel-type>

<channel-type id="codec" advanced="true">
<item-type>String</item-type>
<label>Codec</label>
<description>Name of codec currently being decoded</description>
<state readOnly="true">
<options>
<option value="noSignal">No Signal</option>
<option value="silence">Silence</option>
<option value="DTS">DTS</option>
<option value="dolbyAtmos">Dolby Atmos</option>
<option value="DD20">Dolby Digital 2.0</option>
<option value="PCM20">Dolby Multichannel PCM 2.0</option>
<option value="DD51">Dolby Digital 5.1</option>
<option value="DDPlus51">Dolby Digital Plus 5.1</option>
<option value="PCM51">Dolby Multichannel PCM 5.1</option>
</options>
<limitToOptions>false</limitToOptions>
</state>
</channel-type>

<channel-type id="coordinator" advanced="true">
<item-type>String</item-type>
<label>Coordinator</label>
Expand Down

0 comments on commit 38f5bc1

Please sign in to comment.