Skip to content

Commit

Permalink
Jkbms_pb added possibility to use port as unique identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-manuel committed Oct 16, 2024
1 parent dddae4d commit 8ccaed3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 10 additions & 2 deletions etc/dbus-serialbattery/bms/jkbms_pb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Added by https://github.com/KoljaWindeler

from battery import Battery, Cell
from utils import read_serial_data, logger
from utils import bytearray_to_string, read_serial_data, logger, USE_PORT_AS_UNIQUE_ID
from struct import unpack_from
import sys

Expand Down Expand Up @@ -262,7 +262,15 @@ def unique_identifier(self) -> str:
"""
Used to identify a BMS when multiple BMS are connected
"""
return self.unique_identifier_tmp
# TODO: Temporary solution, since the serial number is not correctly read
if USE_PORT_AS_UNIQUE_ID:
return self.port + (
"__" + bytearray_to_string(self.address).replace("\\", "0")
if self.address is not None
else ""
)
else:
return self.unique_identifier_tmp

def get_balancing(self):
return 1 if self.balancing else 0
Expand Down
6 changes: 5 additions & 1 deletion etc/dbus-serialbattery/dbushelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ def __init__(self, battery, bms_address=None):
self._dbusname = (
"com.victronenergy.battery."
+ self.battery.port[self.battery.port.rfind("/") + 1 :]
+ ("__" + str(bms_address) if bms_address is not None else "")
+ (
"__" + str(bms_address)
if bms_address is not None and bms_address != 0
else ""
)
)
self._dbusservice = VeDbusService(self._dbusname, get_bus(), register=False)
self.bms_id = "".join(
Expand Down

0 comments on commit 8ccaed3

Please sign in to comment.