# -*- 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_bluetooth, configure_con_can, configure_dphys_swapfile, configure_external_antenna, configure_gui, configure_wlan, simple_systemd, ) from ..dbus_helper import DbusInterface log = getLogger(__name__) FeatureFunction = namedtuple("FeatureFunction", ["function", "args"]) class InterfaceRevpiConfig(DbusInterface): """ """ 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": FeatureFunction(configure_bluetooth, []), "wlan": FeatureFunction(configure_wlan, []), "avahi": FeatureFunction(configure_avahi_daemon, []), "external-antenna": FeatureFunction(configure_external_antenna, []), }