-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[upnpcontrol] Ignore negative volume values #17991
[upnpcontrol] Ignore negative volume values #17991
Conversation
Signed-off-by: Stefan Höhn <stefan.hoehn@nfon.com>
This pull request has been mentioned on openHAB Community. There might be relevant details there: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix! I have put some minor comments for consideration.
@@ -1113,6 +1113,11 @@ private void onValueReceivedVolume(String variable, @Nullable String value) { | |||
long volume = Long.valueOf(value); | |||
volume = volume * 100 / config.maxvolume; | |||
|
|||
if (volume < 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this could be checked right after line 1113 to avoid performing any calculations with invalid value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the identified error case, volume came from the service as a negative. But there might also be a case where config.maxvolume (also retrieved from the service) is negative and that would lead to problems as well. Or we catch this bad data where config.maxvolume is set as well, or we leave this statement where it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too many ORs 😅 So what do we wanna do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move it right after line 1113, but also change here:
Line 55 in e2571d6
if (volume) { |
Put the following on that line:
if (volume && volume > 0)
In principle, it should be a positive integer less than or equal to 100. You could also log a warning there if it is not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stefan-hoehn are you able to continue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I honestly forgot about it. Will take care about it on the weekend. Thanks for reminding me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mherwege
Now looking on UpnpRenderingControlConfiguration
if (volume && volume > 0)
doesn't work because volume here is a boolean
public boolean volume;
We rather have to take care of the maxvolume here, so I think the following should be right
if (volume) {
long maxVolumeValue = rcService.getStateVariable("Volume").getTypeDetails().getAllowedValueRange().getMaximum();
if (maxVolumeValue >= 0) {
maxvolume = maxVolumeValue;
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sorry for the wrong suggestion. What you propose is fine, except, I would make it maxVolumeValue > 0
. 0 would obviously also be an issue when dividing by maxvolume
afterwards, and wouldn’t make sense.
...trol/src/main/java/org/openhab/binding/upnpcontrol/internal/handler/UpnpRendererHandler.java
Show resolved
Hide resolved
...trol/src/main/java/org/openhab/binding/upnpcontrol/internal/handler/UpnpRendererHandler.java
Show resolved
Hide resolved
Signed-off-by: Stefan Höhn <stefan.hoehn@nfon.com>
maxvolume = rcService.getStateVariable("Volume").getTypeDetails().getAllowedValueRange().getMaximum(); | ||
long maxVolumeValue = rcService.getStateVariable("Volume").getTypeDetails().getAllowedValueRange() | ||
.getMaximum(); | ||
if (maxVolumeValue >= 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (maxVolumeValue >= 0) { | |
if (maxVolumeValue > 0) { |
Signed-off-by: Stefan Höhn <stefan.hoehn@nfon.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks LGTM
* upnp: ignore negative volume values Signed-off-by: Stefan Höhn <stefan.hoehn@nfon.com>
I have at least one upnp system that is sending incorrect negative volume values. This change make the binding resilient by ignoring negative volume values.