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:
2025-04-21 09:22:30 +02:00
parent 18e6fb3d14
commit 6eb7eeea40
2 changed files with 30 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ from .revpi_config import (
configure_dphys_swapfile, configure_dphys_swapfile,
configure_external_antenna, configure_external_antenna,
configure_gui, configure_gui,
configure_wifi,
simple_systemd, simple_systemd,
) )
from ..dbus_helper import DbusInterface from ..dbus_helper import DbusInterface
@@ -92,7 +93,7 @@ AVAILABLE_FEATURES = {
), ),
"revpipyload": FeatureFunction(simple_systemd, ["revpipyload.service"]), "revpipyload": FeatureFunction(simple_systemd, ["revpipyload.service"]),
"bluetooth": False, "bluetooth": False,
"ieee80211": False, "ieee80211": FeatureFunction(configure_wifi, []),
"avahi": FeatureFunction(configure_avahi_daemon, []), "avahi": FeatureFunction(configure_avahi_daemon, []),
"external-antenna": FeatureFunction(configure_external_antenna, []), "external-antenna": FeatureFunction(configure_external_antenna, []),
} }

View File

@@ -314,6 +314,34 @@ def configure_gui(action: ConfigActions):
raise ValueError(f"action {action} not supported") 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): def simple_systemd(action: ConfigActions, unit: str):
bus = SystemBus() bus = SystemBus()
systemd_manager = bus.get(".systemd1") systemd_manager = bus.get(".systemd1")