-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-coexist.py
More file actions
executable file
·87 lines (67 loc) · 3.04 KB
/
test-coexist.py
File metadata and controls
executable file
·87 lines (67 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3
"""
Test: Can we export objects that coexist with dbus-ble-sensors objects?
"""
import sys
sys.path.insert(1, '/opt/victronenergy/dbus-systemcalc-py/ext/velib_python')
import dbus
from dbus.mainloop.glib import DBusGMainLoop
from gi.repository import GLib
from vedbus import VeDbusService
print("Testing coexistence with dbus-ble-sensors...")
DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
# Check dbus-ble-sensors is running
proxy = bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus')
dbus_iface = dbus.Interface(proxy, 'org.freedesktop.DBus')
if 'com.victronenergy.ble' not in dbus_iface.ListNames():
print("ERROR: dbus-ble-sensors not running")
sys.exit(1)
print("✓ dbus-ble-sensors is running")
# Check existing devices
print("\nExisting devices before our test:")
existing = bus.get_object('com.victronenergy.ble', '/Devices')
intro = dbus.Interface(existing, 'org.freedesktop.DBus.Introspectable')
xml = intro.Introspect()
import re
existing_devices = re.findall(r'<node name="([^"]+)"', xml)
for dev in existing_devices[:5]:
print(f" - {dev}")
if len(existing_devices) > 5:
print(f" ... and {len(existing_devices)-5} more")
# Now try to add OUR objects using a different service name
# but at paths that should appear under com.victronenergy.ble
print("\nCreating our own service with device paths...")
try:
# Create our service with a DIFFERENT name
our_service = VeDbusService('com.victronenergy.ble.integrations', bus)
# But add paths that LOOK like they're under com.victronenergy.ble
our_service.add_path('/Devices/integration_test_device/Name', 'Test Integration')
our_service.add_path('/Devices/integration_test_device/Enabled', 0)
print("✓ Created com.victronenergy.ble.integrations with /Devices paths")
# Can we read it via OUR service name?
test1 = bus.get_object('com.victronenergy.ble.integrations', '/Devices/integration_test_device/Name')
val1 = dbus.Interface(test1, 'com.victronenergy.BusItem').GetValue()
print(f"✓ Via com.victronenergy.ble.integrations: '{val1}'")
# Does it appear when listing com.victronenergy.ble devices?
print("\nChecking if it appears in com.victronenergy.ble /Devices...")
existing = bus.get_object('com.victronenergy.ble', '/Devices')
intro = dbus.Interface(existing, 'org.freedesktop.DBus.Introspectable')
xml = intro.Introspect()
devices_now = re.findall(r'<node name="([^"]+)"', xml)
if 'integration_test_device' in devices_now:
print("✓ YES! Our device appears in com.victronenergy.ble listing!")
else:
print("✗ No, our device does NOT appear in com.victronenergy.ble")
print(f"Devices now: {devices_now[:5]}")
print("\nKeeping alive for 30 seconds for manual testing...")
def timeout():
mainloop.quit()
return False
GLib.timeout_add_seconds(30, timeout)
mainloop = GLib.MainLoop()
mainloop.run()
except Exception as e:
print(f"✗ Error: {e}")
import traceback
traceback.print_exc()