Logitech c930e focus reverts to default settings even with custom udev rules

After some extra research, it seems that automatically restoring default settings is A Feature, Not A Bug ™: https://www.reddit.com/r/obs/comments/fflg5g/logitech_cam_keeps_resetting_video_settings_back/

So I came up with an idea: what if I could set the focus every few seconds or so, to prevent the settings from drifting back to defaults? It turns out this is possible, though not directly with udev since it’s a long-running process and udev rules are blocking. Instead, I used a combination of udev rules, systemd device units and service units.

The high-level idea is as follows:

  • Create a udev rules file that tags systemd so that the associated device unit is created, and set SYSTEMD_WANTS to point to a service template unit file, passing the minor device number to the template
  • The service template unit runs a script, passing its argument (the minor device number) to the script
  • The script uses the minor device number to refer to the correct camera and set the focus parameters repeatedly on that camera, on an interval of 5 seconds

The detailed solution can be found in this gist.