本文整理汇总了Python中astral.Astral.sunrise_utc方法的典型用法代码示例。如果您正苦于以下问题:Python Astral.sunrise_utc方法的具体用法?Python Astral.sunrise_utc怎么用?Python Astral.sunrise_utc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astral.Astral
的用法示例。
在下文中一共展示了Astral.sunrise_utc方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: seconds_till_daytime
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunrise_utc [as 别名]
def seconds_till_daytime(lat,lon,delta_minutes):
if is_it_daytime(lat,lon,delta_minutes):
return 0
now = datetime.now(UTC())
astral = Astral()
sunrise = astral.sunrise_utc(now,lat,lon) + timedelta(minutes=delta_minutes)
if sunrise < now:
sunrise = astral.sunrise_utc(now + timedelta(hours=23),lat,lon) + timedelta(minutes=delta_minutes)
return int((sunrise-now).total_seconds())+1
示例2: test_date_events
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunrise_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)
示例3: test_date_events
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunrise_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))
示例4: test_track_sunrise
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunrise_utc [as 别名]
def test_track_sunrise(self):
"""Test track the sunrise."""
latitude = 32.87336
longitude = 117.22743
# Setup sun component
self.hass.config.latitude = latitude
self.hass.config.longitude = longitude
setup_component(self.hass, sun.DOMAIN, {
sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
# Get next sunrise/sunset
astral = Astral()
utc_now = datetime(2014, 5, 24, 12, 0, 0, tzinfo=dt_util.UTC)
utc_today = utc_now.date()
mod = -1
while True:
next_rising = (astral.sunrise_utc(
utc_today + timedelta(days=mod), latitude, longitude))
if next_rising > utc_now:
break
mod += 1
# Track sunrise
runs = []
with patch('homeassistant.util.dt.utcnow', return_value=utc_now):
unsub = track_sunrise(self.hass, lambda: runs.append(1))
offset_runs = []
offset = timedelta(minutes=30)
with patch('homeassistant.util.dt.utcnow', return_value=utc_now):
unsub2 = track_sunrise(self.hass, lambda: offset_runs.append(1),
offset)
# run tests
self._send_time_changed(next_rising - offset)
self.hass.block_till_done()
self.assertEqual(0, len(runs))
self.assertEqual(0, len(offset_runs))
self._send_time_changed(next_rising)
self.hass.block_till_done()
self.assertEqual(1, len(runs))
self.assertEqual(0, len(offset_runs))
self._send_time_changed(next_rising + offset)
self.hass.block_till_done()
self.assertEqual(1, len(runs))
self.assertEqual(1, len(offset_runs))
unsub()
unsub2()
self._send_time_changed(next_rising + offset)
self.hass.block_till_done()
self.assertEqual(1, len(runs))
self.assertEqual(1, len(offset_runs))
示例5: test_track_sunrise
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunrise_utc [as 别名]
def test_track_sunrise(self):
"""Test track the sunrise."""
latitude = 32.87336
longitude = 117.22743
# Setup sun component
self.hass.config.latitude = latitude
self.hass.config.longitude = longitude
setup_component(self.hass, sun.DOMAIN, {
sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
# Get next sunrise/sunset
astral = Astral()
utc_now = dt_util.utcnow()
mod = -1
while True:
next_rising = (astral.sunrise_utc(utc_now +
timedelta(days=mod), latitude, longitude))
if next_rising > utc_now:
break
mod += 1
# Track sunrise
runs = []
unsub = track_sunrise(self.hass, lambda: runs.append(1))
offset_runs = []
offset = timedelta(minutes=30)
unsub2 = track_sunrise(self.hass, lambda: offset_runs.append(1),
offset)
# run tests
self._send_time_changed(next_rising - offset)
self.hass.block_till_done()
self.assertEqual(0, len(runs))
self.assertEqual(0, len(offset_runs))
self._send_time_changed(next_rising)
self.hass.block_till_done()
self.assertEqual(1, len(runs))
self.assertEqual(0, len(offset_runs))
self._send_time_changed(next_rising + offset)
self.hass.block_till_done()
self.assertEqual(2, len(runs))
self.assertEqual(1, len(offset_runs))
unsub()
unsub2()
self._send_time_changed(next_rising + offset)
self.hass.block_till_done()
self.assertEqual(2, len(runs))
self.assertEqual(1, len(offset_runs))
示例6: test_track_sunrise
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunrise_utc [as 别名]
def test_track_sunrise(self):
""" Test track sunrise decorator """
latitude = 32.87336
longitude = 117.22743
# setup sun component
self.hass.config.latitude = latitude
self.hass.config.longitude = longitude
sun.setup(self.hass, {sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
# get next sunrise/sunset
astral = Astral()
utc_now = dt_util.utcnow()
mod = -1
while True:
next_rising = (astral.sunrise_utc(utc_now +
timedelta(days=mod), latitude, longitude))
if next_rising > utc_now:
break
mod += 1
# use decorator
runs = []
decor = track_sunrise()
decor(lambda x: runs.append(1))
offset_runs = []
offset = timedelta(minutes=30)
decor = track_sunrise(offset)
decor(lambda x: offset_runs.append(1))
# run tests
self._send_time_changed(next_rising - offset)
self.hass.pool.block_till_done()
self.assertEqual(0, len(runs))
self.assertEqual(0, len(offset_runs))
self._send_time_changed(next_rising)
self.hass.pool.block_till_done()
self.assertEqual(1, len(runs))
self.assertEqual(0, len(offset_runs))
self._send_time_changed(next_rising + offset)
self.hass.pool.block_till_done()
self.assertEqual(2, len(runs))
self.assertEqual(1, len(offset_runs))
示例7: test_setting_rising
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunrise_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_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_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_rising(self.hass))
self.assertIsNone(sun.next_setting(self.hass))
# Point it at a non-existing state
self.assertIsNone(sun.next_rising(self.hass, 'non.existing'))
self.assertIsNone(sun.next_setting(self.hass, 'non.existing'))
示例8: test_setting_rising
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunrise_utc [as 别名]
def test_setting_rising(self):
""" Test retrieving sun setting and rising. """
latitude = 32.87336
longitude = 117.22743
# Compare it with the real data
self.hass.config.latitude = latitude
self.hass.config.longitude = longitude
sun.setup(self.hass, {sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
astral = Astral()
utc_now = dt_util.utcnow()
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_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_rising(self.hass))
self.assertIsNone(sun.next_setting(self.hass))
# Point it at a non-existing state
self.assertIsNone(sun.next_rising(self.hass, "non.existing"))
self.assertIsNone(sun.next_setting(self.hass, "non.existing"))
示例9: test_next_events
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunrise_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)
示例10: is_it_daytime
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunrise_utc [as 别名]
def is_it_daytime(lat,lon,delta_minutes):
astral = Astral()
sunrise = astral.sunrise_utc(datetime.today(),lat,lon)
sunset = astral.sunset_utc(datetime.today(),lat,lon)
return sunrise + timedelta(minutes=delta_minutes) < datetime.now(UTC()) < sunset - timedelta(minutes=delta_minutes)
示例11: test_setting_rising
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunrise_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]))
示例12: str
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunrise_utc [as 别名]
+ city_name
+ " is "
+ str(city.latitude)
+ " and the longitude is "
+ str(city.longitude)
)
print("\n")
latitude = float(raw_input("Lataitude: "))
longitude = float(raw_input("Longitude: "))
date = datetime.date(int(year), int(month), int(day))
x = a.sunrise_utc(date, latitude, longitude)
y = a.sunset_utc(date, latitude, longitude)
x = str(x)[11:19]
y = str(y)[11:19]
start_dt = datetime.datetime.strptime(x, "%H:%M:%S")
end_dt = datetime.datetime.strptime(y, "%H:%M:%S")
diff = end_dt - start_dt
colon = str(diff).find(":")
hour = str(diff)[:colon]
minute = str(diff)[colon + 1 : colon + 3]
time = int(hour) * 60 + int(minute)
print("The amount of day in that area is " + str(time))