Nautisch wird anders gesetzt, nach dämmerung nur noch schließen

This commit is contained in:
2026-05-09 09:37:08 +02:00
parent d272844b17
commit 495e1cfb8a
2 changed files with 12 additions and 2 deletions
@@ -230,7 +230,7 @@ class SternwarteDataUpdateCoordinator(DataUpdateCoordinator[SternwarteState]):
self.schedule.open_at = self._format_schedule_datetime(next_schedule["open_at"])
self.schedule.close_at = self._format_schedule_datetime(next_schedule["close_at"])
self.schedule.open_done = False
self.schedule.open_done = next_schedule["open_at"] is None
self.schedule.close_done = False
self.schedule.open_power_on_at = ""
self.schedule.close_power_on_at = ""
@@ -805,7 +805,7 @@ class SternwarteDataUpdateCoordinator(DataUpdateCoordinator[SternwarteState]):
)
return dt_util.as_local(event_utc).replace(second=0, microsecond=0)
def _get_next_nautical_schedule(self, now: datetime) -> dict[str, datetime] | None:
def _get_next_nautical_schedule(self, now: datetime) -> dict[str, datetime | None] | None:
for day_offset in range(3):
base_date = now + timedelta(days=day_offset)
twilight = self._calc_twilight(base_date)
@@ -828,6 +828,16 @@ class SternwarteDataUpdateCoordinator(DataUpdateCoordinator[SternwarteState]):
if close_date is not None:
return {"open_at": dusk, "close_at": close_date}
if day_offset == 0 and dusk and dusk <= now:
for close_offset in range(day_offset, day_offset + 3):
close_base = now + timedelta(days=close_offset)
close_twilight = self._calc_twilight(close_base)
if close_twilight["naut"] is None:
continue
candidate = self._event_to_local_datetime(close_base, close_twilight["naut"]["dawn"])
if candidate and candidate > now:
return {"open_at": None, "close_at": candidate}
if day_offset == 0 and dawn and dawn > now:
return None
return None