Repository: ultrabug/py3status

Issue:
volume_status doesn't show directly at start when use pipewire
**Describe the bug**
`volume_status` module doesn't automatically run upon start while i use pipewire, the module only work if i reload either i3 or i3bar it self

**Your py3status version**
py3status version 3.45 (python 3.10.5) on i3

**To Reproduce**
Steps to reproduce the behavior along with your py3status configuration (filter out any private values):
1. Add module `volume_status`
2. Configure module like this 
```
volume_status {
        cache_timeout = 1
        format = " ICON {percentage}% "
        format_muted = "  "
        thresholds = [(0, 'bad'), (10, 'degraded'), (20, 'good')]
        on_click 3 = "exec ~/rofi-nord/volume.sh"
        on_click 2 = "exec pavucontrol"
}
```
4. Run py3status `status_command py3status -c ~/.config/i3status/i3status.conf`
5. See error

**Expected behavior**
Automatically show `volume_status` on login/startup

**Screenshots**
None, can't be described via screenshots

**Additional context**
None



Discussion:
Your pulseaudio might be running too late at startup so you get `None` value and the format disappears... or amixer was chosen. Idk.

Troubleshoot a bit more with: 
```
format = "{command} {percentage}%"
```
> command

the command return `pactl` anything i can do with that?
Nothing. Just making sure the startup went with pulseaudio instead of alsa.

I realize we probably could add second debug placeholder (pulseaudio or pipewire) in the future.

I would look at logging pipewire and/or volume_status next to see why it's not working at startup. I'm not on i3 so I can't check anything on my side right now.

I just think it's because pipewire wasn't ready, but the next cache timeout should fix that. Odd tho.
> 

the cache timeout can't save it :(, i made a script to manually reload i3bar everytime i start up

Resolving patch:
diff --git a/py3status/modules/volume_status.py b/py3status/modules/volume_status.py
--- a/py3status/modules/volume_status.py
+++ b/py3status/modules/volume_status.py
@@ -26,6 +26,10 @@
         (default False)
     max_volume: Allow the volume to be increased past 100% if available.
         pactl and pamixer supports this. (default 120)
+    start_delay: Number of seconds to wait before starting this module.
+        This allows some systems to start the audio backend before we
+        try picking it up.
+        (default 0)
     thresholds: Threshold for percent volume.
         (default [(0, 'bad'), (20, 'degraded'), (50, 'good')])
     volume_delta: Percentage amount that the volume is increased or
@@ -82,6 +86,7 @@
 
 import re
 import math
+from time import sleep
 from py3status.exceptions import CommandError
 
 STRING_ERROR = "invalid command `{}`"
@@ -324,6 +329,7 @@ class Py3status:
     format_muted = r"[\?if=is_input 😶|♪]: muted"
     is_input = False
     max_volume = 120
+    start_delay = 0
     thresholds = [(0, "bad"), (20, "degraded"), (50, "good")]
     volume_delta = 5
 
@@ -353,6 +359,8 @@ def deprecate_function(config):
         }
 
     def post_config_hook(self):
+        if self.start_delay:
+            sleep(int(self.start_delay))
         if not self.command:
             commands = ["pamixer", "pactl", "amixer"]
             # pamixer, pactl requires pulseaudio to work


Test patch: