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

Revise volume logic #65

Merged
merged 6 commits into from
Dec 31, 2022
Merged

Revise volume logic #65

merged 6 commits into from
Dec 31, 2022

Conversation

pavoni
Copy link
Owner

@pavoni pavoni commented Dec 30, 2022

This PR refactors the pyroon volume logic.

It removes a db to percentage conversation from the change_volume method - which made some assumptions about roon endpoints that weren't always correct. Because of that this is a breaking change - so I've renamed the method change_volume_raw to make it more obvious.

I've also added three new methods to get, set and increment/decrement the volume on a percentage basis - which use the additional data roon provides about endpoints. These methods are based on code from @juliusvaart (thanks).

@juliusvaart also found that the 'type: db' parameter isn't always set for endpoints that are scaled in db - so this new logic avoids depending on this!

I've also added some simple tests - but they require a roon core (and are dependant on my setup) - so can't be run on github.

@juliusvaart could you take a look?

@doctorfree when released this may require some (small) changes to your code.

Closes #55

@pavoni pavoni merged commit b3a3589 into master Dec 31, 2022
@pavoni pavoni deleted the revise_volume_logic branch December 31, 2022 11:01
@doctorfree
Copy link
Contributor

Yes, I call change_volume when setting the volume and was forcing it into [0, 100] for absolute volume values.

I am running to catch up on these changes and should have been following more closely. Can I just replace my calls to change_volume with calls to change_volume_raw and not worry about ranges for absolute volume values?

The new methods look good, I can use change_volume_percent.

@pavoni
Copy link
Owner Author

pavoni commented Dec 31, 2022

If you were using ‘absolute’ you should change to the new method.

The old code attempted to scale for ‘db’ endpoints - but wasn’t always tight.

@doctorfree
Copy link
Contributor

Thus far testing is succeeding using change_volume_raw rather than change_volume.

Is there a reason why you did not leave change_volume and just make it call change_volume_raw ?

@pavoni
Copy link
Owner Author

pavoni commented Dec 31, 2022

It depends on your endpoints. If you have endpoints that have the volume of 0 to 100 that the two calls are the same.

However many roon endpoints have the range -80 to 0 (in db) - so the old change_volume code did a conversion to a db endpoint.

However some endpoints are neither 0/100 nor -80/0 and some -80/0 endpoints don'r have the 'db' type. In those case it would mess up - sometimes badly!

So the change_volume_raw now just sends what you say to roon. But if you want to use 0-100 on the client side - this will mess up if you have a db endpoint - or a non standard endpoint.

So I expect you'll just want to use set_volume which will always work on a 0-100 basis.

Unless you want your users to know what endpoint they are dealing with (and eg use -40 for half volume on a db endpoint) - in which case change_volume_raw is what you want. But that will be breaking change for your clients.

@doctorfree
Copy link
Contributor

My tests are looking good. No issues uncovered thus far with either the new volume methods or the new WebSocket library.

Installs of new or upgraded RoonCommandLine packages will upgrade or install the latest Python roonapi module. The only compatibility issue I have is users running an older RoonCommandLine release who upgrade the Python roonapi module without upgrading RoonCommandLine. This breaks volume handling since there is no longer a change_volume method. That's why I was asking why it was removed rather than modified to call change_volume_raw. But, yes, it was not working for all endpoints.

I'm happy with these changes. I will handle the hopefully infrequent user who upgrades roonapi but not RoonCommandLine.

@pavoni
Copy link
Owner Author

pavoni commented Dec 31, 2022

Thanks for this.

the consequences of using the new code on a db endpoint could have the effect of maxing out the volume. So an error probably is safer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Volume control logic could be improved!
3 participants