From ea69264d000882a0658ef5b0966ed6e5830e2a0d Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 12 Jan 2024 14:26:47 +0100 Subject: [PATCH 1/5] Fixes #919 https://github.com/Louisvdw/dbus-serialbattery/issues/919 --- etc/dbus-serialbattery/battery.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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"} ) From fdf305c052f68f7d818b2f0010fd0053b9aa756a Mon Sep 17 00:00:00 2001 From: Manuel Date: Sun, 21 Jan 2024 09:56:02 +0100 Subject: [PATCH 2/5] Changed: Exit script with error, if port excluded else the serialstarter stops at the dbus-serialbattery --- etc/dbus-serialbattery/dbus-serialbattery.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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") From 3604f1789c35452872c1cdc9373b900744b9d24d Mon Sep 17 00:00:00 2001 From: Manuel Date: Sun, 21 Jan 2024 09:58:53 +0100 Subject: [PATCH 3/5] Fixed some smaller errors --- CHANGELOG.md | 5 +++-- etc/dbus-serialbattery/dbushelper.py | 8 ++++---- etc/dbus-serialbattery/utils.py | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9743edd9..62490e5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,12 +22,13 @@ * `BULK_CELL_VOLTAGE` -> `SOC_RESET_VOLTAGE` * `BULK_AFTER_DAYS` -> `SOC_RESET_AFTER_DAYS` -## v1.0.x +## 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/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..9026c65c 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.20240121dev" zero_char = chr(48) degree_sign = "\N{DEGREE SIGN}" From 555ff134cb50def82415a43613ef241095e8077c Mon Sep 17 00:00:00 2001 From: Manuel Date: Sun, 21 Jan 2024 10:12:56 +0100 Subject: [PATCH 4/5] Updated pre-release workflow --- .github/workflows/release-beta.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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: From 2da6bae211a171a1b76344b3ed3f4347469f2457 Mon Sep 17 00:00:00 2001 From: Manuel Date: Sun, 28 Jan 2024 15:13:35 +0100 Subject: [PATCH 5/5] Fixes #916 https://github.com/Louisvdw/dbus-serialbattery/issues/916 --- CHANGELOG.md | 5 +++++ etc/dbus-serialbattery/bms/jkbms_ble.py | 16 +++++++++++----- etc/dbus-serialbattery/bms/jkbms_brn.py | 7 ++++--- etc/dbus-serialbattery/utils.py | 2 +- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62490e5b..d827a1d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,11 @@ * `BULK_CELL_VOLTAGE` -> `SOC_RESET_VOLTAGE` * `BULK_AFTER_DAYS` -> `SOC_RESET_AFTER_DAYS` +## 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 diff --git a/etc/dbus-serialbattery/bms/jkbms_ble.py b/etc/dbus-serialbattery/bms/jkbms_ble.py index d025b5b6..e5c96c5c 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 df5e0b15..ff992d6f 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 @@ -141,7 +142,9 @@ class Jkbms_Brn: def __init__(self, addr): self.address = addr - self.bt_thread = threading.Thread(target=self.connect_and_scrape) + self.bt_thread = threading.Thread( + target=self.connect_and_scrape, name="Thread-JKBMS-BLE" + ) self.trigger_soc_reset = False async def scanForDevices(self): @@ -568,8 +571,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/utils.py b/etc/dbus-serialbattery/utils.py index 9026c65c..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.20240121dev" +DRIVER_VERSION = "1.1.20240128dev" zero_char = chr(48) degree_sign = "\N{DEGREE SIGN}"