[lgwebos] Fix Volume Subscription on newer LGWebOS TVs which report volumeStatus. (#9331)

Signed-off-by: Sebastian Prehn <sebastian.prehn@gmx.de>
pull/9335/head
Sebastian Prehn 2020-12-11 22:11:31 +01:00 committed by GitHub
parent 1362f9e5c1
commit c0dc0daa4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 7 deletions

View 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;
}