From 0e513cd179a2bf725260e5fa8cb0dcee2fa3a9fb Mon Sep 17 00:00:00 2001 From: Sven Sager Date: Mon, 21 Apr 2025 10:49:47 +0200 Subject: [PATCH] feat(cli): Add `get_properties` helper function for DBus interactions This function facilitates retrieving specific properties from a DBus interface, improving code modularity and reusability. It supports both system and session bus types, streamlining access to DBus resources. --- src/revpi_middleware/cli_commands/dbus_helper.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/revpi_middleware/cli_commands/dbus_helper.py b/src/revpi_middleware/cli_commands/dbus_helper.py index e14f072..45d6690 100644 --- a/src/revpi_middleware/cli_commands/dbus_helper.py +++ b/src/revpi_middleware/cli_commands/dbus_helper.py @@ -17,6 +17,18 @@ class BusType(Enum): SYSTEM = "system" +def get_properties( + property_name: str, + interface: str, + object_path=REVPI_DBUS_BASE_PATH, + bus_type=BusType.SYSTEM, +): + bus = SessionBus() if bus_type is BusType.SESSION else SystemBus() + revpi = bus.get(REVPI_DBUS_NAME, object_path) + iface = revpi[interface] + return getattr(iface, property_name) + + def simple_call( method: str, *args,