-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdummybattery.py
57 lines (48 loc) · 1.96 KB
/
dummybattery.py
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
import platform
from gi.repository import GLib
from dbus_entities import dbusconnection
from vedbus import VeDbusService
class DummyBattery(object):
def __init__(self):
self._dbusservice = VeDbusService(
"com.victronenergy.battery.dummy", dbusconnection()
)
self._paths = {
"/Dc/0/Voltage": {"initial": 54.0},
"/Dc/0/Current": {"initial": 0.926},
"/Dc/0/Power": {"initial": 50.0},
}
# Create the management objects, as specified in the ccgx dbus-api document
self._dbusservice.add_path("/Mgmt/ProcessName", __file__)
self._dbusservice.add_path(
"/Mgmt/ProcessVersion",
"Unkown version, and running on Python " + platform.python_version(),
)
self._dbusservice.add_path("/Mgmt/Connection", "Not implemented")
# Create the mandatory objects
self._dbusservice.add_path("/DeviceInstance", 0)
self._dbusservice.add_path("/ProductId", 0)
self._dbusservice.add_path("/ProductName", "Dummy Battery")
self._dbusservice.add_path("/FirmwareVersion", 0)
self._dbusservice.add_path("/HardwareVersion", 0)
self._dbusservice.add_path("/Connected", 1)
for path, settings in self._paths.items():
self._dbusservice.add_path(
path,
settings["initial"],
writeable=True,
onchangecallback=self._handlechangedvalue,
)
GLib.timeout_add(1000, self._update)
def _update(self):
with self._dbusservice as s:
for path, settings in self._paths.items():
if "update" in settings:
update = settings["update"]
if callable(update):
s[path] = update(path, s[path])
else:
s[path] += update
return True
def _handlechangedvalue(self, path, value):
return True