feat(dbus): Add support for configuring 'revpi-con-can' feature
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.
This commit is contained in:
@@ -8,6 +8,7 @@ from logging import getLogger
|
||||
from .revpi_config import (
|
||||
ConfigActions,
|
||||
configure_avahi_daemon,
|
||||
configure_con_can,
|
||||
configure_dphys_swapfile,
|
||||
configure_external_antenna,
|
||||
configure_gui,
|
||||
@@ -79,7 +80,7 @@ def get_feature(feature: str) -> FeatureFunction:
|
||||
|
||||
AVAILABLE_FEATURES = {
|
||||
"gui": FeatureFunction(configure_gui, []),
|
||||
"revpi-con-can": False,
|
||||
"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"]),
|
||||
|
||||
@@ -260,6 +260,34 @@ def configure_gui(action: ConfigActions):
|
||||
raise ValueError(f"action {action} not supported")
|
||||
|
||||
|
||||
def configure_con_can(action: ConfigActions):
|
||||
revpi = RevPiConfig()
|
||||
if action is ConfigActions.AVAILABLE:
|
||||
return revpi.with_con_bridge
|
||||
|
||||
dt_overlay = "revpi-con-can"
|
||||
config_txt = ConfigTxt()
|
||||
|
||||
if action is ConfigActions.ENABLE and revpi.with_con_bridge:
|
||||
config_txt.clear_dtoverlays([dt_overlay])
|
||||
config_txt.add_name_value("dtoverlay", dt_overlay)
|
||||
config_txt.save_config()
|
||||
subprocess.call(["/usr/bin/dtoverlay", dt_overlay])
|
||||
|
||||
elif action is ConfigActions.DISABLE and revpi.with_con_bridge:
|
||||
config_txt.clear_dtoverlays([dt_overlay])
|
||||
config_txt.save_config()
|
||||
subprocess.call(["/usr/bin/dtoverlay", "-r", dt_overlay])
|
||||
|
||||
elif action is ConfigActions.STATUS:
|
||||
return revpi.with_con_bridge and dt_overlay in config_txt.get_values("dtparam")
|
||||
|
||||
else:
|
||||
raise ValueError(f"action {action} not supported")
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def simple_systemd(action: ConfigActions, unit: str):
|
||||
bus = SystemBus()
|
||||
systemd_manager = bus.get(".systemd1")
|
||||
|
||||
Reference in New Issue
Block a user