diff --git a/.github/workflows/release-beta.yml b/.github/workflows/release-beta.yml index f1634f34..d2e368c0 100644 --- a/.github/workflows/release-beta.yml +++ b/.github/workflows/release-beta.yml @@ -8,7 +8,7 @@ on: # v1.0.0alpha20230507 # v1.0.0-beta20230507 # v1.0.0-development-20230507 - - "v*.*.[0-9]+-?[a-zA-Z]*" + - "v[0-9]+.[0-9]+.[0-9]+-?[a-zA-Z]*" jobs: build: diff --git a/CHANGELOG.md b/CHANGELOG.md index 9743edd9..d827a1d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,12 +22,18 @@ * `BULK_CELL_VOLTAGE` -> `SOC_RESET_VOLTAGE` * `BULK_AFTER_DAYS` -> `SOC_RESET_AFTER_DAYS` -## v1.0.x +## v1.1.x +* Changed: JKBMS BLE - Fix driver gets unresponsive, if connection is lost https://github.com/Louisvdw/dbus-serialbattery/issues/720 with https://github.com/Louisvdw/dbus-serialbattery/pull/941 by @cupertinomiranda +* Changed: JKBMS BLE - Fix temperature issue https://github.com/Louisvdw/dbus-serialbattery/issues/916 by @mr-manuel + +## v1.1.20240121 + +* Changed: Exit the driver with error, when port is excluded in config, else the serialstarter does not continue by @mr-manuel * Changed: Fix issue on first driver startup, when no device setting in dbus exists by @mr-manuel +* Changed: Fixed some smaller errors by @mr-manuel * Changed: More detailed error output when an exception happens by @mr-manuel - ## v1.0.20240102beta * Added: Bluetooth: Show signal strength of BMS in log by @mr-manuel diff --git a/etc/dbus-serialbattery/battery.py b/etc/dbus-serialbattery/battery.py index aa02a2de..07c53bcb 100644 --- a/etc/dbus-serialbattery/battery.py +++ b/etc/dbus-serialbattery/battery.py @@ -666,7 +666,10 @@ def manage_charge_current(self) -> None: # if BMS limit is lower then config limit and therefore the values are not the same, # then the limit was also read from the BMS - if utils.MAX_BATTERY_CHARGE_CURRENT > self.max_battery_charge_current: + if ( + isinstance(self.max_battery_charge_current, (int, float)) + and utils.MAX_BATTERY_CHARGE_CURRENT > self.max_battery_charge_current + ): charge_limits.update({self.max_battery_charge_current: "BMS Settings"}) if utils.CCCM_CV_ENABLE: @@ -747,7 +750,10 @@ def manage_charge_current(self) -> None: # if BMS limit is lower then config limit and therefore the values are not the same, # then the limit was also read from the BMS - if utils.MAX_BATTERY_DISCHARGE_CURRENT > self.max_battery_discharge_current: + if ( + isinstance(self.max_battery_discharge_current, (int, float)) + and utils.MAX_BATTERY_DISCHARGE_CURRENT > self.max_battery_discharge_current + ): discharge_limits.update( {self.max_battery_discharge_current: "BMS Settings"} ) diff --git a/etc/dbus-serialbattery/bms/jkbms_ble.py b/etc/dbus-serialbattery/bms/jkbms_ble.py index 8ebab536..e464f072 100644 --- a/etc/dbus-serialbattery/bms/jkbms_ble.py +++ b/etc/dbus-serialbattery/bms/jkbms_ble.py @@ -181,9 +181,15 @@ def refresh_data(self): for c in range(self.cell_count): self.cells[c].voltage = st["cell_info"]["voltages"][c] - self.to_temp(0, st["cell_info"]["temperature_mos"]) - self.to_temp(1, st["cell_info"]["temperature_sensor_1"]) - self.to_temp(2, st["cell_info"]["temperature_sensor_2"]) + temp_mos = st["cell_info"]["temperature_mos"] + self.to_temp(0, temp_mos if temp_mos < 32767 else (65535 - temp_mos) * -1) + + temp1 = st["cell_info"]["temperature_sensor_1"] + self.to_temp(1, temp1 if temp1 < 32767 else (65535 - temp1) * -1) + + temp2 = st["cell_info"]["temperature_sensor_2"] + self.to_temp(1, temp2 if temp2 < 32767 else (65535 - temp2) * -1) + self.current = round(st["cell_info"]["current"], 1) self.voltage = round(st["cell_info"]["total_voltage"], 2) @@ -197,8 +203,8 @@ def refresh_data(self): self.balancing = False if st["cell_info"]["balancing_action"] == 0.000 else True self.balancing_current = ( st["cell_info"]["balancing_current"] - if st["cell_info"]["balancing_current"] < 32768 - else (65536 / 1000 - st["cell_info"]["balancing_current"]) * -1 + if st["cell_info"]["balancing_current"] < 32767 + else (65535 / 1000 - st["cell_info"]["balancing_current"]) * -1 ) self.balancing_action = st["cell_info"]["balancing_action"] diff --git a/etc/dbus-serialbattery/bms/jkbms_brn.py b/etc/dbus-serialbattery/bms/jkbms_brn.py index 7955a728..f78a6ba8 100644 --- a/etc/dbus-serialbattery/bms/jkbms_brn.py +++ b/etc/dbus-serialbattery/bms/jkbms_brn.py @@ -3,6 +3,7 @@ from time import sleep, time import asyncio import threading +import sys # if used as standalone script then use custom logger # else import logger from utils @@ -139,10 +140,12 @@ class Jkbms_Brn: # translate info placeholder, since it depends on the bms_max_cell_count translate_cell_info = [] - def __init__(self, addr, reset_bt_callback = None): + def __init__(self, addr, reset_bt_callback=None): self.address = addr self.bt_thread = None - self.bt_thread_monitor = threading.Thread(target=self.monitor_scraping) + self.bt_thread_monitor = threading.Thread( + target=self.monitor_scraping, name="Thread-JKBMS-Monitor" + ) self.bt_reset = reset_bt_callback self.should_be_scraping = False self.trigger_soc_reset = False @@ -497,8 +500,10 @@ async def asy_connect_and_scrape(self): logger.info("--> asy_connect_and_scrape(): Exit") def monitor_scraping(self): - while(self.should_be_scraping == True): - self.bt_thread = threading.Thread(target=self.connect_and_scrape) + while self.should_be_scraping == True: + self.bt_thread = threading.Thread( + target=self.connect_and_scrape, name="Thread-JKBMS-Connect-and-Scrape" + ) self.bt_thread.start() logger.debug( "scraping thread started -> main thread id: " @@ -507,9 +512,9 @@ def monitor_scraping(self): + str(self.bt_thread.ident) ) self.bt_thread.join() - if (self.should_be_scraping == True): + if self.should_be_scraping == True: logger.debug("scraping thread ended: reseting bluetooth and restarting") - if (not self.bt_reset == None): + if not self.bt_reset == None: self.bt_reset() sleep(2) @@ -519,7 +524,7 @@ def start_scraping(self): logger.debug("scraping thread already running") return self.should_be_scraping = True - self.bt_thread_monitor.start(); + self.bt_thread_monitor.start() def stop_scraping(self): self.run = False @@ -532,7 +537,7 @@ def stop_scraping(self): return True def is_running(self): - if (self.bt_thread is not None): + if self.bt_thread is not None: return self.bt_thread.is_alive() return False @@ -586,8 +591,6 @@ async def reset_soc_jk(self, c): if __name__ == "__main__": - import sys - jk = Jkbms_Brn(sys.argv[1]) if not jk.test_connection(): logger.error(">>> ERROR: Unable to connect") diff --git a/etc/dbus-serialbattery/dbus-serialbattery.py b/etc/dbus-serialbattery/dbus-serialbattery.py index 69c90437..9f47f969 100644 --- a/etc/dbus-serialbattery/dbus-serialbattery.py +++ b/etc/dbus-serialbattery/dbus-serialbattery.py @@ -146,7 +146,8 @@ def get_port() -> str: + " is excluded trough the config file" ) sleep(60) - sys.exit(0) + # exit with error in order that the serialstarter goes on + sys.exit(1) else: # just for MNB-SPI logger.info("No Port needed") diff --git a/etc/dbus-serialbattery/dbushelper.py b/etc/dbus-serialbattery/dbushelper.py index 2a06aa19..4080444d 100644 --- a/etc/dbus-serialbattery/dbushelper.py +++ b/etc/dbus-serialbattery/dbushelper.py @@ -1039,10 +1039,10 @@ def setSetting( settings_iface = dbus.Interface(obj, "com.victronenergy.BusItem") method = settings_iface.get_dbus_method("SetValue") try: - print(f"Setted setting {object_path}/{setting_name} to {value}") + logger.debug(f"Setted setting {object_path}/{setting_name} to {value}") return True if method(value) == 0 else False except dbus.exceptions.DBusException as e: - print(f"Failed to remove setting: {e}") + logger.error(f"Failed to set setting: {e}") def removeSetting( self, bus, service: str, object_path: str, setting_name: list @@ -1054,10 +1054,10 @@ def removeSetting( settings_iface = dbus.Interface(obj, "com.victronenergy.Settings") method = settings_iface.get_dbus_method("RemoveSettings") try: - print(f"Removed setting at {object_path}") + logger.debug(f"Removed setting at {object_path}") return True if method(setting_name) == 0 else False except dbus.exceptions.DBusException as e: - print(f"Failed to remove setting: {e}") + logger.error(f"Failed to remove setting: {e}") def create_nested_dict(self, path, value) -> dict: keys = path.strip("/").split("/") diff --git a/etc/dbus-serialbattery/utils.py b/etc/dbus-serialbattery/utils.py index 4a3266bd..8a8f9647 100644 --- a/etc/dbus-serialbattery/utils.py +++ b/etc/dbus-serialbattery/utils.py @@ -37,7 +37,7 @@ def _get_list_from_config( # Constants -DRIVER_VERSION = "1.1.20240112dev" +DRIVER_VERSION = "1.1.20240128dev" zero_char = chr(48) degree_sign = "\N{DEGREE SIGN}"