feat(dbus): Add InterfaceWlan for WLAN configuration management
Introduced `InterfaceWlan` to enable/disable WLAN hardware, check availability, and track status via D-Bus. Integrated the new interface with the bus provider initialization to ensure proper registration. Signed-off-by: Sven Sager <s.sager@kunbus.com>
This commit is contained in:
@@ -10,7 +10,7 @@ from pydbus import SessionBus, SystemBus
|
|||||||
|
|
||||||
from . import REVPI_DBUS_NAME
|
from . import REVPI_DBUS_NAME
|
||||||
from .process_image import InterfacePiControl
|
from .process_image import InterfacePiControl
|
||||||
from .system_config import InterfaceRevpiConfig, InterfaceSoftwareServices
|
from .system_config import InterfaceRevpiConfig, InterfaceSoftwareServices, InterfaceWlan
|
||||||
|
|
||||||
log = getLogger(__name__)
|
log = getLogger(__name__)
|
||||||
|
|
||||||
@@ -44,6 +44,7 @@ class BusProvider(Thread):
|
|||||||
InterfacePiControl(self._bus, self.picontrol_device, self.config_rsc),
|
InterfacePiControl(self._bus, self.picontrol_device, self.config_rsc),
|
||||||
InterfaceRevpiConfig(self._bus),
|
InterfaceRevpiConfig(self._bus),
|
||||||
InterfaceSoftwareServices(self._bus),
|
InterfaceSoftwareServices(self._bus),
|
||||||
|
InterfaceWlan(self._bus),
|
||||||
]
|
]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -4,3 +4,4 @@
|
|||||||
"""D-Bus interfaces for system configuration."""
|
"""D-Bus interfaces for system configuration."""
|
||||||
from .interface_config import InterfaceRevpiConfig
|
from .interface_config import InterfaceRevpiConfig
|
||||||
from .interface_services import InterfaceSoftwareServices
|
from .interface_services import InterfaceSoftwareServices
|
||||||
|
from .interface_wlan import InterfaceWlan
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ from .revpi_config import (
|
|||||||
configure_dphys_swapfile,
|
configure_dphys_swapfile,
|
||||||
configure_external_antenna,
|
configure_external_antenna,
|
||||||
configure_gui,
|
configure_gui,
|
||||||
configure_wlan,
|
|
||||||
)
|
)
|
||||||
from ..dbus_helper import DbusInterface
|
from ..dbus_helper import DbusInterface
|
||||||
|
|
||||||
@@ -98,6 +97,5 @@ AVAILABLE_FEATURES = {
|
|||||||
"revpi-con-can": FeatureFunction(configure_con_can, []),
|
"revpi-con-can": FeatureFunction(configure_con_can, []),
|
||||||
"swapfile": FeatureFunction(configure_dphys_swapfile, []),
|
"swapfile": FeatureFunction(configure_dphys_swapfile, []),
|
||||||
"bluetooth": FeatureFunction(configure_bluetooth, []),
|
"bluetooth": FeatureFunction(configure_bluetooth, []),
|
||||||
"wlan": FeatureFunction(configure_wlan, []),
|
|
||||||
"external-antenna": FeatureFunction(configure_external_antenna, []),
|
"external-antenna": FeatureFunction(configure_external_antenna, []),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# SPDX-FileCopyrightText: 2025 KUNBUS GmbH
|
||||||
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
"""D-Bus interfaces for wlan configuration."""
|
||||||
|
from logging import getLogger
|
||||||
|
from threading import Event, Thread
|
||||||
|
|
||||||
|
from pydbus.generic import signal
|
||||||
|
|
||||||
|
from .revpi_config import configure_wlan, ConfigActions
|
||||||
|
from ..dbus_helper import DbusInterface
|
||||||
|
|
||||||
|
log = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class InterfaceWlan(DbusInterface):
|
||||||
|
"""
|
||||||
|
<node>
|
||||||
|
<interface name="com.revolutionpi.middleware1.WlanConfiguration">
|
||||||
|
<method name="Enable">
|
||||||
|
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
|
||||||
|
</method>
|
||||||
|
<method name="Disable">
|
||||||
|
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
|
||||||
|
</method>
|
||||||
|
<property name="available" type="b" access="read">
|
||||||
|
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/>
|
||||||
|
</property>
|
||||||
|
<property name="status" type="s" access="read">
|
||||||
|
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/>
|
||||||
|
</property>
|
||||||
|
</interface>
|
||||||
|
</node>
|
||||||
|
"""
|
||||||
|
|
||||||
|
PropertiesChanged = signal()
|
||||||
|
|
||||||
|
def __init__(self, bus):
|
||||||
|
super().__init__(bus)
|
||||||
|
self._status = ""
|
||||||
|
|
||||||
|
# NetworkManager-Objekt abrufen
|
||||||
|
self.bus_nm = self.bus.get(
|
||||||
|
"org.freedesktop.NetworkManager",
|
||||||
|
"/org/freedesktop/NetworkManager",
|
||||||
|
)
|
||||||
|
|
||||||
|
# Prepare status value and thread
|
||||||
|
self.evt_stop_threading = Event()
|
||||||
|
self._update_status(suppress_signal=True)
|
||||||
|
self.th_run_status_update = Thread(
|
||||||
|
target=self._run_status_update,
|
||||||
|
daemon=True,
|
||||||
|
).start()
|
||||||
|
|
||||||
|
def _run_status_update(self, *args, **kwargs):
|
||||||
|
while not self.evt_stop_threading.wait(1.0):
|
||||||
|
self._update_status()
|
||||||
|
|
||||||
|
def _update_status(self, suppress_signal=False) -> None:
|
||||||
|
str_status = "enabled" if configure_wlan(ConfigActions.STATUS) else "disabled"
|
||||||
|
if self._status != str_status:
|
||||||
|
self._status = str_status
|
||||||
|
|
||||||
|
if not suppress_signal:
|
||||||
|
self.PropertiesChanged(
|
||||||
|
"com.revolutionpi.middleware1.WlanConfiguration",
|
||||||
|
{"status": str_status},
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
|
||||||
|
def cleanup(self):
|
||||||
|
self.evt_stop_threading.set()
|
||||||
|
|
||||||
|
def Disable(self) -> None:
|
||||||
|
"""Disable integrated WLAN hardware."""
|
||||||
|
configure_wlan(ConfigActions.DISABLE)
|
||||||
|
|
||||||
|
def Enable(self) -> None:
|
||||||
|
"""Enable integrated WLAN hardware."""
|
||||||
|
configure_wlan(ConfigActions.ENABLE)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self) -> bool:
|
||||||
|
"""Check if WLAN hardware is available."""
|
||||||
|
return configure_wlan(ConfigActions.AVAILABLE)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def status(self) -> str:
|
||||||
|
return self._status
|
||||||
Reference in New Issue
Block a user