diff --git a/src/revpi_middleware/ios1/interface_devices.py b/src/revpi_middleware/ios1/interface_devices.py index 75723f2..de4c756 100644 --- a/src/revpi_middleware/ios1/interface_devices.py +++ b/src/revpi_middleware/ios1/interface_devices.py @@ -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: - + - - + + + + + + @@ -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