mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Try to fix caldav (#13236)
* Fix device attribute type for event end * Fix is_over and add tests
This commit is contained in:
parent
170b8671b9
commit
ff416c0e7a
@ -194,7 +194,9 @@ class WebDavCalendarData(object):
|
||||
@staticmethod
|
||||
def is_over(vevent):
|
||||
"""Return if the event is over."""
|
||||
return dt.now() > WebDavCalendarData.get_end_date(vevent)
|
||||
return dt.now() >= WebDavCalendarData.to_datetime(
|
||||
WebDavCalendarData.get_end_date(vevent)
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_hass_date(obj):
|
||||
@ -230,4 +232,4 @@ class WebDavCalendarData(object):
|
||||
else:
|
||||
enddate = obj.dtstart.value + timedelta(days=1)
|
||||
|
||||
return WebDavCalendarData.to_datetime(enddate)
|
||||
return enddate
|
||||
|
@ -105,6 +105,20 @@ LOCATION:Hamburg
|
||||
DESCRIPTION:What a day
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
""",
|
||||
"""BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:-//Global Corp.//CalDAV Client//EN
|
||||
BEGIN:VEVENT
|
||||
UID:7
|
||||
DTSTART;TZID=America/Los_Angeles:20171127T083000
|
||||
DTSTAMP:20180301T020053Z
|
||||
DTEND;TZID=America/Los_Angeles:20171127T093000
|
||||
SUMMARY:Enjoy the sun
|
||||
LOCATION:San Francisco
|
||||
DESCRIPTION:Sunny day
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
"""
|
||||
|
||||
]
|
||||
@ -225,7 +239,7 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
|
||||
},
|
||||
_add_device)
|
||||
|
||||
@patch('homeassistant.util.dt.now', return_value=_local_datetime(17, 30))
|
||||
@patch('homeassistant.util.dt.now', return_value=_local_datetime(17, 45))
|
||||
def test_ongoing_event(self, mock_now):
|
||||
"""Test that the ongoing event is returned."""
|
||||
cal = caldav.WebDavCalendarEventDevice(self.hass,
|
||||
@ -244,6 +258,44 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
|
||||
"description": "Surprisingly rainy"
|
||||
})
|
||||
|
||||
@patch('homeassistant.util.dt.now', return_value=_local_datetime(17, 30))
|
||||
def test_just_ended_event(self, mock_now):
|
||||
"""Test that the next ongoing event is returned."""
|
||||
cal = caldav.WebDavCalendarEventDevice(self.hass,
|
||||
DEVICE_DATA,
|
||||
self.calendar)
|
||||
|
||||
self.assertEqual(cal.name, DEVICE_DATA["name"])
|
||||
self.assertEqual(cal.state, STATE_ON)
|
||||
self.assertEqual(cal.device_state_attributes, {
|
||||
"message": "This is a normal event",
|
||||
"all_day": False,
|
||||
"offset_reached": False,
|
||||
"start_time": "2017-11-27 17:00:00",
|
||||
"end_time": "2017-11-27 18:00:00",
|
||||
"location": "Hamburg",
|
||||
"description": "Surprisingly rainy"
|
||||
})
|
||||
|
||||
@patch('homeassistant.util.dt.now', return_value=_local_datetime(17, 00))
|
||||
def test_ongoing_event_different_tz(self, mock_now):
|
||||
"""Test that the ongoing event with another timezone is returned."""
|
||||
cal = caldav.WebDavCalendarEventDevice(self.hass,
|
||||
DEVICE_DATA,
|
||||
self.calendar)
|
||||
|
||||
self.assertEqual(cal.name, DEVICE_DATA["name"])
|
||||
self.assertEqual(cal.state, STATE_ON)
|
||||
self.assertEqual(cal.device_state_attributes, {
|
||||
"message": "Enjoy the sun",
|
||||
"all_day": False,
|
||||
"offset_reached": False,
|
||||
"start_time": "2017-11-27 16:30:00",
|
||||
"description": "Sunny day",
|
||||
"end_time": "2017-11-27 17:30:00",
|
||||
"location": "San Francisco"
|
||||
})
|
||||
|
||||
@patch('homeassistant.util.dt.now', return_value=_local_datetime(8, 30))
|
||||
def test_ongoing_event_with_offset(self, mock_now):
|
||||
"""Test that the offset is taken into account."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user