File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed
homeassistant/components/workday Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change 1010from homeassistant .const import CONF_NAME
1111from homeassistant .core import HomeAssistant
1212from homeassistant .helpers .entity_platform import AddConfigEntryEntitiesCallback
13+ from homeassistant .util import dt as dt_util
1314
1415from . import WorkdayConfigEntry
1516from .const import CONF_EXCLUDES , CONF_OFFSET , CONF_WORKDAYS
@@ -87,11 +88,12 @@ def update_data(self, now: datetime) -> None:
8788 @property
8889 def event (self ) -> CalendarEvent | None :
8990 """Return the next upcoming event."""
90- return (
91- sorted (self .event_list , key = lambda e : e .start )[0 ]
92- if self .event_list
93- else None
91+ sorted_list : list [CalendarEvent ] | None = (
92+ sorted (self .event_list , key = lambda e : e .start ) if self .event_list else None
9493 )
94+ if not sorted_list :
95+ return None
96+ return [d for d in sorted_list if d .start >= dt_util .utcnow ().date ()][0 ]
9597
9698 async def async_get_events (
9799 self , hass : HomeAssistant , start_date : datetime , end_date : datetime
Original file line number Diff line number Diff line change @@ -70,6 +70,11 @@ async def test_holiday_calendar_entity(
7070 async_fire_time_changed (hass )
7171 await hass .async_block_till_done ()
7272
73+ # Binary sensor added to ensure same state for both entities
74+ state = hass .states .get ("binary_sensor.workday_sensor" )
75+ assert state is not None
76+ assert state .state == "on"
77+
7378 state = hass .states .get ("calendar.workday_sensor_calendar" )
7479 assert state is not None
7580 assert state .state == "on"
@@ -78,6 +83,10 @@ async def test_holiday_calendar_entity(
7883 async_fire_time_changed (hass )
7984 await hass .async_block_till_done ()
8085
86+ state = hass .states .get ("binary_sensor.workday_sensor" )
87+ assert state is not None
88+ assert state .state == "off"
89+
8190 state = hass .states .get ("calendar.workday_sensor_calendar" )
8291 assert state is not None
8392 assert state .state == "off"
You can’t perform that action at this time.
0 commit comments