Skip to content

Commit

Permalink
fix: update schedule value algorithm
Browse files Browse the repository at this point in the history
  - improve get_next_schedule function
  • Loading branch information
kevin-briand committed Jul 3, 2024
1 parent 2659143 commit f7cd51b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion custom_components/heatger/zone/dto/schedule_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def is_valid_schedule(self) -> bool:

def to_value(self) -> int:
"""return a schedule in value, the bigger it is, the closer it is to the weekend"""
return self.day * 100 + self.hour.hour * 10 + self.hour.minute
return self.day * 10000 + self.hour.hour * 100 + self.hour.minute

def to_object(self) -> {}:
"""return schedule into object"""
Expand Down
6 changes: 4 additions & 2 deletions custom_components/heatger/zone/zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ async def get_next_schedule(self) -> Optional[ScheduleDto]:

next_schedule: Optional[ScheduleDto] = None
for schedule in list_schedules:
schedule_date = Zone.get_next_day(schedule.day, schedule.hour)
if next_schedule is None or schedule_date < Zone.get_next_day(next_schedule.day, next_schedule.hour):
if next_schedule:
break
next_day = Zone.get_next_day(next_schedule.day, next_schedule.hour)
if next_schedule is None or ScheduleDto(next_day.day, next_day.time(), State.ECO).to_value() < next_schedule.to_value():
next_schedule = schedule
return next_schedule

Expand Down

0 comments on commit f7cd51b

Please sign in to comment.