Skip to content

Commit

Permalink
Add option to ignore particular services
Browse files Browse the repository at this point in the history
Add option to ignore services when they start with some string.
Useful when "com.victronenergy.product" is monitored
but "com.victronenergy.product.someinstance" must be ignored
  • Loading branch information
ReinvdZee committed Mar 25, 2024
1 parent c91b783 commit 838c12a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion dbusmonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,15 @@ def service_class(self):
class DbusMonitor(object):
## Constructor
def __init__(self, dbusTree, valueChangedCallback=None, deviceAddedCallback=None,
deviceRemovedCallback=None, namespace="com.victronenergy"):
deviceRemovedCallback=None, namespace="com.victronenergy", ignoreServices=[]):
# valueChangedCallback is the callback that we call when something has changed.
# def value_changed_on_dbus(dbusServiceName, dbusPath, options, changes, deviceInstance):
# in which changes is a tuple with GetText() and GetValue()
self.valueChangedCallback = valueChangedCallback
self.deviceAddedCallback = deviceAddedCallback
self.deviceRemovedCallback = deviceRemovedCallback
self.dbusTree = dbusTree
self.ignoreServices = ignoreServices

# Lists all tracked services. Stores name, id, device instance, value per path, and whenToLog info
# indexed by service name (eg. com.victronenergy.settings).
Expand Down Expand Up @@ -190,6 +191,10 @@ def scan_dbus_service_inner(self, serviceName):
# make it a normal string instead of dbus string
serviceName = str(serviceName)

if (len(self.ignoreServices) != 0 and any(serviceName.startswith(x) for x in self.ignoreServices)):
logger.debug("Ignoring service %s" % serviceName)
return False

paths = self.dbusTree.get('.'.join(serviceName.split('.')[0:3]), None)
if paths is None:
logger.debug("Ignoring service %s, not in the tree" % serviceName)
Expand Down

3 comments on commit 838c12a

@realdognose
Copy link

@realdognose realdognose commented on 838c12a Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, i'm scratching my head at the moment.

I used this ignoreServices until this noon on my cerbo. Now it starts to report "unknown parameter".
and yes, the file under /opt/victronenergy/dbus-systemcalc-py/ext/velib_python I used suddenly misses this.

has this been removed again?

Edit:
Apparently 4 days ago, but had to clean pycache today :(

image

@ReinvdZee
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @realdognose,

This has not been removed from velib_python. However, dbus-systemcalc-py checks out an older version of velib_python so its not included in /opt/victronenergy/dbus-systemcalc-py/ext/velib_python.
You can update the submodule within dbus-systemcalc-py. Another option is to use velib_python from another service, like dbus-parallel-bms (note, only on Venus OS beta) which checks out the most recent version of velib_python, i.e. /opt/victronenergy/dbus-parallel-bms/ext/velib_python.

@realdognose
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ReinvdZee

Thanks for your reply. Will see if there is a more recent version somewhere on my system. Pretty strange thing is, that the exact file under /opt/victronenergy/dbus-systemcalc-py/ext/velib_python apparently had it earlier - I used that include since 6 weeks, with the ignoreServices-Option present...

I manually included the most recent build for 1 day, until I noted it ships with the system. Then I removed it from my project. Hard to imagine that py-cache somehow kept the old reference to the no longer existing file around for several weeks? But most likely the only explanation, if /opt/victronenergy/dbus-systemcalc-py never used a more recent version.

Please sign in to comment.