Introduce the `configure_con_can` function to manage enabling, disabling, status checking, and availability of the 'revpi-con-can' feature. Update the `AVAILABLE_FEATURES` dictionary to integrate 'revpi-con-can' as a configurable feature.
99 lines
3.6 KiB
Python
99 lines
3.6 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 .revpi_config import (
|
|
ConfigActions,
|
|
configure_avahi_daemon,
|
|
configure_con_can,
|
|
configure_dphys_swapfile,
|
|
configure_external_antenna,
|
|
configure_gui,
|
|
simple_systemd,
|
|
)
|
|
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"/>
|
|
</interface>
|
|
</node>
|
|
"""
|
|
|
|
def Disable(self, feature: str) -> None:
|
|
"""Disable the feature."""
|
|
feature_function = get_feature(feature)
|
|
feature_function.function(ConfigActions.DISABLE, *feature_function.args)
|
|
|
|
def Enable(self, feature: str) -> None:
|
|
"""Enable the feature."""
|
|
feature_function = get_feature(feature)
|
|
feature_function.function(ConfigActions.ENABLE, *feature_function.args)
|
|
|
|
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, []),
|
|
"dphys-swapfile": FeatureFunction(configure_dphys_swapfile, []),
|
|
"pimodbus-master": FeatureFunction(simple_systemd, ["pimodbus-master.service"]),
|
|
"pimodbus-slave": FeatureFunction(simple_systemd, ["pimodbus-slave.service"]),
|
|
"systemd-timesyncd": FeatureFunction(simple_systemd, ["systemd-timesyncd.service"]),
|
|
"ssh": FeatureFunction(simple_systemd, ["ssh.service"]),
|
|
"nodered": FeatureFunction(simple_systemd, ["nodered.service"]),
|
|
"noderedrevpinodes-server": FeatureFunction(
|
|
simple_systemd, ["noderedrevpinodes-server.service"]
|
|
),
|
|
"revpipyload": FeatureFunction(simple_systemd, ["revpipyload.service"]),
|
|
"bluetooth": False,
|
|
"ieee80211": False,
|
|
"avahi": FeatureFunction(configure_avahi_daemon, []),
|
|
"external-antenna": FeatureFunction(configure_external_antenna, []),
|
|
}
|