feat(cli): Add D-Bus helper functions for CLI commands.
This introduces `simple_call`, a utility function to interact with D-Bus interfaces within the RevPi system. It facilitates method invocation on specific interfaces and paths, improving modularity and code reuse in middleware operations.
This commit is contained in:
46
src/revpi_middleware/cli_commands/cli_picontrol.py
Normal file
46
src/revpi_middleware/cli_commands/cli_picontrol.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# SPDX-FileCopyrightText: 2025 KUNBUS GmbH
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
"""Command-Line for the picontrol object of CLI."""
|
||||
from argparse import ArgumentParser
|
||||
from logging import getLogger
|
||||
|
||||
from .dbus_helper import simple_call
|
||||
from .. import proginit as pi
|
||||
from ..dbus_middleware1 import extend_interface
|
||||
|
||||
log = getLogger(__name__)
|
||||
|
||||
|
||||
def add_subparsers(parent_parser: ArgumentParser):
|
||||
methods = parent_parser.add_subparsers(
|
||||
dest="methods",
|
||||
title="methods",
|
||||
help="Available RevPi PiControl methods",
|
||||
)
|
||||
methods.add_parser(
|
||||
"reset",
|
||||
help="Reset the piControl driver",
|
||||
)
|
||||
|
||||
|
||||
def method_reset():
|
||||
log.debug("D-Bus call of method ResetDriver")
|
||||
simple_call("ResetDriver", interface=extend_interface("picontrol"))
|
||||
log.info("ResetDriver called via D-Bus")
|
||||
|
||||
|
||||
def main() -> int:
|
||||
method = pi.pargs.methods
|
||||
try:
|
||||
|
||||
if method == "reset":
|
||||
method_reset()
|
||||
|
||||
else:
|
||||
raise Exception(f"Unknown method: {method}")
|
||||
|
||||
except Exception as e:
|
||||
log.error(f"Error: {e}")
|
||||
return 1
|
||||
|
||||
return 0
|
||||
Reference in New Issue
Block a user