Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions etc/dbus-serialbattery/bms/jkbms_ble.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ class Jkbms_Ble(Battery):
resetting = False

def __init__(self, port, baud, address):
# add "ble_" to the port name, since only numbers are not valid
super(Jkbms_Ble, self).__init__(
"ble_" + address.replace(":", "").lower(), baud, address
port, baud, address
)
self.address = address
self.type = self.BATTERYTYPE
Expand Down
3 changes: 1 addition & 2 deletions etc/dbus-serialbattery/bms/lltjbd_ble.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ class LltJbd_Ble(LltJbd):
BATTERYTYPE = "LltJbd_Ble"

def __init__(self, port: Optional[str], baud: Optional[int], address: str):
# add "ble_" to the port name, since only numbers are not valid
super(LltJbd_Ble, self).__init__(
"ble_" + address.replace(":", "").lower(), -1, address
port, -1, address
)

self.address = address
Expand Down
34 changes: 20 additions & 14 deletions etc/dbus-serialbattery/dbus-serialbattery.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,24 +170,30 @@ def get_port() -> str:
# else the error throw a lot of timeouts
sleep(16)

if port.endswith("_Ble") and len(sys.argv) > 2:
if port.endswith("_Ble"):
"""
Import ble classes only, if it's a ble port, else the driver won't start due to missing python modules
This prevent problems when using the driver only with a serial connection
"""
if port == "Jkbms_Ble":
# noqa: F401 --> ignore flake "imported but unused" error
from bms.jkbms_ble import Jkbms_Ble # noqa: F401

if port == "LltJbd_Ble":
# noqa: F401 --> ignore flake "imported but unused" error
from bms.lltjbd_ble import LltJbd_Ble # noqa: F401

class_ = eval(port)
testbms = class_("", 9600, sys.argv[2])
if testbms.test_connection():
logger.info("Connection established to " + testbms.__class__.__name__)
battery = testbms

if len(sys.argv) <= 2:
logger.error("missing bluetooth address")
else:
ble_address = sys.argv[2]

if port == "Jkbms_Ble":
# noqa: F401 --> ignore flake "imported but unused" error
from bms.jkbms_ble import Jkbms_Ble # noqa: F401

if port == "LltJbd_Ble":
# noqa: F401 --> ignore flake "imported but unused" error
from bms.lltjbd_ble import LltJbd_Ble # noqa: F401

class_ = eval(port)
testbms = class_("ble_" + ble_address.replace(":", "").lower(), 9600, ble_address)
if testbms.test_connection():
logger.info("Connection established to " + testbms.__class__.__name__)
battery = testbms

elif port.startswith("can"):
"""
Expand Down