Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #449 from Thomas55555/Improve-calendar
Browse files Browse the repository at this point in the history
Improve calendar
  • Loading branch information
Thomas55555 authored May 12, 2023
2 parents 05fe637 + 27784af commit 73ff50b
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions custom_components/husqvarna_automower/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,28 @@ def get_next_event(self) -> tuple[list[CalendarEvent], CalendarEvent]:
end_mowing = start_of_day + dt_util.dt.timedelta(
minutes=calendar["start"] + calendar["duration"]
)

day_list = ""
for days in range(7):
today = (start_of_day + dt_util.dt.timedelta(days=days)).weekday()
today_as_string = WEEKDAYS[today]
if calendar[today_as_string] is True:
today_rfc = WEEKDAYS_TO_RFC5545[today_as_string]
if day_list == "":
day_list = today_rfc
else:
day_list += "," + str(today_rfc)

for days in range(7):
today = (start_of_day + dt_util.dt.timedelta(days=days)).weekday()
today_as_string = WEEKDAYS[today]
if calendar[today_as_string] is True:
self._event = CalendarEvent(
summary=f"{self.mower_name} Mowing schedule {task + 1}",
start=start_mowing + dt_util.dt.timedelta(days=days),
end=end_mowing + dt_util.dt.timedelta(days=days),
description="Description can't be changed",
location=self.loc,
rrule=f"FREQ=WEEKLY;BYDAY={today_rfc}",
rrule=f"FREQ=WEEKLY;BYDAY={day_list}",
uid=task,
)
if self._event.start < self._next_event.start:
Expand All @@ -134,7 +143,6 @@ async def async_create_event(self, **kwargs) -> None:
current_event_list = self.mower_attributes["calendar"]["tasks"]
task_list = await self.aysnc_parse_to_husqvarna_string(kwargs)
await self.aysnc_send_command_to_mower(current_event_list + task_list)
await self.async_get_events()

async def async_update_event(
self,
Expand All @@ -148,7 +156,7 @@ async def async_update_event(
task_list = await self.aysnc_parse_to_husqvarna_string(event)
current_event_list[int(uid)] = task_list[0]
await self.aysnc_send_command_to_mower(current_event_list)
await self.async_get_events()
await self.async_update_ha_state(force_refresh=True)

async def async_delete_event(
self,
Expand All @@ -163,7 +171,6 @@ async def async_delete_event(
raise vol.Invalid("You need at least one schedule")
current_event_list.pop(int(uid))
await self.aysnc_send_command_to_mower(current_event_list)
await self.async_get_events()

async def aysnc_parse_to_husqvarna_string(
self,
Expand Down

0 comments on commit 73ff50b

Please sign in to comment.