Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
abb1328a
Unverified
Commit
abb1328a
authored
1 year ago
by
Allen Porter
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix for Google Calendar API returning invalid RRULE:DATE rules (#103870)
parent
80042aa1
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
homeassistant/components/google/calendar.py
+7
-2
7 additions, 2 deletions
homeassistant/components/google/calendar.py
tests/components/google/test_calendar.py
+48
-0
48 additions, 0 deletions
tests/components/google/test_calendar.py
with
55 additions
and
2 deletions
homeassistant/components/google/calendar.py
+
7
−
2
View file @
abb1328a
...
...
@@ -521,8 +521,13 @@ class GoogleCalendarEntity(
def
_get_calendar_event
(
event
:
Event
)
->
CalendarEvent
:
"""
Return a CalendarEvent from an API event.
"""
rrule
:
str
|
None
=
None
if
len
(
event
.
recurrence
)
==
1
:
rrule
=
event
.
recurrence
[
0
].
lstrip
(
RRULE_PREFIX
)
# Home Assistant expects a single RRULE: and all other rule types are unsupported or ignored
if
(
len
(
event
.
recurrence
)
==
1
and
(
raw_rule
:
=
event
.
recurrence
[
0
])
and
raw_rule
.
startswith
(
RRULE_PREFIX
)
):
rrule
=
raw_rule
.
removeprefix
(
RRULE_PREFIX
)
return
CalendarEvent
(
uid
=
event
.
ical_uuid
,
recurrence_id
=
event
.
id
if
event
.
recurring_event_id
else
None
,
...
...
This diff is collapsed.
Click to expand it.
tests/components/google/test_calendar.py
+
48
−
0
View file @
abb1328a
...
...
@@ -1299,3 +1299,51 @@ async def test_event_differs_timezone(
"
description
"
:
event
[
"
description
"
],
"
supported_features
"
:
3
,
}
async
def
test_invalid_rrule_fix
(
hass
:
HomeAssistant
,
hass_client
:
ClientSessionGenerator
,
mock_events_list_items
,
component_setup
,
)
->
None
:
"""
Test that an invalid RRULE returned from Google Calendar API is handled correctly end to end.
"""
week_from_today
=
dt_util
.
now
().
date
()
+
datetime
.
timedelta
(
days
=
7
)
end_event
=
week_from_today
+
datetime
.
timedelta
(
days
=
1
)
event
=
{
**
TEST_EVENT
,
"
start
"
:
{
"
date
"
:
week_from_today
.
isoformat
()},
"
end
"
:
{
"
date
"
:
end_event
.
isoformat
()},
"
recurrence
"
:
[
"
RRULE:DATE;TZID=Europe/Warsaw:20230818T020000,20230915T020000,20231013T020000,20231110T010000,20231208T010000
"
,
],
}
mock_events_list_items
([
event
])
assert
await
component_setup
()
state
=
hass
.
states
.
get
(
TEST_ENTITY
)
assert
state
.
name
==
TEST_ENTITY_NAME
assert
state
.
state
==
STATE_OFF
# Pick a date range that contains two instances of the event
web_client
=
await
hass_client
()
response
=
await
web_client
.
get
(
get_events_url
(
TEST_ENTITY
,
"
2023-08-10T00:00:00Z
"
,
"
2023-09-20T00:00:00Z
"
)
)
assert
response
.
status
==
HTTPStatus
.
OK
events
=
await
response
.
json
()
# Both instances are returned, however the RDATE rule is ignored by Home
# Assistant so they are just treateded as flattened events.
assert
len
(
events
)
==
2
event
=
events
[
0
]
assert
event
[
"
uid
"
]
==
"
cydrevtfuybguinhomj@google.com
"
assert
event
[
"
recurrence_id
"
]
==
"
_c8rinwq863h45qnucyoi43ny8_20230818
"
assert
event
[
"
rrule
"
]
is
None
event
=
events
[
1
]
assert
event
[
"
uid
"
]
==
"
cydrevtfuybguinhomj@google.com
"
assert
event
[
"
recurrence_id
"
]
==
"
_c8rinwq863h45qnucyoi43ny8_20230915
"
assert
event
[
"
rrule
"
]
is
None
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment