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
cf9ada3b
Unverified
Commit
cf9ada3b
authored
2 years ago
by
Allen Porter
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix all day event coercion logic (#91169)
parent
49079691
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/calendar/__init__.py
+10
-21
10 additions, 21 deletions
homeassistant/components/calendar/__init__.py
homeassistant/components/local_calendar/calendar.py
+1
-1
1 addition, 1 deletion
homeassistant/components/local_calendar/calendar.py
with
11 additions
and
22 deletions
homeassistant/components/calendar/__init__.py
+
10
−
21
View file @
cf9ada3b
...
@@ -140,26 +140,6 @@ def _has_min_duration(
...
@@ -140,26 +140,6 @@ def _has_min_duration(
return
validate
return
validate
def
_has_all_day_event_duration
(
start_key
:
str
,
end_key
:
str
,
)
->
Callable
[[
dict
[
str
,
Any
]],
dict
[
str
,
Any
]]:
"""
Modify all day events to have a duration of one day.
"""
def
validate
(
obj
:
dict
[
str
,
Any
])
->
dict
[
str
,
Any
]:
if
(
(
start
:
=
obj
.
get
(
start_key
))
and
(
end
:
=
obj
.
get
(
end_key
))
and
not
isinstance
(
start
,
datetime
.
datetime
)
and
not
isinstance
(
end
,
datetime
.
datetime
)
and
start
==
end
):
obj
[
end_key
]
=
start
+
datetime
.
timedelta
(
days
=
1
)
return
obj
return
validate
def
_has_same_type
(
*
keys
:
Any
)
->
Callable
[[
dict
[
str
,
Any
]],
dict
[
str
,
Any
]]:
def
_has_same_type
(
*
keys
:
Any
)
->
Callable
[[
dict
[
str
,
Any
]],
dict
[
str
,
Any
]]:
"""
Verify that all values are of the same type.
"""
"""
Verify that all values are of the same type.
"""
...
@@ -267,7 +247,6 @@ CALENDAR_EVENT_SCHEMA = vol.Schema(
...
@@ -267,7 +247,6 @@ CALENDAR_EVENT_SCHEMA = vol.Schema(
_has_consistent_timezone
(
"
start
"
,
"
end
"
),
_has_consistent_timezone
(
"
start
"
,
"
end
"
),
_as_local_timezone
(
"
start
"
,
"
end
"
),
_as_local_timezone
(
"
start
"
,
"
end
"
),
_has_min_duration
(
"
start
"
,
"
end
"
,
MIN_EVENT_DURATION
),
_has_min_duration
(
"
start
"
,
"
end
"
,
MIN_EVENT_DURATION
),
_has_all_day_event_duration
(
"
start
"
,
"
end
"
),
),
),
extra
=
vol
.
ALLOW_EXTRA
,
extra
=
vol
.
ALLOW_EXTRA
,
)
)
...
@@ -375,6 +354,16 @@ class CalendarEvent:
...
@@ -375,6 +354,16 @@ class CalendarEvent:
f
"
Failed to validate CalendarEvent:
{
err
}
"
f
"
Failed to validate CalendarEvent:
{
err
}
"
)
from
err
)
from
err
# It is common to set a start an end date to be the same thing for
# an all day event, but that is not a valid duration. Fix to have a
# duration of one day.
if
(
not
isinstance
(
self
.
start
,
datetime
.
datetime
)
and
not
isinstance
(
self
.
end
,
datetime
.
datetime
)
and
self
.
start
==
self
.
end
):
self
.
end
=
self
.
start
+
datetime
.
timedelta
(
days
=
1
)
def
_event_dict_factory
(
obj
:
Iterable
[
tuple
[
str
,
Any
]])
->
dict
[
str
,
str
]:
def
_event_dict_factory
(
obj
:
Iterable
[
tuple
[
str
,
Any
]])
->
dict
[
str
,
str
]:
"""
Convert CalendarEvent dataclass items to dictionary of attributes.
"""
"""
Convert CalendarEvent dataclass items to dictionary of attributes.
"""
...
...
This diff is collapsed.
Click to expand it.
homeassistant/components/local_calendar/calendar.py
+
1
−
1
View file @
cf9ada3b
...
@@ -196,7 +196,7 @@ def _get_calendar_event(event: Event) -> CalendarEvent:
...
@@ -196,7 +196,7 @@ def _get_calendar_event(event: Event) -> CalendarEvent:
else
:
else
:
start
=
event
.
start
start
=
event
.
start
end
=
event
.
end
end
=
event
.
end
if
(
end
-
start
)
<
=
timedelta
(
days
=
0
):
if
(
end
-
start
)
<
timedelta
(
days
=
0
):
end
=
start
+
timedelta
(
days
=
1
)
end
=
start
+
timedelta
(
days
=
1
)
return
CalendarEvent
(
return
CalendarEvent
(
...
...
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