@@ -58,7 +58,8 @@ def _start(self) -> None:
58
58
- Unexpected exceptions: Exit with status code 1
59
59
60
60
This method indefinitely repeats a sequence of operations until an unrecoverable error occurs.
61
- On the first iteration, it performs a special initialization operation to determine the next scheduled execution time.
61
+ On the first iteration, it performs a special initialization operation to determine the next scheduled execution
62
+ time.
62
63
On subsequent iterations, it performs a standard operation to determine the next scheduled execution time.
63
64
64
65
Raises:
@@ -82,7 +83,7 @@ def _start(self) -> None:
82
83
time_to_sleep_to += timedelta (days = 1 )
83
84
self .log .info (
84
85
f"The price minimum { next_price_minimum } has to re-checked "
85
- + f"--> Waiting until { time_to_sleep_to } ..."
86
+ f"--> Waiting until { time_to_sleep_to } ..."
86
87
)
87
88
pause .until (time_to_sleep_to )
88
89
self .log .info ("Waking up since the the price minimum has to re-checked" )
@@ -127,10 +128,7 @@ def _do_iteration(self, current_energy_rate: EnergyRate) -> EnergyRate:
127
128
timestamp_now = TimeHandler .get_time ()
128
129
129
130
next_price_minimum = self .tibber_api_handler .get_next_price_minimum ()
130
- self .log .info (
131
- f"The next price minimum is at { next_price_minimum } and it is feasible to charge for a "
132
- + f"maximum of { current_energy_rate .format_maximum_charging_duration ()} "
133
- )
131
+ self .log .info (f"The next price minimum is at { next_price_minimum } " )
134
132
135
133
if next_price_minimum .rate > current_energy_rate .rate :
136
134
# Information is unused at the moment
@@ -140,12 +138,14 @@ def _do_iteration(self, current_energy_rate: EnergyRate) -> EnergyRate:
140
138
timestamp_now , next_price_minimum .timestamp
141
139
)
142
140
self .log .info (
143
- f"The expected energy harvested by the sun till the next price minimum is { expected_power_harvested_till_next_minimum } "
141
+ f"The expected energy harvested by the sun till the next price minimum is "
142
+ f"{ expected_power_harvested_till_next_minimum } "
144
143
)
145
144
146
145
if self .absence_handler .check_for_current_absence ():
147
146
self .log .info (
148
- "Currently there is an absence, using the power consumption configured in the environment as the basis for calculation"
147
+ "Currently there is an absence, using the power consumption configured in the environment as the "
148
+ "basis for calculation"
149
149
)
150
150
expected_energy_usage_till_next_minimum = self .absence_handler .calculate_power_usage_for_absence (
151
151
timestamp_now , next_price_minimum .timestamp
@@ -162,8 +162,8 @@ def _do_iteration(self, current_energy_rate: EnergyRate) -> EnergyRate:
162
162
power_usage_increase_factor = 20
163
163
self .log .info (
164
164
"The price minimum has to be re-checked since it is at the end of a day and the price rates for "
165
- + "tomorrow are unavailable --> The expected power usage "
166
- + f"({ expected_energy_usage_till_next_minimum } ) is increased by { power_usage_increase_factor } %"
165
+ "tomorrow are unavailable --> The expected power usage "
166
+ f"({ expected_energy_usage_till_next_minimum } ) is increased by { power_usage_increase_factor } %"
167
167
)
168
168
expected_energy_usage_till_next_minimum += expected_energy_usage_till_next_minimum * (
169
169
power_usage_increase_factor / 100
@@ -184,7 +184,8 @@ def _do_iteration(self, current_energy_rate: EnergyRate) -> EnergyRate:
184
184
self .inverter .calculate_energy_saved_in_battery_from_state_of_charge (target_min_state_of_charge )
185
185
)
186
186
self .log .info (
187
- f"The battery shall contain { energy_to_be_in_battery_when_reaching_next_minimum } ({ target_min_state_of_charge } %) when reaching the next minimum"
187
+ f"The battery shall contain { energy_to_be_in_battery_when_reaching_next_minimum } "
188
+ f"({ target_min_state_of_charge } %) when reaching the next minimum"
188
189
)
189
190
190
191
summary_of_energy_vales = {
@@ -230,7 +231,8 @@ def _do_iteration(self, current_energy_rate: EnergyRate) -> EnergyRate:
230
231
231
232
duration_to_wait_for_semsportal_update = timedelta (minutes = 10 )
232
233
self .log .info (
233
- f"Sleeping for { duration_to_wait_for_semsportal_update } to let the SEMS Portal update its power consumption data..."
234
+ f"Sleeping for { duration_to_wait_for_semsportal_update } to let the SEMS Portal update its power "
235
+ "consumption data..."
234
236
)
235
237
pause .seconds (duration_to_wait_for_semsportal_update .total_seconds ())
236
238
@@ -269,20 +271,23 @@ def _charge_inverter(self, target_state_of_charge: int, maximum_charging_duratio
269
271
270
272
self .log .info (
271
273
f"Set the inverter to charge, the target state of charge is { target_state_of_charge } %. "
272
- + f"End of charging is { maximum_end_charging_time .strftime ('%H:%M:%S' )} at the latest. "
273
- + f"Checking the charging progress every { charging_progress_check_interval } ..."
274
+ f"End of charging is { maximum_end_charging_time .strftime ('%H:%M:%S' )} at the latest. "
275
+ f"Checking the charging progress every { charging_progress_check_interval } ..."
274
276
)
275
277
276
278
error_counter = 0
277
279
while True :
278
280
if error_counter == 3 :
279
281
self .log .error (
280
- f"An error occurred { error_counter } times while trying to get the current state of charge --> Stopping the charging process"
282
+ f"An error occurred { error_counter } times while trying to get the current state of charge"
283
+ f"--> Stopping the charging process"
281
284
)
282
285
# Can't set the mode of the inverter as it is unresponsive
283
286
break
284
287
285
- pause .seconds (charging_progress_check_interval .total_seconds ())
288
+ # Account for program execution times, this way the check happens at 05:00 and does not add up delays
289
+ # (minor cosmetics)
290
+ pause .seconds (charging_progress_check_interval .total_seconds () - TimeHandler .get_time ().second )
286
291
287
292
try :
288
293
if self .inverter .get_operation_mode () != OperationMode .ECO_CHARGE :
@@ -310,13 +315,14 @@ def _charge_inverter(self, target_state_of_charge: int, maximum_charging_duratio
310
315
if TimeHandler .get_time () > maximum_end_charging_time :
311
316
self .log .info (
312
317
f"The maximum end charging time of { maximum_end_charging_time } has been reached "
313
- + f"--> Stopping the charging process. The battery is at { current_state_of_charge } %"
318
+ f"--> Stopping the charging process. The battery is at { current_state_of_charge } %"
314
319
)
315
320
self .inverter .set_operation_mode (OperationMode .GENERAL )
316
321
break
317
322
318
323
self .log .debug (
319
- f"Charging is still ongoing (current: { current_state_of_charge } %, target: >= { target_state_of_charge } %) --> Waiting for another { charging_progress_check_interval } ..."
324
+ f"Charging is still ongoing (current: { current_state_of_charge } %, target: >= { target_state_of_charge } "
325
+ f"%) --> Waiting for another { charging_progress_check_interval } ..."
320
326
)
321
327
322
328
def _calculate_amount_of_energy_bought (
@@ -343,14 +349,17 @@ def _calculate_amount_of_energy_bought(
343
349
if timestamp_starting_to_charge .date () == timestamp_ending_to_charge .date ():
344
350
energy_bought_today_after_charging = self .sems_portal_api_handler .get_energy_buy ()
345
351
self .log .debug (
346
- f"It is till the same day since starting to charge, the amount of energy bought after charging is { energy_bought_today_after_charging } "
352
+ f"It is till the same day since starting to charge, the amount of energy bought after charging is "
353
+ f"{ energy_bought_today_after_charging } "
347
354
)
348
355
return energy_bought_today_after_charging - energy_bought_before_charging
349
356
350
357
energy_bought_today_after_charging = self .sems_portal_api_handler .get_energy_buy ()
351
358
energy_bought_yesterday = self .sems_portal_api_handler .get_energy_buy (1 ) - energy_bought_before_charging
352
359
self .log .debug (
353
- f"It is the next day since starting to charge, the amount of energy bought after charging (today) is { energy_bought_today_after_charging } , the amount of energy bought after charging (yesterday) is { energy_bought_yesterday } "
360
+ f"It is the next day since starting to charge, the amount of energy bought after charging (today) is "
361
+ f"{ energy_bought_today_after_charging } , the amount of energy bought after charging (yesterday) is "
362
+ f"{ energy_bought_yesterday } "
354
363
)
355
364
return energy_bought_today_after_charging + energy_bought_yesterday
356
365
0 commit comments