-
Notifications
You must be signed in to change notification settings - Fork 1
/
battery_cell_list.py
51 lines (34 loc) · 2.05 KB
/
battery_cell_list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import time
from battery_cell import BatteryCell
class BatteryCellList(list[BatteryCell]):
def in_relax_time(self) -> bool:
return any(cell.is_relaxing() for cell in self.__iter__())
def set_relax_time(self, seconds: float):
for cell in self.__iter__():
cell.relax_time = seconds
def currently_balancing(self) -> bool:
return any(cell.is_balance_discharging() for cell in self.__iter__())
def highest_voltage(self) -> float:
return max(cell.voltage.value for cell in self.__iter__())
def highest_accurate_voltage(self) -> float:
return max(cell.accurate_voltage.value for cell in self.__iter__())
def lowest_voltage(self) -> float:
return min(cell.voltage.value for cell in self.__iter__())
def lowest_accurate_voltage(self) -> float:
return min(cell.accurate_voltage.value for cell in self.__iter__())
def with_voltage_above(self, value: float) -> list[BatteryCell]:
return [cell for cell in self.__iter__() if cell.voltage.value > value]
def with_accurate_voltage_above(self, value: float) -> list[BatteryCell]:
return [cell for cell in self.__iter__() if cell.accurate_voltage.value > value]
def highest_soc(self) -> float:
return max(cell.soc() for cell in self.__iter__())
def lowest_soc(self) -> float:
return min(cell.soc() for cell in self.__iter__())
def max_diff(self) -> float:
return self.highest_voltage() - self.lowest_voltage()
def has_voltage_older_than(self, seconds: float) -> bool:
return any(not cell.voltage.initialized() or cell.voltage.age_seconds() > seconds for cell in self.__iter__())
def with_voltage_older_than(self, seconds: float) -> list[BatteryCell]:
return [cell for cell in self.__iter__() if not cell.voltage.initialized() or cell.voltage.age_seconds() > seconds]
def has_accurate_readings_older_than(self, seconds: float) -> bool:
return any(not cell.voltage.initialized() or cell.accurate_voltage.age_seconds() > seconds for cell in self.__iter__())