fix: handle plain-string start field in calendar provider - #74
Conversation
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
start field in calendar provider
There was a problem hiding this comment.
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 normalizestartextraction across dict and string shapes. - Updated
_format_event_timeand_parse_event_startto 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.
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>
|
@copilot Shouldnt we extend this logic to the end field and other date/time fields as well? |
… all date/time fields
Yes — done in 583cdb4. |
Some HA calendar integrations return
event["start"]as a plain ISO string instead of the standard{"dateTime": "..."}/{"date": "..."}dict shape, crashingnormalize()withAttributeError: 'str' object has no attribute 'get'.Changes
providers/calendar.py— introduces_extract_start_strings(start)that handles both shapes (dict withdateTime/datekeys, or bare string);_format_event_timeand_parse_event_startnow delegate to it instead of calling.get()directlytests/test_providers.py— adds two cases covering the string-start path: one fornormalize()output, one for the alert-emission path