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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,11 @@ private void onValueReceivedVolume(String variable, @Nullable String value) {
long volume = Long.valueOf(value);
jlaur marked this conversation as resolved.
Show resolved Hide resolved
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.

logger.warn("UPnP device {} received invalid volume value {}", thing.getLabel(), value);
jlaur marked this conversation as resolved.
Show resolved Hide resolved
return;
}

String upnpChannel = variable.replace("Volume", "volume").replace("Master", "");
updateState(upnpChannel, new PercentType((int) volume));

Expand Down