Skip to content

Commit

Permalink
Merge pull request #918 from mr-manuel/dev
Browse files Browse the repository at this point in the history
Changes 2024.01.12
  • Loading branch information
mr-manuel authored Jan 12, 2024
2 parents 9779b2e + da0f524 commit 976ef06
Show file tree
Hide file tree
Showing 20 changed files with 366 additions and 167 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@

## v1.0.x

* Changed: Fix issue on first driver startup, when no device setting in dbus exists 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
* Added: Configure logging level in `config.ini` by @mr-manuel
* Added: Create unique identifier, if not provided from BMS by @mr-manuel
Expand Down
2 changes: 0 additions & 2 deletions etc/dbus-serialbattery/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,6 @@ def manage_charge_voltage_linear(self) -> None:
if self.soc_reset_requested:
# logger.info("set soc_reset_requested to False")
self.soc_reset_requested = False
# IDEA: Save "soc_reset_last_reached" in the dbus path com.victronenergy.settings
# to make it restart persistent
self.soc_reset_last_reached = current_time
if self.control_voltage:
# check if battery changed from bulk/absoprtion to float
Expand Down
14 changes: 12 additions & 2 deletions etc/dbus-serialbattery/bms/ant.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from utils import read_serial_data, logger
import utils
from struct import unpack_from
import sys


class ANT(Battery):
Expand All @@ -32,8 +33,17 @@ def test_connection(self):
try:
result = self.read_status_data()
result = result and self.refresh_data()
except Exception as err:
logger.error(f"Unexpected {err=}, {type(err)=}")
except Exception:
(
exception_type,
exception_object,
exception_traceback,
) = sys.exc_info()
file = exception_traceback.tb_frame.f_code.co_filename
line = exception_traceback.tb_lineno
logger.error(
f"Exception occurred: {repr(exception_object)} of type {exception_type} in {file} line #{line}"
)
result = False

return result
Expand Down
14 changes: 12 additions & 2 deletions etc/dbus-serialbattery/bms/battery_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from utils import is_bit_set, read_serial_data, logger
import utils
from struct import unpack_from
import sys


class BatteryTemplate(Battery):
Expand All @@ -29,8 +30,17 @@ def test_connection(self):
result = self.read_status_data()
# get first data to show in startup log, only if result is true
result = result and self.refresh_data()
except Exception as err:
logger.error(f"Unexpected {err=}, {type(err)=}")
except Exception:
(
exception_type,
exception_object,
exception_traceback,
) = sys.exc_info()
file = exception_traceback.tb_frame.f_code.co_filename
line = exception_traceback.tb_lineno
logger.error(
f"Exception occurred: {repr(exception_object)} of type {exception_type} in {file} line #{line}"
)
result = False

return result
Expand Down
14 changes: 12 additions & 2 deletions etc/dbus-serialbattery/bms/daly.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from time import sleep, time
from datetime import datetime
from re import sub
import sys


class Daly(Battery):
Expand Down Expand Up @@ -66,8 +67,17 @@ def test_connection(self):
self.read_soc_data(ser)
self.read_battery_code(ser)

except Exception as err:
logger.error(f"Unexpected {err=}, {type(err)=}")
except Exception:
(
exception_type,
exception_object,
exception_traceback,
) = sys.exc_info()
file = exception_traceback.tb_frame.f_code.co_filename
line = exception_traceback.tb_lineno
logger.error(
f"Exception occurred: {repr(exception_object)} of type {exception_type} in {file} line #{line}"
)
result = False

# give the user a feedback that no BMS was found
Expand Down
14 changes: 12 additions & 2 deletions etc/dbus-serialbattery/bms/ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from utils import logger
import utils
import minimalmodbus
import sys


class Ecs(Battery):
Expand Down Expand Up @@ -58,8 +59,17 @@ def test_connection(self):

except IOError:
result = False
except Exception as err:
logger.error(f"Unexpected {err=}, {type(err)=}")
except Exception:
(
exception_type,
exception_object,
exception_traceback,
) = sys.exc_info()
file = exception_traceback.tb_frame.f_code.co_filename
line = exception_traceback.tb_lineno
logger.error(
f"Exception occurred: {repr(exception_object)} of type {exception_type} in {file} line #{line}"
)
result = False

# give the user a feedback that no BMS was found
Expand Down
14 changes: 12 additions & 2 deletions etc/dbus-serialbattery/bms/hlpdatabms4s.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import utils
import serial
from time import sleep
import sys


class HLPdataBMS4S(Battery):
Expand All @@ -20,8 +21,17 @@ def test_connection(self):
result = False
try:
result = self.read_test_data()
except Exception as err:
logger.error(f"Unexpected {err=}, {type(err)=}")
except Exception:
(
exception_type,
exception_object,
exception_traceback,
) = sys.exc_info()
file = exception_traceback.tb_frame.f_code.co_filename
line = exception_traceback.tb_lineno
logger.error(
f"Exception occurred: {repr(exception_object)} of type {exception_type} in {file} line #{line}"
)
result = False

# give the user a feedback that no BMS was found
Expand Down
14 changes: 12 additions & 2 deletions etc/dbus-serialbattery/bms/jkbms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import utils
from struct import unpack_from
from re import sub
import sys


class Jkbms(Battery):
Expand All @@ -25,8 +26,17 @@ def test_connection(self):
# Return True if success, False for failure
try:
return self.read_status_data()
except Exception as err:
logger.error(f"Unexpected {err=}, {type(err)=}")
except Exception:
(
exception_type,
exception_object,
exception_traceback,
) = sys.exc_info()
file = exception_traceback.tb_frame.f_code.co_filename
line = exception_traceback.tb_lineno
logger.error(
f"Exception occurred: {repr(exception_object)} of type {exception_type} in {file} line #{line}"
)
return False

def get_settings(self):
Expand Down
14 changes: 12 additions & 2 deletions etc/dbus-serialbattery/bms/jkbms_ble.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from time import sleep, time
from bms.jkbms_brn import Jkbms_Brn
import os
import sys

# from bleak import BleakScanner, BleakError
# import asyncio
Expand Down Expand Up @@ -69,8 +70,17 @@ def test_connection(self):
if not result:
logger.error("No BMS found at " + self.address)

except Exception as err:
logger.error(f"Unexpected {err=}, {type(err)=}")
except Exception:
(
exception_type,
exception_object,
exception_traceback,
) = sys.exc_info()
file = exception_traceback.tb_frame.f_code.co_filename
line = exception_traceback.tb_lineno
logger.error(
f"Exception occurred: {repr(exception_object)} of type {exception_type} in {file} line #{line}"
)
result = False

return result
Expand Down
26 changes: 21 additions & 5 deletions etc/dbus-serialbattery/bms/jkbms_brn.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,19 +460,35 @@ async def asy_connect_and_scrape(self):
self.trigger_soc_reset = False
await self.reset_soc_jk(client)
await asyncio.sleep(0.01)
except Exception as err:
self.run = False
except Exception:
(
exception_type,
exception_object,
exception_traceback,
) = sys.exc_info()
file = exception_traceback.tb_frame.f_code.co_filename
line = exception_traceback.tb_lineno
logger.info(
f"--> asy_connect_and_scrape(): error while connecting to bt: {err}"
f"--> asy_connect_and_scrape(): error while connecting to bt: {repr(exception_object)} "
+ f"of type {exception_type} in {file} line #{line}"
)
self.run = False
finally:
self.run = False
if client.is_connected:
try:
await client.disconnect()
except Exception as err:
except Exception:
(
exception_type,
exception_object,
exception_traceback,
) = sys.exc_info()
file = exception_traceback.tb_frame.f_code.co_filename
line = exception_traceback.tb_lineno
logger.info(
f"--> asy_connect_and_scrape(): error while disconnecting: {err}"
f"--> asy_connect_and_scrape(): error while disconnecting: {repr(exception_object)} "
+ f"of type {exception_type} in {file} line #{line}"
)

logger.info("--> asy_connect_and_scrape(): Exit")
Expand Down
14 changes: 12 additions & 2 deletions etc/dbus-serialbattery/bms/lifepower.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import utils
from struct import unpack_from
import re
import sys


class Lifepower(Battery):
Expand All @@ -28,8 +29,17 @@ def test_connection(self):
result = False
try:
result = self.read_status_data()
except Exception as err:
logger.error(f"Unexpected {err=}, {type(err)=}")
except Exception:
(
exception_type,
exception_object,
exception_traceback,
) = sys.exc_info()
file = exception_traceback.tb_frame.f_code.co_filename
line = exception_traceback.tb_lineno
logger.error(
f"Exception occurred: {repr(exception_object)} of type {exception_type} in {file} line #{line}"
)
result = False

return result
Expand Down
16 changes: 13 additions & 3 deletions etc/dbus-serialbattery/bms/lltjbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import utils
from struct import unpack_from, pack
import struct
import sys

# Protocol registers
REG_ENTER_FACTORY = 0x00
Expand Down Expand Up @@ -268,8 +269,17 @@ def test_connection(self):
and self.get_settings()
and self.refresh_data()
)
except Exception as err:
logger.error(f"Unexpected {err=}, {type(err)=}")
except Exception:
(
exception_type,
exception_object,
exception_traceback,
) = sys.exc_info()
file = exception_traceback.tb_frame.f_code.co_filename
line = exception_traceback.tb_lineno
logger.error(
f"Exception occurred: {repr(exception_object)} of type {exception_type} in {file} line #{line}"
)
result = False

return result
Expand Down Expand Up @@ -622,7 +632,7 @@ def validate_packet(data):
">>> ERROR: Invalid response packet. Expected begin packet character 0xDD"
)
if status != 0x0:
logger.warn(">>> WARN: BMS rejected request. Status " + status)
logger.warn(">>> WARN: BMS rejected request. Status " + str(status))
return False
if len(data) != payload_length + 7:
logger.error(
Expand Down
14 changes: 12 additions & 2 deletions etc/dbus-serialbattery/bms/mnb.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from battery import Protection, Battery, Cell
from utils import logger
from bms.mnb_utils_max17853 import data_cycle, init_max
import sys

# from struct import *
# from bms.mnb_test_max17853 import * # use test for testing
Expand Down Expand Up @@ -97,8 +98,17 @@ def test_connection(self):
result = False
try:
result = self.read_status_data()
except Exception as err:
logger.error(f"Unexpected {err=}, {type(err)=}")
except Exception:
(
exception_type,
exception_object,
exception_traceback,
) = sys.exc_info()
file = exception_traceback.tb_frame.f_code.co_filename
line = exception_traceback.tb_lineno
logger.error(
f"Exception occurred: {repr(exception_object)} of type {exception_type} in {file} line #{line}"
)
result = False

return result
Expand Down
14 changes: 12 additions & 2 deletions etc/dbus-serialbattery/bms/renogy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import utils
from struct import unpack
import struct
import sys


class Renogy(Battery):
Expand Down Expand Up @@ -49,8 +50,17 @@ def test_connection(self):
result = self.read_gen_data()
# get first data to show in startup log
result = result and self.refresh_data()
except Exception as err:
logger.error(f"Unexpected {err=}, {type(err)=}")
except Exception:
(
exception_type,
exception_object,
exception_traceback,
) = sys.exc_info()
file = exception_traceback.tb_frame.f_code.co_filename
line = exception_traceback.tb_lineno
logger.error(
f"Exception occurred: {repr(exception_object)} of type {exception_type} in {file} line #{line}"
)
result = False

return result
Expand Down
Loading

0 comments on commit 976ef06

Please sign in to comment.