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>
102 lines
3.5 KiB
Python
102 lines
3.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
# SPDX-FileCopyrightText: 2025 KUNBUS GmbH
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
"""D-Bus interfaces for hardware configuration."""
|
|
from collections import namedtuple
|
|
from logging import getLogger
|
|
|
|
from pydbus.generic import signal
|
|
|
|
from .revpi_config import (
|
|
ConfigActions,
|
|
configure_bluetooth,
|
|
configure_con_can,
|
|
configure_dphys_swapfile,
|
|
configure_external_antenna,
|
|
configure_gui,
|
|
)
|
|
from ..dbus_helper import DbusInterface
|
|
|
|
log = getLogger(__name__)
|
|
|
|
FeatureFunction = namedtuple("FeatureFunction", ["function", "args"])
|
|
|
|
|
|
class InterfaceRevpiConfig(DbusInterface):
|
|
"""
|
|
<node>
|
|
<interface name="com.revolutionpi.middleware1.RevpiConfig">
|
|
<method name="Disable">
|
|
<arg name="feature" type="s" direction="in"/>
|
|
</method>
|
|
<method name="Enable">
|
|
<arg name="feature" type="s" direction="in"/>
|
|
</method>
|
|
<method name="GetStatus">
|
|
<arg name="feature" type="s" direction="in"/>
|
|
<arg name="status" type="b" direction="out"/>
|
|
</method>
|
|
<method name="GetAvailability">
|
|
<arg name="feature" type="s" direction="in"/>
|
|
<arg name="available" type="b" direction="out"/>
|
|
</method>
|
|
<property name="available_features" type="as" access="read"/>
|
|
<signal name="StatusChanged">
|
|
<arg name="feature" type="s"/>
|
|
<arg name="status" type="b"/>
|
|
</signal>
|
|
<signal name="AvailabilityChanged">
|
|
<arg name="feature" type="s"/>
|
|
<arg name="available" type="b"/>
|
|
</signal>
|
|
</interface>
|
|
</node>
|
|
"""
|
|
|
|
AvailabilityChanged = signal()
|
|
StatusChanged = signal()
|
|
|
|
def Disable(self, feature: str) -> None:
|
|
"""Disable the feature."""
|
|
feature_function = get_feature(feature)
|
|
feature_function.function(ConfigActions.DISABLE, *feature_function.args)
|
|
self.StatusChanged(feature, False)
|
|
|
|
def Enable(self, feature: str) -> None:
|
|
"""Enable the feature."""
|
|
feature_function = get_feature(feature)
|
|
feature_function.function(ConfigActions.ENABLE, *feature_function.args)
|
|
self.StatusChanged(feature, True)
|
|
|
|
def GetStatus(self, feature: str) -> bool:
|
|
"""Get feature status."""
|
|
feature_function = get_feature(feature)
|
|
return feature_function.function(ConfigActions.STATUS, *feature_function.args)
|
|
|
|
def GetAvailability(self, feature: str) -> bool:
|
|
"""Get feature availability on the RevPi."""
|
|
feature_function = get_feature(feature)
|
|
return feature_function.function(ConfigActions.AVAILABLE, *feature_function.args)
|
|
|
|
@property
|
|
def available_features(self) -> list[str]:
|
|
return list(AVAILABLE_FEATURES.keys())
|
|
|
|
|
|
def get_feature(feature: str) -> FeatureFunction:
|
|
if feature not in AVAILABLE_FEATURES:
|
|
raise ValueError(f"feature {feature} does not exist")
|
|
feature_function = AVAILABLE_FEATURES[feature]
|
|
if not feature_function:
|
|
raise NotImplementedError(f"feature {feature} is not implemented")
|
|
return feature_function
|
|
|
|
|
|
AVAILABLE_FEATURES = {
|
|
"gui": FeatureFunction(configure_gui, []),
|
|
"revpi-con-can": FeatureFunction(configure_con_can, []),
|
|
"swapfile": FeatureFunction(configure_dphys_swapfile, []),
|
|
"bluetooth": FeatureFunction(configure_bluetooth, []),
|
|
"external-antenna": FeatureFunction(configure_external_antenna, []),
|
|
}
|