Quiet the chatty sun.sun (#23832)

* Split up method to allow caching event

* Lower frequency of updates.

* Code review patches.

* Minor changes to test

* Skip end of period at fixed multiple of delta.
Improved documentation.
This commit is contained in:
Penny Wood
2019-05-15 15:02:29 +08:00
committed by GitHub
parent 18149dcb8c
commit 9da74dda43
3 changed files with 289 additions and 171 deletions

View File

@@ -43,9 +43,18 @@ def get_astral_event_next(
utc_point_in_time: Optional[datetime.datetime] = None,
offset: Optional[datetime.timedelta] = None) -> datetime.datetime:
"""Calculate the next specified solar event."""
from astral import AstralError
location = get_astral_location(hass)
return get_location_astral_event_next(
location, event, utc_point_in_time, offset)
@callback
def get_location_astral_event_next(
location: 'astral.Location', event: str,
utc_point_in_time: Optional[datetime.datetime] = None,
offset: Optional[datetime.timedelta] = None) -> datetime.datetime:
"""Calculate the next specified solar event."""
from astral import AstralError
if offset is None:
offset = datetime.timedelta()