@@ -460,9 +460,9 @@ def get_schedules(breaks_config, tariff_pricing_config, plunge_pricing_breaks_co
460460 return schedules
461461
462462
463- def to_charge_period_json (start_day_of_week , end_day_of_week , period ):
464- start_local = period [0 ].astimezone ()
465- end_local = period [1 ].astimezone ()
463+ def to_charge_period_json (start_day_of_week , end_day_of_week , period , tz ):
464+ start_local = period [0 ].astimezone (tz )
465+ end_local = period [1 ].astimezone (tz )
466466 return {
467467 "fromDayOfWeek" : start_day_of_week ,
468468 "fromHour" : start_local .hour ,
@@ -473,20 +473,20 @@ def to_charge_period_json(start_day_of_week, end_day_of_week, period):
473473 }
474474
475475
476- def populate_tou_periods (tou_periods , schedules , start_day_of_week , end_day_of_week ):
476+ def populate_tou_periods (tou_periods , schedules , start_day_of_week , end_day_of_week , tz ):
477477 for schedule in schedules :
478478 charge_periods = tou_periods [schedule .charge_name ]
479479 for period in schedule .get_periods ():
480- charge_periods .append (to_charge_period_json (start_day_of_week , end_day_of_week , period ))
480+ charge_periods .append (to_charge_period_json (start_day_of_week , end_day_of_week , period , tz ))
481481
482482
483- def schedules_to_tariff (week_schedules , schedule_type , weekday , export = False ):
483+ def schedules_to_tariff (week_schedules , schedule_type , weekday , tz = None , export = False ):
484484 tou_periods = defaultdict (list )
485485
486486 if schedule_type == "week" :
487487 # week
488488 today_schedules = week_schedules .get_schedules (weekday , export )
489- populate_tou_periods (tou_periods , today_schedules , 0 , 6 )
489+ populate_tou_periods (tou_periods , today_schedules , 0 , 6 , tz )
490490 elif schedule_type == "weekend" :
491491 # midweek/weekend when possible
492492 if is_midweek (weekday ):
@@ -505,12 +505,12 @@ def schedules_to_tariff(week_schedules, schedule_type, weekday, export=False):
505505 break
506506
507507 if midweek_schedules and weekend_schedules :
508- populate_tou_periods (tou_periods , midweek_schedules , 0 , 4 )
509- populate_tou_periods (tou_periods , weekend_schedules , 5 , 6 )
508+ populate_tou_periods (tou_periods , midweek_schedules , 0 , 4 , tz )
509+ populate_tou_periods (tou_periods , weekend_schedules , 5 , 6 , tz )
510510 elif midweek_schedules :
511- populate_tou_periods (tou_periods , midweek_schedules , 0 , 6 )
511+ populate_tou_periods (tou_periods , midweek_schedules , 0 , 6 , tz )
512512 elif weekend_schedules :
513- populate_tou_periods (tou_periods , weekend_schedules , 0 , 6 )
513+ populate_tou_periods (tou_periods , weekend_schedules , 0 , 6 , tz )
514514 else :
515515 raise ValueError ("At least one schedule is required" )
516516 elif schedule_type == "multiday" :
@@ -520,11 +520,11 @@ def schedules_to_tariff(week_schedules, schedule_type, weekday, export=False):
520520 schedules = week_schedules .get_schedules (i , export )
521521 if schedules :
522522 if last_schedules :
523- populate_tou_periods (tou_periods , last_schedules , start , i - 1 )
523+ populate_tou_periods (tou_periods , last_schedules , start , i - 1 , tz )
524524 start = i
525525 last_schedules = schedules
526526 if last_schedules :
527- populate_tou_periods (tou_periods , last_schedules , start , 6 )
527+ populate_tou_periods (tou_periods , last_schedules , start , 6 , tz )
528528 else :
529529 raise ValueError (f"Invalid schedule type: { schedule_type } " )
530530
@@ -542,15 +542,15 @@ def get_price_info(schedules):
542542 return price_info
543543
544544
545- def to_tariff_data (provider_name , import_plan , import_standing_charge , import_schedule_type , export_plan , export_standing_charge , export_schedule_type , week_schedules , day_date ):
545+ def to_tariff_data (provider_name , import_plan , import_standing_charge , import_schedule_type , export_plan , export_standing_charge , export_schedule_type , week_schedules , day_date , tz = None ):
546546 weekday = day_date .weekday ()
547547 current_import_schedules = week_schedules .get_schedules (weekday )
548548 current_export_schedules = week_schedules .get_schedules (weekday , export = True )
549- import_seasons = schedules_to_tariff (week_schedules , import_schedule_type , weekday )
549+ import_seasons = schedules_to_tariff (week_schedules , import_schedule_type , weekday , tz = tz )
550550 buy_price_info = get_price_info (current_import_schedules );
551551
552552 if current_export_schedules :
553- export_seasons = schedules_to_tariff (week_schedules , export_schedule_type , weekday , export = True )
553+ export_seasons = schedules_to_tariff (week_schedules , export_schedule_type , weekday , tz = tz , export = True )
554554 sell_price_info = get_price_info (current_export_schedules );
555555 else :
556556 export_seasons = import_seasons
0 commit comments