本文整理汇总了Python中astral.Astral.dawn_utc方法的典型用法代码示例。如果您正苦于以下问题:Python Astral.dawn_utc方法的具体用法?Python Astral.dawn_utc怎么用?Python Astral.dawn_utc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astral.Astral
的用法示例。
在下文中一共展示了Astral.dawn_utc方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_date_events
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import dawn_utc [as 别名]
def test_date_events(self):
"""Test retrieving next sun events."""
utc_now = datetime(2016, 11, 1, 8, 0, 0, tzinfo=dt_util.UTC)
from astral import Astral
astral = Astral()
utc_today = utc_now.date()
latitude = self.hass.config.latitude
longitude = self.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)
assert dawn == sun.get_astral_event_date(
self.hass, 'dawn', utc_today)
assert dusk == sun.get_astral_event_date(
self.hass, 'dusk', utc_today)
assert midnight == sun.get_astral_event_date(
self.hass, 'solar_midnight', utc_today)
assert noon == sun.get_astral_event_date(
self.hass, 'solar_noon', utc_today)
assert sunrise == sun.get_astral_event_date(
self.hass, SUN_EVENT_SUNRISE, utc_today)
assert sunset == sun.get_astral_event_date(
self.hass, SUN_EVENT_SUNSET, utc_today)
示例2: test_date_events
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import dawn_utc [as 别名]
def test_date_events(self):
"""Test retrieving next sun events."""
utc_now = datetime(2016, 11, 1, 8, 0, 0, tzinfo=dt_util.UTC)
from astral import Astral
astral = Astral()
utc_today = utc_now.date()
latitude = self.hass.config.latitude
longitude = self.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)
self.assertEqual(dawn, sun.get_astral_event_date(
self.hass, 'dawn', utc_today))
self.assertEqual(dusk, sun.get_astral_event_date(
self.hass, 'dusk', utc_today))
self.assertEqual(midnight, sun.get_astral_event_date(
self.hass, 'solar_midnight', utc_today))
self.assertEqual(noon, sun.get_astral_event_date(
self.hass, 'solar_noon', utc_today))
self.assertEqual(sunrise, sun.get_astral_event_date(
self.hass, 'sunrise', utc_today))
self.assertEqual(sunset, sun.get_astral_event_date(
self.hass, 'sunset', utc_today))
示例3: test_next_events
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import dawn_utc [as 别名]
def test_next_events(self):
"""Test retrieving next sun events."""
utc_now = datetime(2016, 11, 1, 8, 0, 0, tzinfo=dt_util.UTC)
from astral import Astral
astral = Astral()
utc_today = utc_now.date()
latitude = self.hass.config.latitude
longitude = self.hass.config.longitude
mod = -1
while True:
next_dawn = (astral.dawn_utc(
utc_today + timedelta(days=mod), latitude, longitude))
if next_dawn > utc_now:
break
mod += 1
mod = -1
while True:
next_dusk = (astral.dusk_utc(
utc_today + timedelta(days=mod), latitude, longitude))
if next_dusk > utc_now:
break
mod += 1
mod = -1
while True:
next_midnight = (astral.solar_midnight_utc(
utc_today + timedelta(days=mod), longitude))
if next_midnight > utc_now:
break
mod += 1
mod = -1
while True:
next_noon = (astral.solar_noon_utc(
utc_today + timedelta(days=mod), longitude))
if next_noon > utc_now:
break
mod += 1
mod = -1
while True:
next_rising = (astral.sunrise_utc(
utc_today + timedelta(days=mod), latitude, longitude))
if next_rising > utc_now:
break
mod += 1
mod = -1
while True:
next_setting = (astral.sunset_utc(
utc_today + timedelta(days=mod), latitude, longitude))
if next_setting > utc_now:
break
mod += 1
with patch('homeassistant.helpers.condition.dt_util.utcnow',
return_value=utc_now):
assert next_dawn == sun.get_astral_event_next(
self.hass, 'dawn')
assert next_dusk == sun.get_astral_event_next(
self.hass, 'dusk')
assert next_midnight == sun.get_astral_event_next(
self.hass, 'solar_midnight')
assert next_noon == sun.get_astral_event_next(
self.hass, 'solar_noon')
assert next_rising == sun.get_astral_event_next(
self.hass, SUN_EVENT_SUNRISE)
assert next_setting == sun.get_astral_event_next(
self.hass, SUN_EVENT_SUNSET)
示例4: test_setting_rising
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import dawn_utc [as 别名]
def test_setting_rising(self):
"""Test retrieving sun setting and rising."""
utc_now = datetime(2016, 11, 1, 8, 0, 0, tzinfo=dt_util.UTC)
with patch('homeassistant.helpers.condition.dt_util.utcnow',
return_value=utc_now):
setup_component(self.hass, sun.DOMAIN, {
sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
self.hass.block_till_done()
state = self.hass.states.get(sun.ENTITY_ID)
from astral import Astral
astral = Astral()
utc_today = utc_now.date()
latitude = self.hass.config.latitude
longitude = self.hass.config.longitude
mod = -1
while True:
next_dawn = (astral.dawn_utc(
utc_today + timedelta(days=mod), latitude, longitude))
if next_dawn > utc_now:
break
mod += 1
mod = -1
while True:
next_dusk = (astral.dusk_utc(
utc_today + timedelta(days=mod), latitude, longitude))
if next_dusk > utc_now:
break
mod += 1
mod = -1
while True:
next_midnight = (astral.solar_midnight_utc(
utc_today + timedelta(days=mod), longitude))
if next_midnight > utc_now:
break
mod += 1
mod = -1
while True:
next_noon = (astral.solar_noon_utc(
utc_today + timedelta(days=mod), longitude))
if next_noon > utc_now:
break
mod += 1
mod = -1
while True:
next_rising = (astral.sunrise_utc(
utc_today + timedelta(days=mod), latitude, longitude))
if next_rising > utc_now:
break
mod += 1
mod = -1
while True:
next_setting = (astral.sunset_utc(
utc_today + timedelta(days=mod), latitude, longitude))
if next_setting > utc_now:
break
mod += 1
self.assertEqual(next_dawn, dt_util.parse_datetime(
state.attributes[sun.STATE_ATTR_NEXT_DAWN]))
self.assertEqual(next_dusk, dt_util.parse_datetime(
state.attributes[sun.STATE_ATTR_NEXT_DUSK]))
self.assertEqual(next_midnight, dt_util.parse_datetime(
state.attributes[sun.STATE_ATTR_NEXT_MIDNIGHT]))
self.assertEqual(next_noon, dt_util.parse_datetime(
state.attributes[sun.STATE_ATTR_NEXT_NOON]))
self.assertEqual(next_rising, dt_util.parse_datetime(
state.attributes[sun.STATE_ATTR_NEXT_RISING]))
self.assertEqual(next_setting, dt_util.parse_datetime(
state.attributes[sun.STATE_ATTR_NEXT_SETTING]))
示例5: test_setting_rising
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import dawn_utc [as 别名]
def test_setting_rising(self):
"""Test retrieving sun setting and rising."""
setup_component(self.hass, sun.DOMAIN, {
sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
from astral import Astral
astral = Astral()
utc_now = dt_util.utcnow()
latitude = self.hass.config.latitude
longitude = self.hass.config.longitude
mod = -1
while True:
next_dawn = (astral.dawn_utc(utc_now +
timedelta(days=mod), latitude, longitude))
if next_dawn > utc_now:
break
mod += 1
mod = -1
while True:
next_dusk = (astral.dusk_utc(utc_now +
timedelta(days=mod), latitude, longitude))
if next_dusk > utc_now:
break
mod += 1
mod = -1
while True:
next_midnight = (astral.solar_midnight_utc(utc_now +
timedelta(days=mod), longitude))
if next_midnight > utc_now:
break
mod += 1
mod = -1
while True:
next_noon = (astral.solar_noon_utc(utc_now +
timedelta(days=mod), longitude))
if next_noon > utc_now:
break
mod += 1
mod = -1
while True:
next_rising = (astral.sunrise_utc(utc_now +
timedelta(days=mod), latitude, longitude))
if next_rising > utc_now:
break
mod += 1
mod = -1
while True:
next_setting = (astral.sunset_utc(utc_now +
timedelta(days=mod), latitude, longitude))
if next_setting > utc_now:
break
mod += 1
self.assertEqual(next_dawn, sun.next_dawn_utc(self.hass))
self.assertEqual(next_dusk, sun.next_dusk_utc(self.hass))
self.assertEqual(next_midnight, sun.next_midnight_utc(self.hass))
self.assertEqual(next_noon, sun.next_noon_utc(self.hass))
self.assertEqual(next_rising, sun.next_rising_utc(self.hass))
self.assertEqual(next_setting, sun.next_setting_utc(self.hass))
# Point it at a state without the proper attributes
self.hass.states.set(sun.ENTITY_ID, sun.STATE_ABOVE_HORIZON)
self.assertIsNone(sun.next_dawn(self.hass))
self.assertIsNone(sun.next_dusk(self.hass))
self.assertIsNone(sun.next_midnight(self.hass))
self.assertIsNone(sun.next_noon(self.hass))
self.assertIsNone(sun.next_rising(self.hass))
self.assertIsNone(sun.next_setting(self.hass))
# Point it at a non-existing state
self.assertIsNone(sun.next_dawn(self.hass, 'non.existing'))
self.assertIsNone(sun.next_dusk(self.hass, 'non.existing'))
self.assertIsNone(sun.next_midnight(self.hass, 'non.existing'))
self.assertIsNone(sun.next_noon(self.hass, 'non.existing'))
self.assertIsNone(sun.next_rising(self.hass, 'non.existing'))
self.assertIsNone(sun.next_setting(self.hass, 'non.existing'))