Skip to content
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

Merged
merged 4 commits into from
Feb 22, 2025

Conversation

stefan-hoehn
Copy link
Contributor

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.

Signed-off-by: Stefan Höhn <stefan.hoehn@nfon.com>
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/upnp-binding-already-exposed-and-exception-when-using-wz-wiim-pro/161084/7

@jlaur jlaur changed the title upnp: ignore negative volume values [upnpcontrol] Ignore negative volume values Dec 28, 2024
@jlaur jlaur added the bug An unexpected problem or unintended behavior of an add-on label Dec 28, 2024
Copy link
Contributor

@jlaur jlaur left a 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) {
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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:


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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor

@mherwege mherwege Feb 22, 2025

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.

maxvolume = rcService.getStateVariable("Volume").getTypeDetails().getAllowedValueRange().getMaximum();
long maxVolumeValue = rcService.getStateVariable("Volume").getTypeDetails().getAllowedValueRange()
.getMaximum();
if (maxVolumeValue >= 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (maxVolumeValue >= 0) {
if (maxVolumeValue > 0) {

Signed-off-by: Stefan Höhn <stefan.hoehn@nfon.com>
Copy link
Contributor

@mherwege mherwege left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@lsiepel lsiepel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks LGTM

@lsiepel lsiepel merged commit fe0b942 into openhab:main Feb 22, 2025
2 checks passed
@lsiepel lsiepel added this to the 5.0 milestone Feb 22, 2025
matgroe pushed a commit to matgroe/openhab-addons that referenced this pull request Feb 24, 2025
* upnp: ignore negative volume values

Signed-off-by: Stefan Höhn <stefan.hoehn@nfon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants