feat(dbus): Add Wi-Fi configuration support to the system config
Introduces the `configure_wifi` function to handle Wi-Fi actions such as enabling, disabling, and checking status. Updates the `ieee80211` feature to use the new function, integrating Wi-Fi management into the existing configuration framework.
This commit is contained in:
@@ -12,6 +12,7 @@ from .revpi_config import (
|
||||
configure_dphys_swapfile,
|
||||
configure_external_antenna,
|
||||
configure_gui,
|
||||
configure_wifi,
|
||||
simple_systemd,
|
||||
)
|
||||
from ..dbus_helper import DbusInterface
|
||||
@@ -92,7 +93,7 @@ AVAILABLE_FEATURES = {
|
||||
),
|
||||
"revpipyload": FeatureFunction(simple_systemd, ["revpipyload.service"]),
|
||||
"bluetooth": False,
|
||||
"ieee80211": False,
|
||||
"ieee80211": FeatureFunction(configure_wifi, []),
|
||||
"avahi": FeatureFunction(configure_avahi_daemon, []),
|
||||
"external-antenna": FeatureFunction(configure_external_antenna, []),
|
||||
}
|
||||
|
||||
@@ -314,6 +314,34 @@ def configure_gui(action: ConfigActions):
|
||||
raise ValueError(f"action {action} not supported")
|
||||
|
||||
|
||||
def configure_wifi(action: ConfigActions):
|
||||
revpi = RevPiConfig()
|
||||
|
||||
if action is ConfigActions.ENABLE:
|
||||
if revpi.rfkill_index is not None:
|
||||
subprocess.call(["rfkill", "unblock", str(revpi.rfkill_index)])
|
||||
|
||||
elif action is ConfigActions.DISABLE:
|
||||
if revpi.rfkill_index is not None:
|
||||
subprocess.call(["rfkill", "block", str(revpi.rfkill_index)])
|
||||
|
||||
elif action is ConfigActions.AVAILABLE:
|
||||
return revpi.with_wifi and revpi.rfkill_index is not None
|
||||
|
||||
elif action is ConfigActions.STATUS:
|
||||
if revpi.rfkill_index is None:
|
||||
return False
|
||||
|
||||
with open(f"/sys/class/rfkill/rfkill{revpi.rfkill_index}/soft", "r") as f:
|
||||
buffer = f.read().strip()
|
||||
return buffer == "0"
|
||||
|
||||
else:
|
||||
raise ValueError(f"action {action} not supported")
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def simple_systemd(action: ConfigActions, unit: str):
|
||||
bus = SystemBus()
|
||||
systemd_manager = bus.get(".systemd1")
|
||||
|
||||
Reference in New Issue
Block a user