diff --git a/CHANGELOG.md b/CHANGELOG.md index 68d1f9ce..db26b426 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ ## v1.0.x * 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 * Added: Current average of the last 5 minutes by @mr-manuel * Added: Daly BMS - Auto reset SoC when changing to float (can be turned off in the config file) by @transistorgit diff --git a/etc/dbus-serialbattery/config.default.ini b/etc/dbus-serialbattery/config.default.ini index d8ae2c4c..7317902e 100644 --- a/etc/dbus-serialbattery/config.default.ini +++ b/etc/dbus-serialbattery/config.default.ini @@ -1,5 +1,12 @@ [DEFAULT] +; --------- Set logging level --------- +; ERROR: Only errors are logged +; WARNING: Errors and warnings are logged +; INFO: Errors, warnings and info messages are logged +; DEBUG: Errors, warnings, info and debug messages are logged +LOGGING = INFO + ; --------- Battery Current limits --------- MAX_BATTERY_CHARGE_CURRENT = 50.0 MAX_BATTERY_DISCHARGE_CURRENT = 60.0 diff --git a/etc/dbus-serialbattery/dbus-serialbattery.py b/etc/dbus-serialbattery/dbus-serialbattery.py index 9119e850..e4bde35e 100644 --- a/etc/dbus-serialbattery/dbus-serialbattery.py +++ b/etc/dbus-serialbattery/dbus-serialbattery.py @@ -195,6 +195,9 @@ def get_port() -> str: battery = get_battery(port) else: + # wait some seconds to be sure that the serial connection is ready + # else the error throw a lot of timeouts + sleep(16) battery = get_battery(port) # exit if no battery could be found diff --git a/etc/dbus-serialbattery/utils.py b/etc/dbus-serialbattery/utils.py index c38cbd9f..0d85998b 100644 --- a/etc/dbus-serialbattery/utils.py +++ b/etc/dbus-serialbattery/utils.py @@ -13,7 +13,6 @@ # Logging logging.basicConfig() logger = logging.getLogger("SerialBattery") -logger.setLevel(logging.INFO) PATH_CONFIG_DEFAULT = "config.default.ini" PATH_CONFIG_USER = "config.ini" @@ -38,10 +37,20 @@ def _get_list_from_config( # Constants -DRIVER_VERSION = "1.0.20230927dev" +DRIVER_VERSION = "1.0.20231009dev" zero_char = chr(48) degree_sign = "\N{DEGREE SIGN}" +# get logging level from config file +if config["DEFAULT"]["LOGGING"] == "ERROR": + logging.basicConfig(level=logging.ERROR) +elif config["DEFAULT"]["LOGGING"] == "WARNING": + logging.basicConfig(level=logging.WARNING) +elif config["DEFAULT"]["LOGGING"] == "DEBUG": + logging.basicConfig(level=logging.DEBUG) +else: + logging.basicConfig(level=logging.INFO) + # save config values to constants # --------- Battery Current limits ---------