diff --git a/packages/control/ev/charge_template.py b/packages/control/ev/charge_template.py index 361d7d2070..9ed37d4638 100644 --- a/packages/control/ev/charge_template.py +++ b/packages/control/ev/charge_template.py @@ -339,30 +339,28 @@ def _find_recent_plan(self, filtered_plans = [d for d in plans_diff_end_date if list(d.values())[0] is not None] if filtered_plans: sorted_plans = sorted(filtered_plans, key=lambda x: list(x.values())[0]) - if len(sorted_plans) == 1: - plan_dict = sorted_plans[0] - elif (len(sorted_plans) > 1 and - list(sorted_plans[0].values())[0] < self.BUFFER): - plan_dict = sorted_plans[1] + for plan in sorted_plans: + if self.BUFFER < list(sorted_plans[0].values())[0]: + plan_dict = plan + break else: - plan_dict = sorted_plans[0] - if plan_dict: - plan_id = list(plan_dict.keys())[0] - plan_end_time = list(plan_dict.values())[0] - - for p in plans: - if p.id == plan_id: - plan = p - - remaining_time, missing_amount, phases, duration = self._calc_remaining_time( - plan, plan_end_time, soc, ev_template, used_amount, max_hw_phases, phase_switch_supported, - charging_type, control_parameter.phases, soc_request_interval_offset, hw_bidi) - - return SelectedPlan(remaining_time=remaining_time, - duration=duration, - missing_amount=missing_amount, - phases=phases, - plan=plan) + return None + plan_id = list(plan_dict.keys())[0] + plan_end_time = list(plan_dict.values())[0] + + for p in plans: + if p.id == plan_id: + plan = p + + remaining_time, missing_amount, phases, duration = self._calc_remaining_time( + plan, plan_end_time, soc, ev_template, used_amount, max_hw_phases, phase_switch_supported, + charging_type, control_parameter.phases, soc_request_interval_offset, hw_bidi) + + return SelectedPlan(remaining_time=remaining_time, + duration=duration, + missing_amount=missing_amount, + phases=phases, + plan=plan) else: return None