[lgwebos] Fix Volume Subscription on newer LGWebOS TVs which report volumeStatus. (#9331)
Signed-off-by: Sebastian Prehn <sebastian.prehn@gmx.de>
This commit is contained in:
@@ -520,20 +520,22 @@ public class LGWebOSTVSocket {
|
|||||||
return request;
|
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) {
|
public ServiceSubscription<Float> subscribeVolume(ResponseListener<Float> listener) {
|
||||||
ServiceSubscription<Float> request = new ServiceSubscription<>(VOLUME, null,
|
ServiceSubscription<Float> request = new ServiceSubscription<>(VOLUME, null, this::volumeFromResponse,
|
||||||
jsonObj -> jsonObj.get("volume").getAsInt() >= 0 ? (float) (jsonObj.get("volume").getAsInt() / 100.0)
|
|
||||||
: Float.NaN,
|
|
||||||
listener);
|
listener);
|
||||||
sendCommand(request);
|
sendCommand(request);
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServiceCommand<Float> getVolume(ResponseListener<Float> listener) {
|
public ServiceCommand<Float> getVolume(ResponseListener<Float> listener) {
|
||||||
ServiceCommand<Float> request = new ServiceCommand<>(VOLUME, null,
|
ServiceCommand<Float> request = new ServiceCommand<>(VOLUME, null, this::volumeFromResponse, listener);
|
||||||
jsonObj -> jsonObj.get("volume").getAsInt() >= 0 ? (float) (jsonObj.get("volume").getAsInt() / 100.0)
|
|
||||||
: Float.NaN,
|
|
||||||
listener);
|
|
||||||
sendCommand(request);
|
sendCommand(request);
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user