Skip to content

Commit

Permalink
Optimized error code reporting to GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-manuel committed Aug 24, 2024
1 parent 275c690 commit c98a16b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
* Changed: Renogy BMS - Use port as unique identifier, since it's not possible to change any values on this BMS by @mr-manuel
* Changed: Reworked, documented and cleaned up a lot of code by @mr-manuel
* Changed: Set default charge/discharge current from utils in main battery class by @mr-manuel
* Changed: Show non blocking errors only, if more than 100 occured in the last 24 hours and do not block inverting/charging by @mr-manuel
* Changed: Show non blocking errors only, if more than 180 occured in the last 3 hours (1 per minute) and do not block inverting/charging by @mr-manuel
* Changed: The setting `HELTEC_MODBUS_ADDR` was replaced by `MODBUS_ADDRESSES` in the `config.default.ini` by @mr-manuel
* Changed: Updated `battery_template.py` and added tons of descriptions by @mr-manuel

Expand Down
28 changes: 14 additions & 14 deletions etc/dbus-serialbattery/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2072,34 +2072,34 @@ def get_current(self) -> Union[float, None]:
Get the current from the battery.
If an external current sensor is connected, use that value.
"""
logger.debug(
f"current: {self.current} - current_external: {self.current_external}"
)
if self.current_external is not None:
logger.debug(
f"current: {self.current} - current_external: {self.current_external}"
)
return self.current_external
return self.current

def manage_error_code(self, error_code: int = 8) -> None:
"""
This method is used to process errors.
It sets the error code after 100 errors within 24 hours.
It sets the error code after 180 errors within 3 hours.
:param error_code: The error code to display
"""
self.error_timestamps.append(int(time()))

# only keep last 100 errors
if len(self.error_timestamps) > 100:
# only keep last 180 errors
if len(self.error_timestamps) > 180:
# remove first element
self.error_timestamps.pop(0)

# check if
# there are more or equal to 100 errors
# the first error in the list is within the last 24 hours
# there are more or equal to 180 errors
# the first error in the list is within the last 3 hours
# the error code is different from the current error
if (
len(self.error_timestamps) >= 100
and int(time()) - self.error_timestamps[0] <= 86400
len(self.error_timestamps) >= 180
and int(time()) - self.error_timestamps[0] <= (60 * 60 * 3)
and self.error_code != error_code
):
# set error code
Expand All @@ -2110,12 +2110,12 @@ def manage_error_code_reset(self) -> None:
This method is used to reset the error code.
"""
# check if
# there are more or equal to 100 errors
# the first error in the list is not within the last 24 hours
# there are more or equal to 180 errors
# the first error in the list is not within the last 3 hours
# the error code is not already None
if (
len(self.error_timestamps) >= 100
and int(time()) - self.error_timestamps[0] > 86400
len(self.error_timestamps) >= 180
and int(time()) - self.error_timestamps[0] > (60 * 60 * 3)
and self.error_code is not None
):
self.error_code = None
Expand Down

0 comments on commit c98a16b

Please sign in to comment.