]> git.basschouten.com Git - openhab-addons.git/commitdiff
[sonos] Add new channels for battery (Sonos Move) (#9998)
authorlolodomo <lg.hc@free.fr>
Sun, 31 Jan 2021 20:07:23 +0000 (21:07 +0100)
committerGitHub <noreply@github.com>
Sun, 31 Jan 2021 20:07:23 +0000 (21:07 +0100)
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
bundles/org.openhab.binding.sonos/README.md
bundles/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/internal/SonosBindingConstants.java
bundles/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/internal/handler/ZonePlayerHandler.java
bundles/org.openhab.binding.sonos/src/main/resources/OH-INF/thing/Move.xml
bundles/org.openhab.binding.sonos/src/main/resources/OH-INF/thing/channels.xml

index 081680c3d045225af8bc9e4e5b0e01649bf81839..b706f326098d59116567292f92511134e1dd90dc 100644 (file)
@@ -55,6 +55,8 @@ The devices support the following channels:
 | alarmproperties     | String    | R           | Properties of the alarm currently running                                                                                                                 | all                                  |
 | alarmrunning        | Switch    | R           | Set to ON if the alarm was triggered                                                                                                                      | all                                  |
 | bass                | Number    | RW          | Set or get the bass level adjustment (value in range -10 / 10)                                                                                            | all                                  |
+| 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                                  |
 | 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                                  |
index 5cb4daafd4d8dc95d69df80e4edbc0e865656aae..b437c0715ca90682ef106fe386b89af930c69443 100644 (file)
@@ -83,6 +83,8 @@ public class SonosBindingConstants {
     public static final String ALARMPROPERTIES = "alarmproperties";
     public static final String ALARMRUNNING = "alarmrunning";
     public static final String BASS = "bass";
+    public static final String BATTERYCHARGING = "batterycharging";
+    public static final String BATTERYLEVEL = "batterylevel";
     public static final String CLEARQUEUE = "clearqueue";
     public static final String CONTROL = "control";
     public static final String COORDINATOR = "coordinator";
index f335fc4cfcdaba6ad6dd453ae34e840125249846..e4b59fbb4b70d88c67ffcf5281ae047c4b1a00ae 100644 (file)
@@ -689,6 +689,10 @@ public class ZonePlayerHandler extends BaseThingHandler implements UpnpIOPartici
                         stateDescriptionProvider.setStateOptions(new ChannelUID(getThing().getUID(), RADIO), options);
                     }
                     break;
+                case "MoreInfo":
+                    updateChannel(BATTERYCHARGING);
+                    updateChannel(BATTERYLEVEL);
+                    break;
                 default:
                     break;
             }
@@ -957,6 +961,18 @@ public class ZonePlayerHandler extends BaseThingHandler implements UpnpIOPartici
                     newState = new StringType(value);
                 }
                 break;
+            case BATTERYCHARGING:
+                value = extractInfoFromMoreInfo("BattChg");
+                if (value != null) {
+                    newState = OnOffType.from("CHARGING".equalsIgnoreCase(value));
+                }
+                break;
+            case BATTERYLEVEL:
+                value = extractInfoFromMoreInfo("RawBattPct");
+                if (value != null) {
+                    newState = new DecimalType(value);
+                }
+                break;
             default:
                 newState = null;
                 break;
@@ -3225,4 +3241,18 @@ public class ZonePlayerHandler extends BaseThingHandler implements UpnpIOPartici
         int seconds = Integer.parseInt(units[2]);
         return 3600 * hours + 60 * minutes + seconds;
     }
+
+    private @Nullable String extractInfoFromMoreInfo(String searchedInfo) {
+        String value = stateMap.get("MoreInfo");
+        if (value != null) {
+            String[] fields = value.split(",");
+            for (int i = 0; i < fields.length; i++) {
+                String[] pair = fields[i].trim().split(":");
+                if (pair.length == 2 && searchedInfo.equalsIgnoreCase(pair[0].trim())) {
+                    return pair[1].trim();
+                }
+            }
+        }
+        return null;
+    }
 }
index e26a1c86c364c84363a211605166f73d0d1a617b..1bca40910cd1855606a4fcd3b130a00a69565a8a 100644 (file)
@@ -53,6 +53,9 @@
                        <channel id="sleeptimer" typeId="sleeptimer"/>
                        <channel id="currenttransporturi" typeId="currenttransporturi"/>
                        <channel id="currenttrackuri" typeId="currenttrackuri"/>
+                       <!-- Extended SONOS channels -->
+                       <channel id="batterycharging" typeId="batterycharging"/>
+                       <channel id="batterylevel" typeId="system.battery-level"/>
                </channels>
 
                <properties>
index eaaeaa44d88ce6e543a4db7af718aabdbb8ef0b3..6fc4cd4e01634934e174839cdd9f2595f0454c01 100644 (file)
                <description>Play the line-in of the the Zone Player corresponding to the given UIN</description>
        </channel-type>
 
+       <!-- Extended channels (for SONOS Move only) -->
+       <channel-type id="batterycharging" advanced="true">
+               <item-type>Switch</item-type>
+               <label>Battery Charging</label>
+               <description>Indicator set to ON when the battery is charging</description>
+               <state readOnly="true"/>
+       </channel-type>
+
 </thing:thing-descriptions>