diff --git a/custom_components/yasno_outages/coordinator.py b/custom_components/yasno_outages/coordinator.py index ba1c964..85ac1f7 100644 --- a/custom_components/yasno_outages/coordinator.py +++ b/custom_components/yasno_outages/coordinator.py @@ -92,21 +92,37 @@ async def async_fetch_translations(self) -> None: LOGGER.debug("Translations loaded: %s", self.translations) @property - def next_outage(self) -> CalendarEvent: - """Get the next outage.""" + def next_outage(self) -> datetime.datetime | None: + """Get the next outage time.""" next_events = self.get_next_events() for event in next_events: if self._event_to_state(event) == STATE_OFF: - return event + return event.start return None @property - def next_possible_outage(self) -> CalendarEvent: - """Get the next outage.""" + def next_possible_outage(self) -> datetime.datetime | None: + """Get the next outage time.""" next_events = self.get_next_events() for event in next_events: if self._event_to_state(event) == STATE_MAYBE: - return event + return event.start + return None + + @property + def next_connectivity(self) -> datetime.datetime | None: + """Get next connectivity time.""" + now = dt_utils.now() + current_event = self.get_event_at(now) + # If current event is maybe, return the end time + if self._event_to_state(current_event) == STATE_MAYBE: + return current_event.end + + # Otherwise, return the next maybe event's end + next_events = self.get_next_events() + for event in next_events: + if self._event_to_state(event) == STATE_MAYBE: + return event.end return None @property diff --git a/custom_components/yasno_outages/sensor.py b/custom_components/yasno_outages/sensor.py index 5873256..6211a48 100644 --- a/custom_components/yasno_outages/sensor.py +++ b/custom_components/yasno_outages/sensor.py @@ -47,21 +47,21 @@ def get_next_outage(coordinator: YasnoOutagesCoordinator) -> str: translation_key="next_outage", icon="mdi:calendar-remove", device_class=SensorDeviceClass.TIMESTAMP, - val_func=lambda coordinator: coordinator.next_outage.start, + val_func=lambda coordinator: coordinator.next_outage, ), YasnoOutagesSensorDescription( key="next_possible_outage", translation_key="next_possible_outage", icon="mdi:calendar-question", device_class=SensorDeviceClass.TIMESTAMP, - val_func=lambda coordinator: coordinator.next_possible_outage.start, + val_func=lambda coordinator: coordinator.next_possible_outage, ), YasnoOutagesSensorDescription( key="next_connectivity", translation_key="next_connectivity", icon="mdi:calendar-check", device_class=SensorDeviceClass.TIMESTAMP, - val_func=lambda coordinator: coordinator.next_possible_outage.end, + val_func=lambda coordinator: coordinator.next_connectivity, ), )