feat(io): Add InterfaceDeviceManager to D-Bus bus provider
Integrated the InterfaceDeviceManager class into the com.revolutionpi .ios1 D-Bus bus provider. This addition enables managing device paths and querying all devices via D-Bus. Signed-off-by: Sven Sager <s.sager@kunbus.com>
This commit is contained in:
@@ -11,6 +11,9 @@ from pydbus import SessionBus, SystemBus
|
|||||||
from revpimodio2 import Cycletools
|
from revpimodio2 import Cycletools
|
||||||
|
|
||||||
from . import REVPI_DBUS_NAME
|
from . import REVPI_DBUS_NAME
|
||||||
|
from .interface_devices import (
|
||||||
|
InterfaceDeviceManager,
|
||||||
|
)
|
||||||
from .interface_ios import (
|
from .interface_ios import (
|
||||||
InterfaceIoManager,
|
InterfaceIoManager,
|
||||||
InterfaceInpBool,
|
InterfaceInpBool,
|
||||||
@@ -75,6 +78,7 @@ class BusProviderIo(Thread):
|
|||||||
try:
|
try:
|
||||||
self._bus.publish(
|
self._bus.publish(
|
||||||
REVPI_DBUS_NAME,
|
REVPI_DBUS_NAME,
|
||||||
|
InterfaceDeviceManager(self._modio),
|
||||||
InterfaceIoManager(self._modio, self._dc_io_interfaces),
|
InterfaceIoManager(self._modio, self._dc_io_interfaces),
|
||||||
*lst_interfaces,
|
*lst_interfaces,
|
||||||
)
|
)
|
||||||
|
|||||||
46
src/revpi_middleware/ios1/interface_devices.py
Normal file
46
src/revpi_middleware/ios1/interface_devices.py
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# SPDX-FileCopyrightText: 2025 KUNBUS GmbH
|
||||||
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
"""D-Bus interfaces for IOs."""
|
||||||
|
from gi.overrides.GLib import Variant
|
||||||
|
from pydbus.generic import signal
|
||||||
|
from revpimodio2 import RevPiModIO, Cycletools
|
||||||
|
|
||||||
|
from .ios1_helper import REVPI_DBUS_BASE_PATH, DbusInterfaceIo
|
||||||
|
|
||||||
|
|
||||||
|
class InterfaceDeviceManager:
|
||||||
|
"""
|
||||||
|
<node>
|
||||||
|
<interface name="com.revolutionpi.ios1.DeviceManager">
|
||||||
|
<method name="GetAllDevices">
|
||||||
|
<arg type="as" direction="out"/>
|
||||||
|
</method>
|
||||||
|
<method name="Get">
|
||||||
|
<arg name="device_name" type="s" direction="in"/>
|
||||||
|
<arg name="object-path" type="o" direction="out"/>
|
||||||
|
</method>
|
||||||
|
</interface>
|
||||||
|
</node>
|
||||||
|
"""
|
||||||
|
|
||||||
|
interface_name = "com.revolutionpi.ios1.DeviceManager"
|
||||||
|
|
||||||
|
def __init__(self, modio: RevPiModIO):
|
||||||
|
self.modio = modio
|
||||||
|
|
||||||
|
self.lst_device = []
|
||||||
|
for dev in self.modio.device:
|
||||||
|
self.lst_device.append(self._get_device_path(dev.position))
|
||||||
|
|
||||||
|
def _get_device_path(self, position: int) -> str:
|
||||||
|
return f"{REVPI_DBUS_BASE_PATH}/device/{position}"
|
||||||
|
|
||||||
|
def GetAllDevices(self) -> list[str]:
|
||||||
|
return self.lst_device
|
||||||
|
|
||||||
|
def Get(self, device_position) -> str:
|
||||||
|
if device_position in self.modio.device:
|
||||||
|
return self._get_device_path(device_position)
|
||||||
|
|
||||||
|
raise KeyError(f"No device on position '{device_position}' found.")
|
||||||
Reference in New Issue
Block a user