@@ -33,17 +33,17 @@ def apply_offset(date_time: datetime, offset: str, inverse = False):
3333
3434 return date_time + timedelta (hours = hours , minutes = minutes , seconds = seconds )
3535
36- def is_target_timeframe_complete_in_period (current_date : datetime , applicable_time_periods : list | None , target_timeframes : list | None ):
37- if applicable_time_periods is None or target_timeframes is None or len ( applicable_time_periods ) < 1 or len (target_timeframes ) < 1 :
36+ def is_target_timeframe_complete_in_period (current_date : datetime , start_time : datetime , end_time : datetime , target_timeframes : list | None ):
37+ if target_timeframes is None or len (target_timeframes ) < 1 :
3838 return False
3939
4040 return (
41- applicable_time_periods [ 0 ][ "start" ] <= target_timeframes [0 ]["start" ] and
42- applicable_time_periods [ - 1 ][ "end" ] >= target_timeframes [- 1 ]["end" ] and
41+ start_time <= target_timeframes [0 ]["start" ] and
42+ end_time >= target_timeframes [- 1 ]["end" ] and
4343 target_timeframes [- 1 ]["end" ] <= current_date
4444 )
4545
46- def get_fixed_applicable_time_periods (current_date : datetime , target_start_time : str , target_end_time : str , time_period_values : list , is_rolling_target = True ):
46+ def get_start_and_end_times (current_date : datetime , target_start_time : str , target_end_time : str , start_time_not_in_past = True ):
4747 if (target_start_time is not None ):
4848 target_start = parse_datetime (current_date .strftime (f"%Y-%m-%dT{ target_start_time } :00%z" ))
4949 else :
@@ -65,7 +65,7 @@ def get_fixed_applicable_time_periods(current_date: datetime, target_start_time:
6565 target_end = target_end + timedelta (days = 1 )
6666
6767 # If our start date has passed, reset it to current_date to avoid picking a slot in the past
68- if (is_rolling_target == True and target_start < current_date and current_date < target_end ):
68+ if (start_time_not_in_past == True and target_start < current_date and current_date < target_end ):
6969 _LOGGER .debug (f'Rolling target and { target_start } is in the past. Setting start to { current_date } ' )
7070 target_start = current_date
7171
@@ -74,6 +74,9 @@ def get_fixed_applicable_time_periods(current_date: datetime, target_start_time:
7474 target_start = target_start + timedelta (days = 1 )
7575 target_end = target_end + timedelta (days = 1 )
7676
77+ return (target_start , target_end )
78+
79+ def get_fixed_applicable_time_periods (target_start : datetime , target_end : datetime , time_period_values : list ):
7780 _LOGGER .debug (f'Finding rates between { target_start } and { target_end } ' )
7881
7982 # Retrieve the rates that are applicable for our target rate
@@ -434,4 +437,4 @@ def should_evaluate_target_timeframes(current_date: datetime, target_timeframes:
434437
435438 return ((evaluation_mode == CONFIG_TARGET_TARGET_TIMES_EVALUATION_MODE_ALL_IN_PAST and all_rates_in_past ) or
436439 (evaluation_mode == CONFIG_TARGET_TARGET_TIMES_EVALUATION_MODE_ALL_IN_FUTURE_OR_PAST and (one_rate_in_past == False or all_rates_in_past )) or
437- (evaluation_mode == CONFIG_TARGET_TARGET_TIMES_EVALUATION_MODE_ALWAYS ))
440+ (evaluation_mode == CONFIG_TARGET_TARGET_TIMES_EVALUATION_MODE_ALWAYS ))
0 commit comments