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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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.

@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.

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.

5 participants