Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved some bluetooth specific code from each implementation to a common place #56

Merged
merged 5 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 7 additions & 2 deletions etc/dbus-serialbattery/dbus-serialbattery.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,16 @@ 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 len(sys.argv) <= 2
logger.error("missing bluetooth address")
calledit marked this conversation as resolved.
Show resolved Hide resolved
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
Expand All @@ -184,7 +189,7 @@ def get_port() -> str:
from bms.lltjbd_ble import LltJbd_Ble # noqa: F401

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