volume_status add wpctl support#2332
Conversation
9d49866 to
6bdacff
Compare
|
Well. Looks ok now! |
|
Need to drop manual device setting because device ID-s are dynamic. |
According to wiki, you may be able to supply
src https://wiki.archlinux.org/title/WirePlumber#Obtain_interface_name_for_rules_matching EDIT: I assume it wouldn't work, but technically, you could create a small function that runs a command to see if that particular device name/node is active before running any other function. |
d469d3c to
5910a5b
Compare
5910a5b to
7000cb2
Compare
|
Added quite silly wpctl status -n parser. Is "if self.dev_target:" guarding overkill or not? I personally don't like to send invalid shell command which might have unexpected side effects. ( sending None as device id) In general view, ready for review. |
There was a problem hiding this comment.
therefore it is possible to have faulty config
I hope we can honor config as close as possible, especially on various backends. If user placed bad/invalid config, then I suppose we would not ignore it. However, it's up to you because...
Personally, I think/wonder if is_input config is a terrible user config that should be just removed because maybe the backends can figure is_input out themselves from device name / device information (in each setup)... We would still keep the placeholder.
Just not in this PR.
Added quite silly wpctl status -n parser.
Apparently there is pw-dump too (located in pipewire-utils). Ideal for JSON scripting. Just FYI. I don't know if it's worth it. Might be more clean/more reliable than wpctl if wpctl status -n changed one day. EDIT: Not a right tool.
| try: | ||
| lines = self.command_output(["wpctl", "status", "-n"]) | ||
| except CommandError: | ||
| self.dev_target = None | ||
| return |
There was a problem hiding this comment.
Just wondering. Why do we need try/except with verified installed wpctl? Is this faulty None config you mentioned?
EDIT: It's for self.dev_target = None checks?
| else: | ||
| self.dev_target = "@DEFAULT_AUDIO_SOURCE@" if self.is_input else "@DEFAULT_AUDIO_SINK@" |
There was a problem hiding this comment.
(Experiment/Optimization) Without testing anything... I think maybe for "performance reason".
Try noop: pass function (and real resolve_device_id function)... Assign a correct function at setup to basically make this optimized when device is not in use... and potentially avoid try/except + send None issue.
(Nit) Self.device, self.dev_target, self._resolve_device_id is blending in... Can you rename to self.target and self._resolve_target?
There was a problem hiding this comment.
To better understand this issue, I coded too.
Please look at this. https://github.com/lasers/py3status/tree/volume_status-wpctl-wip
This is still your contribution. Take it if you find this to be better.
I noticed that...
wpctl status -n gives us same thing we need from get_volume call.... By using this data instead, we can skip extra subprocess call. One call, not two... on every refresh/volume changed, device changed, etc.
We use this output to find target_id too.
We also can use this output to find default device anyway. Not in use, but...
Microphone percentage/muted now works too... because of self._target_id.
Unrelated -- I think it would be useful in adding format and format_device and defaulting devices to (default * devices)... meaning volume_status can spawn default source+sink on the bar by default (or be silly and spawn all sources+sinks). And convert code to use thresholds too. All in a different PR though.
My code was just PoC. Looks like your code handles SINK/SOURCE correctly.
We still need it to differentiate between default SINK/SOURCE
I tested your code. Looks like working OK; but seems like output type should be int not a float.
You are right. It is possible to get needed info from status command. Nice work with parsing it!
Interesting bug. Microphone percentage/muted was working for me.
As I see that You added some formatting to debug output. It helps to differentiate between used backends. Also we need to update documentation to list wpctl status -n command in list: Also I found out that you don't need set volume upper limit in your at all, because wpctl can handle limiting itself, because limit is one argument of setting volume. BYW: Wrapping up some code changes and I will push it soon. |
|
In general it is good to go review again. During testing, it took time to recover computer restart. For example pactl doesn't have issue. |
lasers
left a comment
There was a problem hiding this comment.
Just addressing one thing immediately. My PR didn't had this fix too.
| @staticmethod | ||
| def _format_volume(volume): | ||
| return int(float(volume) * 100) |
There was a problem hiding this comment.
Use class Meta + :.0f instead... giving users int/float volume choices.
Grep update_placeholder_format on modules for an example.
No description provided.