Skip to content

Commit

Permalink
Merge pull request #896 from mr-manuel/dev
Browse files Browse the repository at this point in the history
Fix some errors
  • Loading branch information
mr-manuel committed Dec 23, 2023
2 parents f67f363 + 6a5ed30 commit 4f4f1c5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
44 changes: 25 additions & 19 deletions etc/dbus-serialbattery/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,17 @@ def manage_charge_voltage_linear(self) -> None:
controlvoltage = self.control_voltage - (
(
self.get_max_cell_voltage()
- utils.MAX_CELL_VOLTAGE
- (
utils.SOC_RESET_VOLTAGE
if self.soc_reset_requested
else utils.MAX_CELL_VOLTAGE
)
- utils.CELL_VOLTAGE_DIFF_KEEP_MAX_VOLTAGE_UNTIL
)
* utils.CVL_ICONTROLLER_FACTOR
)
else:
controlvoltage = utils.MAX_CELL_VOLTAGE * self.cell_count
controlvoltage = self.max_battery_voltage

controlvoltage = min(
max(controlvoltage, self.min_battery_voltage),
Expand Down Expand Up @@ -1009,39 +1013,41 @@ def get_capacity_remain(self) -> Union[float, None]:
return None

def get_timeToSoc(
self, socnum: float, crntPrctPerSec: float, onlyNumber: bool = False
self, soc_target: float, percent_per_second: float, only_number: bool = False
) -> str:
if self.current > 0:
diffSoc = socnum - self.soc_calc
soc_diff = soc_target - self.soc_calc
else:
diffSoc = self.soc_calc - socnum
soc_diff = self.soc - soc_target

"""
calculate only positive SoC points, since negative points have no sense
when charging only points above current SoC are shown
when discharging only points below current SoC are shown
"""
if diffSoc < 0:
if soc_diff < 0:
return None

ttgStr = None
if self.soc_calc != socnum and (
diffSoc > 0 or utils.TIME_TO_SOC_INC_FROM is True
time_to_go_str = None
if (
self.soc_calc != soc_target
and percent_per_second != 0
and (soc_diff > 0 or utils.TIME_TO_SOC_INC_FROM is True)
):
secondstogo = int(diffSoc / crntPrctPerSec)
ttgStr = ""
seconds_to_go = int(soc_diff / percent_per_second)
time_to_go_str = ""

if onlyNumber or utils.TIME_TO_SOC_VALUE_TYPE & 1:
ttgStr += str(secondstogo)
if not onlyNumber and utils.TIME_TO_SOC_VALUE_TYPE & 2:
ttgStr += " ["
if not onlyNumber and utils.TIME_TO_SOC_VALUE_TYPE & 2:
ttgStr += self.get_secondsToString(secondstogo)
if only_number or utils.TIME_TO_SOC_VALUE_TYPE & 1:
time_to_go_str += str(seconds_to_go)
if not only_number and utils.TIME_TO_SOC_VALUE_TYPE & 2:
time_to_go_str += " ["
if not only_number and utils.TIME_TO_SOC_VALUE_TYPE & 2:
time_to_go_str += self.get_secondsToString(seconds_to_go)

if utils.TIME_TO_SOC_VALUE_TYPE & 1:
ttgStr += "]"
time_to_go_str += "]"

return ttgStr
return time_to_go_str

def get_secondsToString(self, timespan: int, precision: int = 3) -> str:
"""
Expand Down
8 changes: 4 additions & 4 deletions etc/dbus-serialbattery/dbushelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,17 +924,17 @@ def publish_dbus(self):

self._dbusservice["/CurrentAvg"] = self.battery.current_avg

crntPrctPerSec = (
percent_per_seconds = (
abs(self.battery.current_avg / (self.battery.capacity / 100)) / 3600
)

# Update TimeToGo item
if utils.TIME_TO_GO_ENABLE and crntPrctPerSec is not None:
if utils.TIME_TO_GO_ENABLE and percent_per_seconds is not None:
# Update TimeToGo item, has to be a positive int since it's used from dbus-systemcalc-py
time_to_go = self.battery.get_timeToSoc(
# switch value depending on charging/discharging
utils.SOC_LOW_WARNING if self.battery.current_avg < 0 else 100,
crntPrctPerSec,
percent_per_seconds,
True,
)

Expand All @@ -950,7 +950,7 @@ def publish_dbus(self):
if len(utils.TIME_TO_SOC_POINTS) > 0:
for num in utils.TIME_TO_SOC_POINTS:
self._dbusservice["/TimeToSoC/" + str(num)] = (
self.battery.get_timeToSoc(num, crntPrctPerSec)
self.battery.get_timeToSoc(num, percent_per_seconds)
if self.battery.current_avg
else None
)
Expand Down
2 changes: 1 addition & 1 deletion etc/dbus-serialbattery/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _get_list_from_config(


# Constants
DRIVER_VERSION = "1.0.20231217dev"
DRIVER_VERSION = "1.0.20231218dev"
zero_char = chr(48)
degree_sign = "\N{DEGREE SIGN}"

Expand Down

0 comments on commit 4f4f1c5

Please sign in to comment.