-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdbus-btoutback.py
More file actions
executable file
·78 lines (59 loc) · 2.04 KB
/
Copy pathdbus-btoutback.py
File metadata and controls
executable file
·78 lines (59 loc) · 2.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
from outbackbt import OutbackBtDev
from dbus.mainloop.glib import DBusGMainLoop
from threading import Thread
import sys
if sys.version_info.major == 2:
import gobject
else:
from gi.repository import GLib as gobject
# Victron packages
# from ve_utils import exit_on_error
from dbushelper import DbusHelper
from utils import *
import utils
from inverter import Inverter
from outbackbt import OutbackBt
logger.info("Starting dbus-btoutback")
def main():
def get_btaddr() -> list:
# Get the bluetooth address we need to use from the argument
if len(sys.argv) > 1:
return sys.argv[1:]
else:
return [utils.OUTBACK_ADDRESS]
logger.info("dbus-btoutback v" + str(utils.DRIVER_VERSION) + utils.DRIVER_SUBVERSION)
btaddr = get_btaddr()
outbackBtDevConnection = OutbackBtDev(btaddr[0])
outbackInverterObject: Inverter = OutbackBt(outbackBtDevConnection, btaddr[0])
outbackBtDevConnection.connect()
if outbackInverterObject is None:
logger.error("ERROR >>> No Inverter connection at " + str(btaddr))
sys.exit(1)
outbackInverterObject.log_settings()
# Have a mainloop, so we can send/receive asynchronous calls to and from dbus
DBusGMainLoop(set_as_default=True)
if sys.version_info.major == 2:
gobject.threads_init()
mainloop = gobject.MainLoop()
# Get the initial values for the battery used by setup_vedbus
inverterDevice = DbusHelper(outbackInverterObject, 1)
if not inverterDevice.setup_vedbus():
logger.error("ERROR >>> Problem with inverter " + str(btaddr))
sys.exit(1)
def poll_inverter(loop):
# Run in separate thread. Pass in the mainloop so the thread can kill us if there is an exception.
poller = Thread(target=lambda: inverterDevice.publish_inverter(loop))
# Thread will die with us if deamon
poller.daemon = True
poller.start()
return True
# Poll the battery at INTERVAL and run the main loop
gobject.timeout_add(outbackInverterObject.poll_interval, lambda: poll_inverter(mainloop))
try:
mainloop.run()
except KeyboardInterrupt:
pass
if __name__ == "__main__":
main()