]> git.basschouten.com Git - openhab-addons.git/commitdiff
[lgwebos] Fix Volume Subscription on newer LGWebOS TVs which report volumeStatus...
authorSebastian Prehn <2531264+sprehn@users.noreply.github.com>
Fri, 11 Dec 2020 21:11:31 +0000 (22:11 +0100)
committerGitHub <noreply@github.com>
Fri, 11 Dec 2020 21:11:31 +0000 (13:11 -0800)
Signed-off-by: Sebastian Prehn <sebastian.prehn@gmx.de>
bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/LGWebOSTVSocket.java

index adb9eb652d249ff5ace33753dacc4876bb252682..1f09037c027adc1aada15384c3a33839d209b279 100644 (file)
@@ -520,20 +520,22 @@ public class LGWebOSTVSocket {
         return request;
     }
 
+    private Float volumeFromResponse(JsonObject jsonObj) {
+        final String VOLUME_STATUS = "volumeStatus";
+        final String VOLUME = "volume";
+        JsonObject parent = jsonObj.has(VOLUME_STATUS) ? jsonObj.getAsJsonObject(VOLUME_STATUS) : jsonObj;
+        return parent.get(VOLUME).getAsInt() >= 0 ? (float) (parent.get(VOLUME).getAsInt() / 100.0) : Float.NaN;
+    }
+
     public ServiceSubscription<Float> subscribeVolume(ResponseListener<Float> listener) {
-        ServiceSubscription<Float> request = new ServiceSubscription<>(VOLUME, null,
-                jsonObj -> jsonObj.get("volume").getAsInt() >= 0 ? (float) (jsonObj.get("volume").getAsInt() / 100.0)
-                        : Float.NaN,
+        ServiceSubscription<Float> request = new ServiceSubscription<>(VOLUME, null, this::volumeFromResponse,
                 listener);
         sendCommand(request);
         return request;
     }
 
     public ServiceCommand<Float> getVolume(ResponseListener<Float> listener) {
-        ServiceCommand<Float> request = new ServiceCommand<>(VOLUME, null,
-                jsonObj -> jsonObj.get("volume").getAsInt() >= 0 ? (float) (jsonObj.get("volume").getAsInt() / 100.0)
-                        : Float.NaN,
-                listener);
+        ServiceCommand<Float> request = new ServiceCommand<>(VOLUME, null, this::volumeFromResponse, listener);
         sendCommand(request);
         return request;
     }