feat(io): Add GetByName and GetByPosition methods to DeviceManager

Introduced `GetByName` and `GetByPosition` methods in the D-Bus
interface and implementation for retrieving device object paths by name
or position. Updated `GetAllDevices` return type to `ao`.

Signed-off-by: Sven Sager <s.sager@kunbus.com>
This commit is contained in:
Sven Sager
2026-02-04 14:58:45 +01:00
parent 8ee5e0836f
commit 710d7b2078

View File

@@ -3,6 +3,8 @@
# SPDX-License-Identifier: GPL-2.0-or-later
"""D-Bus interfaces for IOs."""
from typing import Union
from dbus import SystemBus, SessionBus
from pydbus.generic import signal
from revpimodio2 import RevPiModIO
@@ -16,10 +18,14 @@ class InterfaceDeviceManager:
<node>
<interface name="com.revolutionpi.ios1.DeviceManager">
<method name="GetAllDevices">
<arg type="as" direction="out"/>
<arg type="ao" direction="out"/>
</method>
<method name="Get">
<arg name="device_name" type="s" direction="in"/>
<method name="GetByName">
<arg name="device-name" type="s" direction="in"/>
<arg name="object-path" type="o" direction="out"/>
</method>
<method name="GetByPosition">
<arg name="device-position" type="n" direction="in"/>
<arg name="object-path" type="o" direction="out"/>
</method>
</interface>
@@ -41,7 +47,13 @@ class InterfaceDeviceManager:
def GetAllDevices(self) -> list[str]:
return self.lst_device
def Get(self, device_position) -> str:
def GetByName(self, device_name) -> str:
if device_name in self.modio.device:
return self._get_device_path(self.modio.device[device_name].position)
raise KeyError(f"No device with name '{device_name}' found.")
def GetByPosition(self, device_position) -> str:
if device_position in self.modio.device:
return self._get_device_path(device_position)
@@ -68,7 +80,7 @@ class InterfaceDevice:
interface_name = "com.revolutionpi.ios1.Device"
PropertiesChanged = signal()
def __init__(self, dbus: SystemBus or SessionBus, device: Device):
def __init__(self, dbus: Union[SystemBus, SessionBus], device: Device):
self.dbus = dbus
self.device = device