Upgrade Astral to 2.2 (#48573)
This commit is contained in:
parent
e76503ddc3
commit
09eb74fd9d
12 changed files with 211 additions and 188 deletions
|
@ -11,18 +11,19 @@ import homeassistant.util.dt as dt_util
|
|||
def test_next_events(hass):
|
||||
"""Test retrieving next sun events."""
|
||||
utc_now = datetime(2016, 11, 1, 8, 0, 0, tzinfo=dt_util.UTC)
|
||||
from astral import Astral
|
||||
from astral import LocationInfo
|
||||
import astral.sun
|
||||
|
||||
astral = Astral()
|
||||
utc_today = utc_now.date()
|
||||
|
||||
latitude = hass.config.latitude
|
||||
longitude = hass.config.longitude
|
||||
location = LocationInfo(
|
||||
latitude=hass.config.latitude, longitude=hass.config.longitude
|
||||
)
|
||||
|
||||
mod = -1
|
||||
while True:
|
||||
next_dawn = astral.dawn_utc(
|
||||
utc_today + timedelta(days=mod), latitude, longitude
|
||||
next_dawn = astral.sun.dawn(
|
||||
location.observer, date=utc_today + timedelta(days=mod)
|
||||
)
|
||||
if next_dawn > utc_now:
|
||||
break
|
||||
|
@ -30,8 +31,8 @@ def test_next_events(hass):
|
|||
|
||||
mod = -1
|
||||
while True:
|
||||
next_dusk = astral.dusk_utc(
|
||||
utc_today + timedelta(days=mod), latitude, longitude
|
||||
next_dusk = astral.sun.dusk(
|
||||
location.observer, date=utc_today + timedelta(days=mod)
|
||||
)
|
||||
if next_dusk > utc_now:
|
||||
break
|
||||
|
@ -39,8 +40,8 @@ def test_next_events(hass):
|
|||
|
||||
mod = -1
|
||||
while True:
|
||||
next_midnight = astral.solar_midnight_utc(
|
||||
utc_today + timedelta(days=mod), longitude
|
||||
next_midnight = astral.sun.midnight(
|
||||
location.observer, date=utc_today + timedelta(days=mod)
|
||||
)
|
||||
if next_midnight > utc_now:
|
||||
break
|
||||
|
@ -48,15 +49,17 @@ def test_next_events(hass):
|
|||
|
||||
mod = -1
|
||||
while True:
|
||||
next_noon = astral.solar_noon_utc(utc_today + timedelta(days=mod), longitude)
|
||||
next_noon = astral.sun.noon(
|
||||
location.observer, date=utc_today + timedelta(days=mod)
|
||||
)
|
||||
if next_noon > utc_now:
|
||||
break
|
||||
mod += 1
|
||||
|
||||
mod = -1
|
||||
while True:
|
||||
next_rising = astral.sunrise_utc(
|
||||
utc_today + timedelta(days=mod), latitude, longitude
|
||||
next_rising = astral.sun.sunrise(
|
||||
location.observer, date=utc_today + timedelta(days=mod)
|
||||
)
|
||||
if next_rising > utc_now:
|
||||
break
|
||||
|
@ -64,8 +67,8 @@ def test_next_events(hass):
|
|||
|
||||
mod = -1
|
||||
while True:
|
||||
next_setting = astral.sunset_utc(
|
||||
utc_today + timedelta(days=mod), latitude, longitude
|
||||
next_setting = astral.sun.sunset(
|
||||
location.observer, utc_today + timedelta(days=mod)
|
||||
)
|
||||
if next_setting > utc_now:
|
||||
break
|
||||
|
@ -74,8 +77,8 @@ def test_next_events(hass):
|
|||
with patch("homeassistant.helpers.condition.dt_util.utcnow", return_value=utc_now):
|
||||
assert next_dawn == sun.get_astral_event_next(hass, "dawn")
|
||||
assert next_dusk == sun.get_astral_event_next(hass, "dusk")
|
||||
assert next_midnight == sun.get_astral_event_next(hass, "solar_midnight")
|
||||
assert next_noon == sun.get_astral_event_next(hass, "solar_noon")
|
||||
assert next_midnight == sun.get_astral_event_next(hass, "midnight")
|
||||
assert next_noon == sun.get_astral_event_next(hass, "noon")
|
||||
assert next_rising == sun.get_astral_event_next(hass, SUN_EVENT_SUNRISE)
|
||||
assert next_setting == sun.get_astral_event_next(hass, SUN_EVENT_SUNSET)
|
||||
|
||||
|
@ -83,25 +86,26 @@ def test_next_events(hass):
|
|||
def test_date_events(hass):
|
||||
"""Test retrieving next sun events."""
|
||||
utc_now = datetime(2016, 11, 1, 8, 0, 0, tzinfo=dt_util.UTC)
|
||||
from astral import Astral
|
||||
from astral import LocationInfo
|
||||
import astral.sun
|
||||
|
||||
astral = Astral()
|
||||
utc_today = utc_now.date()
|
||||
|
||||
latitude = hass.config.latitude
|
||||
longitude = hass.config.longitude
|
||||
location = LocationInfo(
|
||||
latitude=hass.config.latitude, longitude=hass.config.longitude
|
||||
)
|
||||
|
||||
dawn = astral.dawn_utc(utc_today, latitude, longitude)
|
||||
dusk = astral.dusk_utc(utc_today, latitude, longitude)
|
||||
midnight = astral.solar_midnight_utc(utc_today, longitude)
|
||||
noon = astral.solar_noon_utc(utc_today, longitude)
|
||||
sunrise = astral.sunrise_utc(utc_today, latitude, longitude)
|
||||
sunset = astral.sunset_utc(utc_today, latitude, longitude)
|
||||
dawn = astral.sun.dawn(location.observer, utc_today)
|
||||
dusk = astral.sun.dusk(location.observer, utc_today)
|
||||
midnight = astral.sun.midnight(location.observer, utc_today)
|
||||
noon = astral.sun.noon(location.observer, utc_today)
|
||||
sunrise = astral.sun.sunrise(location.observer, utc_today)
|
||||
sunset = astral.sun.sunset(location.observer, utc_today)
|
||||
|
||||
assert dawn == sun.get_astral_event_date(hass, "dawn", utc_today)
|
||||
assert dusk == sun.get_astral_event_date(hass, "dusk", utc_today)
|
||||
assert midnight == sun.get_astral_event_date(hass, "solar_midnight", utc_today)
|
||||
assert noon == sun.get_astral_event_date(hass, "solar_noon", utc_today)
|
||||
assert midnight == sun.get_astral_event_date(hass, "midnight", utc_today)
|
||||
assert noon == sun.get_astral_event_date(hass, "noon", utc_today)
|
||||
assert sunrise == sun.get_astral_event_date(hass, SUN_EVENT_SUNRISE, utc_today)
|
||||
assert sunset == sun.get_astral_event_date(hass, SUN_EVENT_SUNSET, utc_today)
|
||||
|
||||
|
@ -109,26 +113,27 @@ def test_date_events(hass):
|
|||
def test_date_events_default_date(hass):
|
||||
"""Test retrieving next sun events."""
|
||||
utc_now = datetime(2016, 11, 1, 8, 0, 0, tzinfo=dt_util.UTC)
|
||||
from astral import Astral
|
||||
from astral import LocationInfo
|
||||
import astral.sun
|
||||
|
||||
astral = Astral()
|
||||
utc_today = utc_now.date()
|
||||
|
||||
latitude = hass.config.latitude
|
||||
longitude = hass.config.longitude
|
||||
location = LocationInfo(
|
||||
latitude=hass.config.latitude, longitude=hass.config.longitude
|
||||
)
|
||||
|
||||
dawn = astral.dawn_utc(utc_today, latitude, longitude)
|
||||
dusk = astral.dusk_utc(utc_today, latitude, longitude)
|
||||
midnight = astral.solar_midnight_utc(utc_today, longitude)
|
||||
noon = astral.solar_noon_utc(utc_today, longitude)
|
||||
sunrise = astral.sunrise_utc(utc_today, latitude, longitude)
|
||||
sunset = astral.sunset_utc(utc_today, latitude, longitude)
|
||||
dawn = astral.sun.dawn(location.observer, date=utc_today)
|
||||
dusk = astral.sun.dusk(location.observer, date=utc_today)
|
||||
midnight = astral.sun.midnight(location.observer, date=utc_today)
|
||||
noon = astral.sun.noon(location.observer, date=utc_today)
|
||||
sunrise = astral.sun.sunrise(location.observer, date=utc_today)
|
||||
sunset = astral.sun.sunset(location.observer, date=utc_today)
|
||||
|
||||
with patch("homeassistant.util.dt.now", return_value=utc_now):
|
||||
assert dawn == sun.get_astral_event_date(hass, "dawn", utc_today)
|
||||
assert dusk == sun.get_astral_event_date(hass, "dusk", utc_today)
|
||||
assert midnight == sun.get_astral_event_date(hass, "solar_midnight", utc_today)
|
||||
assert noon == sun.get_astral_event_date(hass, "solar_noon", utc_today)
|
||||
assert midnight == sun.get_astral_event_date(hass, "midnight", utc_today)
|
||||
assert noon == sun.get_astral_event_date(hass, "noon", utc_today)
|
||||
assert sunrise == sun.get_astral_event_date(hass, SUN_EVENT_SUNRISE, utc_today)
|
||||
assert sunset == sun.get_astral_event_date(hass, SUN_EVENT_SUNSET, utc_today)
|
||||
|
||||
|
@ -136,25 +141,26 @@ def test_date_events_default_date(hass):
|
|||
def test_date_events_accepts_datetime(hass):
|
||||
"""Test retrieving next sun events."""
|
||||
utc_now = datetime(2016, 11, 1, 8, 0, 0, tzinfo=dt_util.UTC)
|
||||
from astral import Astral
|
||||
from astral import LocationInfo
|
||||
import astral.sun
|
||||
|
||||
astral = Astral()
|
||||
utc_today = utc_now.date()
|
||||
|
||||
latitude = hass.config.latitude
|
||||
longitude = hass.config.longitude
|
||||
location = LocationInfo(
|
||||
latitude=hass.config.latitude, longitude=hass.config.longitude
|
||||
)
|
||||
|
||||
dawn = astral.dawn_utc(utc_today, latitude, longitude)
|
||||
dusk = astral.dusk_utc(utc_today, latitude, longitude)
|
||||
midnight = astral.solar_midnight_utc(utc_today, longitude)
|
||||
noon = astral.solar_noon_utc(utc_today, longitude)
|
||||
sunrise = astral.sunrise_utc(utc_today, latitude, longitude)
|
||||
sunset = astral.sunset_utc(utc_today, latitude, longitude)
|
||||
dawn = astral.sun.dawn(location.observer, date=utc_today)
|
||||
dusk = astral.sun.dusk(location.observer, date=utc_today)
|
||||
midnight = astral.sun.midnight(location.observer, date=utc_today)
|
||||
noon = astral.sun.noon(location.observer, date=utc_today)
|
||||
sunrise = astral.sun.sunrise(location.observer, date=utc_today)
|
||||
sunset = astral.sun.sunset(location.observer, date=utc_today)
|
||||
|
||||
assert dawn == sun.get_astral_event_date(hass, "dawn", utc_now)
|
||||
assert dusk == sun.get_astral_event_date(hass, "dusk", utc_now)
|
||||
assert midnight == sun.get_astral_event_date(hass, "solar_midnight", utc_now)
|
||||
assert noon == sun.get_astral_event_date(hass, "solar_noon", utc_now)
|
||||
assert midnight == sun.get_astral_event_date(hass, "midnight", utc_now)
|
||||
assert noon == sun.get_astral_event_date(hass, "noon", utc_now)
|
||||
assert sunrise == sun.get_astral_event_date(hass, SUN_EVENT_SUNRISE, utc_now)
|
||||
assert sunset == sun.get_astral_event_date(hass, SUN_EVENT_SUNSET, utc_now)
|
||||
|
||||
|
@ -184,10 +190,10 @@ def test_norway_in_june(hass):
|
|||
print(sun.get_astral_event_date(hass, SUN_EVENT_SUNSET, datetime(2017, 7, 26)))
|
||||
|
||||
assert sun.get_astral_event_next(hass, SUN_EVENT_SUNRISE, june) == datetime(
|
||||
2016, 7, 25, 23, 23, 39, tzinfo=dt_util.UTC
|
||||
2016, 7, 24, 22, 59, 45, 689645, tzinfo=dt_util.UTC
|
||||
)
|
||||
assert sun.get_astral_event_next(hass, SUN_EVENT_SUNSET, june) == datetime(
|
||||
2016, 7, 26, 22, 19, 1, tzinfo=dt_util.UTC
|
||||
2016, 7, 25, 22, 17, 13, 503932, tzinfo=dt_util.UTC
|
||||
)
|
||||
assert sun.get_astral_event_date(hass, SUN_EVENT_SUNRISE, june) is None
|
||||
assert sun.get_astral_event_date(hass, SUN_EVENT_SUNSET, june) is None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue