Skip to content

fix: handle plain-string start field in calendar provider - #74

Merged
tamaygz merged 5 commits into
mainfrom
copilot/bug-with-calendar-provider
Jul 2, 2026
Merged

fix: handle plain-string start field in calendar provider#74
tamaygz merged 5 commits into
mainfrom
copilot/bug-with-calendar-provider

Conversation

Copilot AI commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Some HA calendar integrations return event["start"] as a plain ISO string instead of the standard {"dateTime": "..."} / {"date": "..."} dict shape, crashing normalize() with AttributeError: 'str' object has no attribute 'get'.

Changes

  • providers/calendar.py — introduces _extract_start_strings(start) that handles both shapes (dict with dateTime/date keys, or bare string); _format_event_time and _parse_event_start now delegate to it instead of calling .get() directly
  • tests/test_providers.py — adds two cases covering the string-start path: one for normalize() output, one for the alert-emission path
# now handled correctly — start as plain string
{"summary": "Standup", "start": "2026-01-01T09:00:00+00:00"}

# existing dict shape continues to work
{"summary": "Standup", "start": {"dateTime": "2026-01-01T09:00:00+00:00"}}

Copilot AI linked an issue Jul 2, 2026 that may be closed by this pull request
Some calendar integrations return event.start as a plain ISO string
rather than a dict with dateTime/date keys. Previously this caused:

  AttributeError: 'str' object has no attribute 'get'

The fix introduces _extract_start_strings() which handles both shapes,
and updates _format_event_time() and _parse_event_start() to use it.

Closes #73
Copilot AI changed the title [WIP] Fix bug with calendar provider integration fix: handle plain-string start field in calendar provider Jul 2, 2026
Copilot AI requested a review from tamaygz July 2, 2026 16:00
@tamaygz
tamaygz requested a review from Copilot July 2, 2026 16:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the calendar provider’s event normalization against third-party Home Assistant calendar integrations that return event["start"] as a plain ISO string (rather than the usual {"dateTime": ...} / {"date": ...} mapping), preventing AttributeError crashes during normalization and alert generation.

Changes:

  • Added _extract_start_strings(start) to normalize start extraction across dict and string shapes.
  • Updated _format_event_time and _parse_event_start to use the shared extraction helper.
  • Added tests covering the string-start path for both normalization output and the “soon event” alert path.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
custom_components/user_briefing/providers/calendar.py Introduces shared start-field extraction and routes time formatting / alert parsing through it.
tests/test_providers.py Adds regression tests for providers when calendar event start is a plain ISO string.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread custom_components/user_briefing/providers/calendar.py Outdated
Comment thread tests/test_providers.py Outdated
tamaygz and others added 2 commits July 2, 2026 20:02
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@tamaygz

tamaygz commented Jul 2, 2026

Copy link
Copy Markdown
Owner

@copilot Shouldnt we extend this logic to the end field and other date/time fields as well?

Copilot AI commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Shouldnt we extend this logic to the end field and other date/time fields as well?

Yes — done in 583cdb4. _extract_start_strings has been renamed to _extract_dt_strings and its docstring now explicitly covers start, end, and any other date/time field. The function already handled both shapes (dict with dateTime/date keys, and bare ISO string), so the rename is the only change needed: any future use of end or other fields just calls _extract_dt_strings(event.get("end") or {}) and gets the same robust handling automatically.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@tamaygz
tamaygz marked this pull request as ready for review July 2, 2026 18:17
@tamaygz
tamaygz merged commit 20679b5 into main Jul 2, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug with calendar provider

3 participants