Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
* Changed: Fix System Switch in IO page
* Changed: Fix #239 by @TimGFoley
* Changed: Fix #311
* Changed: Run code analyse only on code change
* Changed: Separate Time-To-Go and Time-To-SoC activation
* Changed: fix UnicodeDecodeError #485 (comment)
  • Loading branch information
mr-manuel authored Apr 25, 2023
2 parents bda2534 + 017df8a commit d8a5d64
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 32 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/analyse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
branches:
- '**'

# Run on changes in the etc folder
paths:
- etc/**

jobs:
analyse:
name: Analyze Using GitHub CodeQL
Expand Down
6 changes: 4 additions & 2 deletions etc/dbus-serialbattery/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,10 @@ def get_midvoltage(self) -> Tuple[Union[float, None], Union[float, None]]:
# get the midpoint of the battery
midpoint = half1voltage + extra
return (
midpoint,
(half2voltage - half1voltage) / (half2voltage + half1voltage) * 100,
abs(midpoint),
abs(
(half2voltage - half1voltage) / (half2voltage + half1voltage) * 100
),
)
except ValueError:
return None, None
Expand Down
9 changes: 7 additions & 2 deletions etc/dbus-serialbattery/config.default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ BLUETOOTH_ENABLED = False
LINEAR_LIMITATION_ENABLE = False

; Battery Current limits
MAX_BATTERY_CHARGE_CURRENT = 70.0
MAX_BATTERY_DISCHARGE_CURRENT = 90.0
MAX_BATTERY_CHARGE_CURRENT = 50.0
MAX_BATTERY_DISCHARGE_CURRENT = 60.0


; --------- Charge Voltage limitation (affecting CVL) ---------
Expand Down Expand Up @@ -124,6 +124,11 @@ DC_CURRENT_LIMIT2_FRACTION = 0.3
DC_CURRENT_LIMIT3_FRACTION = 0.5


; --------- Time-To-Go ---------
; Description: Calculates the time to go shown in the GUI
; Recalculation is done based on TIME_TO_SOC_RECALCULATE_EVERY
TIME_TO_GO_ENABLE = True

; --------- Time-To-Soc ---------
; Description: Calculates the time to a specific SoC
; Example: TIME_TO_SOC_POINTS = 50, 25, 15, 0
Expand Down
49 changes: 27 additions & 22 deletions etc/dbus-serialbattery/dbushelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,17 @@ def setup_vedbus(self):
)

# Create TimeToSoC items only if enabled
if self.battery.capacity is not None and len(TIME_TO_SOC_POINTS) > 0:
if self.battery.capacity is not None:
# Create TimeToGo item
self._dbusservice.add_path("/TimeToGo", None, writeable=True)
if TIME_TO_GO_ENABLE:
self._dbusservice.add_path("/TimeToGo", None, writeable=True)

# Create TimeToSoc items
for num in TIME_TO_SOC_POINTS:
self._dbusservice.add_path(
"/TimeToSoC/" + str(num), None, writeable=True
)
if len(TIME_TO_SOC_POINTS) > 0:
for num in TIME_TO_SOC_POINTS:
self._dbusservice.add_path(
"/TimeToSoC/" + str(num), None, writeable=True
)

logger.info(f"publish config values = {PUBLISH_CONFIG_VALUES}")
if PUBLISH_CONFIG_VALUES == 1:
Expand Down Expand Up @@ -481,7 +483,7 @@ def publish_dbus(self):
try:
if (
self.battery.capacity is not None
and len(TIME_TO_SOC_POINTS) > 0
and (TIME_TO_GO_ENABLE or len(TIME_TO_SOC_POINTS) > 0)
and (
(
# update only once in same second
Expand All @@ -500,27 +502,30 @@ def publish_dbus(self):
abs(self.battery.current / (self.battery.capacity / 100)) / 3600
)

# Update TimeToGo item, has to be a positive int since it's used from dbus-systemcalc-py
self._dbusservice["/TimeToGo"] = (
abs(
int(
self.battery.get_timeToSoc(
SOC_LOW_WARNING, crntPrctPerSec, True
# Update TimeToGo item
if TIME_TO_GO_ENABLE:
# Update TimeToGo item, has to be a positive int since it's used from dbus-systemcalc-py
self._dbusservice["/TimeToGo"] = (
abs(
int(
self.battery.get_timeToSoc(
SOC_LOW_WARNING, crntPrctPerSec, True
)
)
)
)
if self.battery.current
else None
)

# Update TimeToSoc items
for num in TIME_TO_SOC_POINTS:
self._dbusservice["/TimeToSoC/" + str(num)] = (
self.battery.get_timeToSoc(num, crntPrctPerSec)
if self.battery.current
else None
)

# Update TimeToSoc items
if len(TIME_TO_SOC_POINTS) > 0:
for num in TIME_TO_SOC_POINTS:
self._dbusservice["/TimeToSoC/" + str(num)] = (
self.battery.get_timeToSoc(num, crntPrctPerSec)
if self.battery.current
else None
)

except:
pass

Expand Down
4 changes: 3 additions & 1 deletion etc/dbus-serialbattery/jkbms_brn.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
[["device_info", "sw_rev"], 30, "8s"],
[["device_info", "uptime"], 38, "<L"],
[["device_info", "vendor_id"], 6, "16s"],
[["device_info", "manufacturing_date"], 78, "8s"],
# disabled since some BMS throw a UnicodeDecodeError
# https://github.com/Louisvdw/dbus-serialbattery/discussions/485#discussioncomment-5694781
# [["device_info", "manufacturing_date"], 78, "8s"],
]

TRANSLATE_SETTINGS = [
Expand Down
1 change: 1 addition & 0 deletions etc/dbus-serialbattery/qml/PageLynxIonIo.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ MbPage {
description: qsTr("System Switch")
bind: Utils.path(bindPrefix, "/SystemSwitch")
readonly: true
show: item.valid
possibleValues:[
MbOption{description: qsTr("Disabled"); value: 0},
MbOption{description: qsTr("Enabled"); value: 1}
Expand Down
26 changes: 22 additions & 4 deletions etc/dbus-serialbattery/renogy.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,30 @@ def read_cell_data(self):
return True

def read_temp_data(self):
temp1 = self.read_serial_data_renogy(self.command_bms_temp1)
temp2 = self.read_serial_data_renogy(self.command_bms_temp2)
# Check to see how many Enviromental Temp Sensors this battery has, it may have none.
num_env_temps = self.read_serial_data_renogy(self.command_env_temp_count)
logger.info("Number of Enviromental Sensors = %s", num_env_temps)

if num_env_temps == 0:
return False

if num_env_temps == 1:
temp1 = self.read_serial_data_renogy(self.command_env_temp1)

if temp1 is False:
return False
self.temp1 = unpack(">H", temp1)[0] / 10
self.temp2 = unpack(">H", temp2)[0] / 10
else:
self.temp1 = unpack(">H", temp1)[0] / 10
logger.info("temp1 = %s °C", temp1)

if num_env_temps == 2:
temp2 = self.read_serial_data_renogy(self.command_env_temp2)

if temp2 is False:
return False
else:
self.temp2 = unpack(">H", temp2)[0] / 10
logger.info("temp2 = %s °C", temp2)

return True

Expand Down
6 changes: 5 additions & 1 deletion etc/dbus-serialbattery/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _get_list_from_config(

# Constants - Need to dynamically get them in future
DRIVER_VERSION = "1.0"
DRIVER_SUBVERSION = ".0-jkbms_ble (20230420)"
DRIVER_SUBVERSION = ".0-jkbms_ble (20230423)"
zero_char = chr(48)
degree_sign = "\N{DEGREE SIGN}"

Expand Down Expand Up @@ -209,6 +209,10 @@ def _get_list_from_config(
)


# --------- Time-To-Go ---------
# Description: Calculates the time to go shown in the GUI
TIME_TO_GO_ENABLE = "True" == config["DEFAULT"]["TIME_TO_GO_ENABLE"]

# --------- Time-To-Soc ---------
# Description: Calculates the time to a specific SoC
# Example: TIME_TO_SOC_POINTS = 50, 25, 15, 0
Expand Down

0 comments on commit d8a5d64

Please sign in to comment.