File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -73,12 +73,21 @@ def update_wh(self, used_wH: float) -> None:
7373 LOG .debug ("Updating Wh: %s" , used_wH )
7474 self .used_kWh = round (used_wH / 1000 , 2 )
7575 self .last_update = datetime .now (timezone .utc ).astimezone ()
76+ self ._recalculate_percentage ()
7677
7778 def update_allowed_wh (self , allowed_wH : float ) -> None :
7879 """This function is used to update the allowed_kWh attribute during a Hilo Challenge Event"""
7980 LOG .debug ("Updating allowed Wh: %s" , allowed_wH )
8081 self .allowed_kWh = round (allowed_wH / 1000 , 2 )
8182 self .last_update = datetime .now (timezone .utc ).astimezone ()
83+ self ._recalculate_percentage ()
84+
85+ def _recalculate_percentage (self ) -> None :
86+ """Recalculate used percentage based on current values"""
87+ if self .allowed_kWh > 0 :
88+ self .used_percentage = round (self .used_kWh / self .allowed_kWh * 100 , 2 )
89+ else :
90+ self .used_percentage = 0
8291
8392 def should_check_for_allowed_wh (self ) -> bool :
8493 """This function is used to authorize subscribing to a specific event in Hilo to receive the allowed_kWh
You can’t perform that action at this time.
0 commit comments