feat(revpiconfig): Replace rfkill subprocess calls with sysfs writes

Updated Bluetooth and WiFi rfkill handling by replacing subprocess calls
to "rfkill" with direct writes to sysfs files. This change simplifies
the implementation and improves performance by avoiding external
command execution.
This commit is contained in:
2025-04-21 13:25:56 +02:00
parent de1774f60e
commit fc82ec0eb9

View File

@@ -224,11 +224,13 @@ def configure_bluetooth(action: ConfigActions):
if action is ConfigActions.ENABLE: if action is ConfigActions.ENABLE:
if bt_rfkill_index is not None: if bt_rfkill_index is not None:
subprocess.call(["rfkill", "unblock", str(bt_rfkill_index)]) with open(f"/sys/class/rfkill/rfkill{bt_rfkill_index}/soft", "w") as f:
f.write("0")
elif action is ConfigActions.DISABLE: elif action is ConfigActions.DISABLE:
if bt_rfkill_index is not None: if bt_rfkill_index is not None:
subprocess.call(["rfkill", "block", str(bt_rfkill_index)]) with open(f"/sys/class/rfkill/rfkill{bt_rfkill_index}/soft", "w") as f:
f.write("1")
elif action is ConfigActions.STATUS: elif action is ConfigActions.STATUS:
if bt_rfkill_index is None: if bt_rfkill_index is None:
@@ -343,12 +345,14 @@ def configure_wifi(action: ConfigActions):
if action is ConfigActions.ENABLE: if action is ConfigActions.ENABLE:
if revpi.with_wifi: if revpi.with_wifi:
wifi_rfkill_index = get_rfkill_index(revpi.class_path_wifi) wifi_rfkill_index = get_rfkill_index(revpi.class_path_wifi)
subprocess.call(["rfkill", "unblock", str(wifi_rfkill_index)]) with open(f"/sys/class/rfkill/rfkill{wifi_rfkill_index}/soft", "w") as f:
f.write("0")
elif action is ConfigActions.DISABLE: elif action is ConfigActions.DISABLE:
if revpi.with_wifi: if revpi.with_wifi:
wifi_rfkill_index = get_rfkill_index(revpi.class_path_wifi) wifi_rfkill_index = get_rfkill_index(revpi.class_path_wifi)
subprocess.call(["rfkill", "block", str(wifi_rfkill_index)]) with open(f"/sys/class/rfkill/rfkill{wifi_rfkill_index}/soft", "w") as f:
f.write("1")
elif action is ConfigActions.AVAILABLE: elif action is ConfigActions.AVAILABLE:
return revpi.with_wifi return revpi.with_wifi