Skip to content

Commit

Permalink
maint: Code simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerSelwyn committed Aug 23, 2024
1 parent 0f6e5be commit b6cac4e
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def _log_error(self, error, err):
async def _async_update_calendar_event(
self, event_id, ha_event, subject, start, end, **kwargs
):
event = await self._async_get_event_from_calendar(event_id)
event = await self.data.async_get_event(self.hass, event_id)
event = add_call_data_to_event(event, subject, start, end, **kwargs)
await self.hass.async_add_executor_job(event.save)
self._raise_event(ha_event, event_id)
Expand Down Expand Up @@ -434,7 +434,7 @@ async def async_remove_calendar_event(
)

async def _async_delete_calendar_event(self, event_id, ha_event):
event = await self._async_get_event_from_calendar(event_id)
event = await self.data.async_get_event(self.hass, event_id)
await self.hass.async_add_executor_job(
event.delete,
)
Expand All @@ -457,7 +457,7 @@ async def async_respond_calendar_event(
self.async_schedule_update_ha_state(True)

async def _async_send_response(self, event_id, response, send_response, message):
event = await self._async_get_event_from_calendar(event_id)
event = await self.data.async_get_event(self.hass, event_id)
if response == EventResponse.Accept:
await self.hass.async_add_executor_job(
ft.partial(event.accept_event, message, send_response=send_response)
Expand All @@ -478,10 +478,6 @@ async def _async_send_response(self, event_id, response, send_response, message)
ft.partial(event.decline_event, message, send_response=send_response)
)

async def _async_get_event_from_calendar(self, event_id):
calendar = self.data.calendar
return await self.hass.async_add_executor_job(calendar.get_event, event_id)

def _validate_permissions(self, error_message):
if not self._entry.runtime_data.permissions.validate_authorization(
PERM_CALENDARS_READWRITE
Expand Down Expand Up @@ -648,6 +644,10 @@ async def async_get_events(self, hass, start_date, end_date):

return event_list

async def async_get_event(self, hass, event_id):
"""Get a single event by event_id."""
return await hass.async_add_executor_job(self.calendar.get_event, event_id)

async def async_update(self, hass, limit):
"""Do the update."""
start_of_day_utc = dt_util.as_utc(dt_util.start_of_local_day())
Expand Down

0 comments on commit b6cac4e

Please sign in to comment.