feat(io): Add InterfaceDevice class for device handling via D-Bus
Introduced the `InterfaceDevice` class, enabling detailed device property access through D-Bus. Updated `bus_provider_io` to include device interfaces in the D-Bus provider. Signed-off-by: Sven Sager <s.sager@kunbus.com>
This commit is contained in:
@@ -8,11 +8,11 @@ from threading import Thread
|
||||
import revpimodio2
|
||||
from gi.repository import GLib
|
||||
from pydbus import SessionBus, SystemBus
|
||||
from revpimodio2 import Cycletools
|
||||
|
||||
from . import REVPI_DBUS_NAME
|
||||
from .interface_devices import (
|
||||
InterfaceDeviceManager,
|
||||
InterfaceDevice,
|
||||
)
|
||||
from .interface_ios import (
|
||||
InterfaceIoManager,
|
||||
@@ -75,6 +75,10 @@ class BusProviderIo(Thread):
|
||||
lst_interfaces = [
|
||||
(f"io/{io_name}", self._dc_io_interfaces[io_name]) for io_name in self._dc_io_interfaces
|
||||
]
|
||||
lst_interfaces += [
|
||||
(f"device/{device.position}", InterfaceDevice(self._bus, device))
|
||||
for device in self._modio.device
|
||||
]
|
||||
try:
|
||||
self._bus.publish(
|
||||
REVPI_DBUS_NAME,
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
# 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
|
||||
from dbus import SystemBus, SessionBus
|
||||
from pydbus.generic import signal
|
||||
from revpimodio2 import RevPiModIO
|
||||
from revpimodio2.device import Device
|
||||
|
||||
from .ios1_helper import REVPI_DBUS_BASE_PATH
|
||||
|
||||
|
||||
class InterfaceDeviceManager:
|
||||
@@ -44,3 +46,49 @@ class InterfaceDeviceManager:
|
||||
return self._get_device_path(device_position)
|
||||
|
||||
raise KeyError(f"No device on position '{device_position}' found.")
|
||||
|
||||
|
||||
class InterfaceDevice:
|
||||
"""
|
||||
<node>
|
||||
<interface name="com.revolutionpi.ios1.Device">
|
||||
<property name="bmk" type="s" access="read"/>
|
||||
<property name="catalognr" type="s" access="read"/>
|
||||
<property name="comment" type="s" access="read"/>
|
||||
<property name="id" type="s" access="read"/>
|
||||
<property name="name" type="s" access="read"/>
|
||||
<property name="type" type="s" access="read"/>
|
||||
</interface>
|
||||
</node>
|
||||
"""
|
||||
|
||||
interface_name = "com.revolutionpi.ios1.Device"
|
||||
PropertiesChanged = signal()
|
||||
|
||||
def __init__(self, dbus: SystemBus or SessionBus, device: Device):
|
||||
self.dbus = dbus
|
||||
self.device = device
|
||||
|
||||
@property
|
||||
def bmk(self) -> str:
|
||||
return self.device.bmk
|
||||
|
||||
@property
|
||||
def catalognr(self):
|
||||
return self.device.catalognr
|
||||
|
||||
@property
|
||||
def comment(self):
|
||||
return self.device.comment
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self.device.id
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self.device.name
|
||||
|
||||
@property
|
||||
def type(self):
|
||||
return self.device.type
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
# SPDX-FileCopyrightText: 2025 KUNBUS GmbH
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
"""Helper for io read and write."""
|
||||
|
||||
from logging import getLogger
|
||||
|
||||
from gi.overrides.GLib import Variant
|
||||
from pydbus import SessionBus, SystemBus
|
||||
from pydbus.generic import signal
|
||||
from revpimodio2.io import IOBase
|
||||
|
||||
Reference in New Issue
Block a user