File tree 1 file changed +9
-0
lines changed
1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change 4
4
from datetime import datetime , timedelta
5
5
6
6
from environment_variable_getter import EnvironmentVariableGetter
7
+ from logger import LoggerMixin
7
8
8
9
9
10
@dataclass
@@ -82,6 +83,7 @@ def format_maximum_charging_duration(self) -> str:
82
83
return f"{ charging_duration_in_hours } hours"
83
84
84
85
86
+ soc_logger = LoggerMixin ("StateOfCharge" )
85
87
battery_capacity = EnergyAmount (int (EnvironmentVariableGetter .get ("INVERTER_BATTERY_CAPACITY" )))
86
88
87
89
@@ -92,6 +94,13 @@ class StateOfCharge:
92
94
def __repr__ (self ):
93
95
return f"{ self .in_percentage } % ({ self .absolute } )"
94
96
97
+ def __post_init__ (self ):
98
+ if not self .absolute .watt_hours > battery_capacity .watt_hours :
99
+ return
100
+
101
+ soc_logger .log .debug (f"Capping the state of charge at the battery capacity (would be { self .absolute } )" )
102
+ self .absolute = EnergyAmount (battery_capacity .watt_hours )
103
+
95
104
def __add__ (self , other : StateOfCharge ) -> StateOfCharge :
96
105
return StateOfCharge (self .absolute + other .absolute )
97
106
You can’t perform that action at this time.
0 commit comments