jishi / node-sonos-http-api

An HTTP API bridge for Sonos easing automation. Hostable on any node.js capable device, like a raspberry pi or similar.
http://jishi.github.io/node-sonos-http-api/
MIT License
1.84k stars 463 forks source link

Volume parameter issue with float numbers #731

Open pasger opened 4 years ago

pasger commented 4 years ago

Volume parameters with float numbers are not interpreted when used with "clip".

For example: GET /kitchen/clip/ring.mp3/3.0 Volume parameter is not interpreted as "3" and the predefined announceVolume in settings.json is used.

but GET /kitchen/volume/3.0 is interpreted correctly and the volume is set to 3.

Unfortunately my application can not send integer value to bypass this issue.

Is it possible to accept float values when "clip" is used?

regards Pascal

jishi commented 4 years ago

https://github.com/jishi/node-sonos-http-api/blob/master/lib/actions/clip.js#L17-L20

That checks that the volume parameter (the comment is wrong, it's the second parameter) consist of only numbers, which is why it is ignoring it. It would have to check for periods as well and then maybe do a parseInt of it or similar, because Sonos will probably be sad if you sent in a decimal value as volume (it only takes integer 0-100).

jishi commented 4 years ago

Is this a problem because the value is produced by some external source? Seems fairly trivial to just only send integers in the request to begin with :)

pasger commented 4 years ago

Thank you very much for your reply.

Yes, the values are produced by an external building automation system which can not be modified.

It would be great if the check could be modified to accept float values and round them downwards to its nearest integer. That would match the /volume/ behavior. If I send /kitchen/volume/10.7 the volume is automatically rounded downwards (probably with method floor) to 10.

Thank you.