core icon indicating copy to clipboard operation
core copied to clipboard

Add GoogleCalendarEvent class with "attendees" attribute

Open sfdye opened this issue 1 year ago • 13 comments
trafficstars

Proposed change

Type of change

  • [ ] Dependency upgrade
  • [ ] Bugfix (non-breaking change which fixes an issue)
  • [ ] New integration (thank you!)
  • [x] New feature (which adds functionality to an existing integration)
  • [ ] Deprecation (breaking change to happen in the future)
  • [x] Breaking change (fix/feature causing existing functionality to break)
  • [ ] Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
    • https://community.home-assistant.io/t/google-calendar-invitation-acceptance-status-as-attribute/429269
  • Link to documentation pull request:
    • [ ] Update https://www.home-assistant.io/integrations/google/

Google Calendar API doc

Checklist

  • [ ] The code change is tested and works locally.
  • [ ] Local tests pass. Your PR cannot be merged unless tests pass
  • [ ] There is no commented out code in this PR.
  • [ ] I have followed the development checklist
  • [ ] I have followed the perfect PR recommendations
  • [ ] The code has been formatted using Ruff (ruff format homeassistant tests)
  • [ ] Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • [ ] The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • [ ] New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • [ ] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • [ ] Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

sfdye avatar Jun 12 '24 07:06 sfdye

Hey there @allenporter, mind taking a look at this pull request as it has been labeled with an integration (google) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of google can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign google Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

home-assistant[bot] avatar Jun 12 '24 07:06 home-assistant[bot]

Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration (calendar) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of calendar can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign calendar Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

home-assistant[bot] avatar Jun 12 '24 07:06 home-assistant[bot]

Still WIP, will add the attendees_omitted related logic and unit tests later

sfdye avatar Jun 12 '24 07:06 sfdye

@allenporter Thanks for your input.

Here we go https://github.com/home-assistant/architecture/discussions/1099

sfdye avatar Jun 12 '24 23:06 sfdye

Hey @allenporter I am getting back on this (after our discussion here) and making good progress.

Highlight of the new approach:

  • Introduce a new class GoogleCalendarEvent (extend from CalendarEvent) and add attendees attribute there only. This is to control the blast radius and not to worry about other integration use cases just yet.
  • Modify the _event_filter method to return events that are (both)
    1. Opaque (show as busy)
    2. Accepted by self

I was able to test the changes locally with a few caveats:

  1. The logic to filter events that are accepted by self needs some love as I wasn't able to figure out where to get the email for self.
  2. From my local testing, the returned attendees data seem to be corrupted where display_name and response_status always returns the default value, regardless of the actual value.

Example (real data with redacted email)

attendees=[Attendee(id=None, email='redacted', display_name=None, optional=False, comment=None, response_status=<ResponseStatus.NEEDS_ACTION: 'needsAction'>), Attendee(id=None, email='redacted', display_name=None, optional=False, comment=None, response_status=<ResponseStatus.NEEDS_ACTION: 'needsAction'>)]

Digging around, I think the issue might be due to the slight nuance of the alias feature in pydantic v1 and v2. (apparently home assistant is using v1 whereas gcal_sync supports both v1 and v2) 3. The attendees[].self boolean field might be useful to solve point 1 but it was removed by the _remove_self validator. Can I suggest we keep this and rename it to say is_self?

sfdye avatar Jun 22 '24 00:06 sfdye

Gentle bump

sfdye avatar Jun 28 '24 00:06 sfdye

Ah sorry you can mark "Ready for review" when its ready, otherwise its still in draft. I'll take a look.

allenporter avatar Jun 28 '24 15:06 allenporter

sorry didn't realize that was a question above.

I think an upstream to fix attendees[].self looks like it may be the way to go. This may need a fix in gcal_sync to store it with some other field name since self has special meaning in python and pydantic is hiding it.

I don't think you need to add GoogleCalendarEvent given that the filtering is happening on the gcal_sync Event type.

allenporter avatar Jun 28 '24 15:06 allenporter

@allenporter

Thanks for your review on the attendees[].self and GoogleCalendarEvent. However the whole flow still doesn't work because attendees[].response_status is essentially broken due to the broken alias I mentioned above. Do you have any recommendation to fix this? I am still pretty new to pydantic so any pointer is welcome.

sfdye avatar Jun 29 '24 02:06 sfdye

I have created an issue in https://github.com/allenporter/gcal_sync/issues/545

sfdye avatar Jun 29 '24 07:06 sfdye

I don't think you need to add GoogleCalendarEvent given that the filtering is happening on the gcal_sync Event type.

But I only want google calendar event to have the attendees attribute (i.e. not other local calendar or todoist)

sfdye avatar Jun 30 '24 01:06 sfdye

I don't think you need to add GoogleCalendarEvent given that the filtering is happening on the gcal_sync Event type.

But I only want google calendar event to have the attendees attribute (i.e. not other local calendar or todoist)

The filter function uses gcal_sync.model.Event not the calendar platform.

allenporter avatar Jun 30 '24 02:06 allenporter

I don't think you need to add GoogleCalendarEvent given that the filtering is happening on the gcal_sync Event type.

But I only want google calendar event to have the attendees attribute (i.e. not other local calendar or todoist)

The filter function uses gcal_sync.model.Event not the calendar platform.

Right, we don't need to store the attribute, just use it for filtering.

sfdye avatar Jun 30 '24 04:06 sfdye

Marking this PR draft, awaiting the results of the architectural discussion.

../Frenck

frenck avatar Jul 07 '24 21:07 frenck

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes. Thank you for your contribution!

github-actions[bot] avatar Sep 05 '24 23:09 github-actions[bot]