From c0dc0daa4f1712ecd28a29e792970bc3145912d0 Mon Sep 17 00:00:00 2001 From: Sebastian Prehn <2531264+sprehn@users.noreply.github.com> Date: Fri, 11 Dec 2020 22:11:31 +0100 Subject: [PATCH] [lgwebos] Fix Volume Subscription on newer LGWebOS TVs which report volumeStatus. (#9331) Signed-off-by: Sebastian Prehn --- .../internal/handler/LGWebOSTVSocket.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/LGWebOSTVSocket.java b/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/LGWebOSTVSocket.java index adb9eb652d..1f09037c02 100644 --- a/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/LGWebOSTVSocket.java +++ b/bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/LGWebOSTVSocket.java @@ -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 subscribeVolume(ResponseListener listener) { - ServiceSubscription request = new ServiceSubscription<>(VOLUME, null, - jsonObj -> jsonObj.get("volume").getAsInt() >= 0 ? (float) (jsonObj.get("volume").getAsInt() / 100.0) - : Float.NaN, + ServiceSubscription request = new ServiceSubscription<>(VOLUME, null, this::volumeFromResponse, listener); sendCommand(request); return request; } public ServiceCommand getVolume(ResponseListener listener) { - ServiceCommand request = new ServiceCommand<>(VOLUME, null, - jsonObj -> jsonObj.get("volume").getAsInt() >= 0 ? (float) (jsonObj.get("volume").getAsInt() / 100.0) - : Float.NaN, - listener); + ServiceCommand request = new ServiceCommand<>(VOLUME, null, this::volumeFromResponse, listener); sendCommand(request); return request; } -- 2.47.3