diff --git a/test/mock_dbus_service.py b/test/mock_dbus_service.py index 471c801..c74937b 100644 --- a/test/mock_dbus_service.py +++ b/test/mock_dbus_service.py @@ -12,6 +12,10 @@ def add_path(self, path, value, description="", writeable=False, onchangecallbac if onchangecallback is not None: self._callbacks[path] = onchangecallback + def register(self): + # Nothing to do when mocking + pass + # Add the mandatory paths, as per victron dbus api doc def add_mandatory_paths(self, processname, processversion, connection, deviceinstance, productid, productname, firmwareversion, hardwareversion, connected): diff --git a/vedbus.py b/vedbus.py index 4b73aa3..0407f6c 100644 --- a/vedbus.py +++ b/vedbus.py @@ -64,6 +64,7 @@ def __init__(self, servicename, bus=None): self._dbusnodes = {} self._ratelimiters = [] self._dbusname = None + self.name = servicename # dict containing the onchange callbacks, for each object. Object path is the key self._onchangecallbacks = {} @@ -74,13 +75,13 @@ def __init__(self, servicename, bus=None): # make the dbus connection available to outside, could make this a true property instead, but ach.. self.dbusconn = self._dbusconn - # Register ourselves on the dbus, trigger an error if already in use (do_not_queue) - self._dbusname = dbus.service.BusName(servicename, self._dbusconn, do_not_queue=True) - # Add the root item that will return all items as a tree self._dbusnodes['/'] = VeDbusRootExport(self._dbusconn, '/', self) - logging.info("registered ourselves on D-Bus as %s" % servicename) + def register(self): + # Register ourselves on the dbus, trigger an error if already in use (do_not_queue) + self._dbusname = dbus.service.BusName(self.name, self._dbusconn, do_not_queue=True) + logging.info("registered ourselves on D-Bus as %s" % self.name) # To force immediate deregistering of this dbus service and all its object paths, explicitly # call __del__().