当前位置: 首页>>代码示例>>Python>>正文


Python Astral.sunset_utc方法代码示例

本文整理汇总了Python中astral.Astral.sunset_utc方法的典型用法代码示例。如果您正苦于以下问题:Python Astral.sunset_utc方法的具体用法?Python Astral.sunset_utc怎么用?Python Astral.sunset_utc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在astral.Astral的用法示例。


在下文中一共展示了Astral.sunset_utc方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_date_events

# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunset_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)
开发者ID:ManHammer,项目名称:home-assistant,代码行数:32,代码来源:test_sun.py

示例2: test_date_events

# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunset_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))
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:32,代码来源:test_sun.py

示例3: seconds_till_daytime_ends

# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunset_utc [as 别名]
def seconds_till_daytime_ends(lat,lon,delta_minutes):
   if not is_it_daytime(lat,lon,delta_minutes):
       return 0
   now = datetime.now(UTC())
   astral = Astral()
   sunset = astral.sunset_utc(now,lat,lon) - timedelta(minutes=delta_minutes)
   answer = int((sunset-now).total_seconds())+1
   return answer
开发者ID:IrishMarineInstitute,项目名称:uwobs,代码行数:10,代码来源:daytimes.py

示例4: test_track_sunset

# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunset_utc [as 别名]
    def test_track_sunset(self):
        """Test track the sunset."""
        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_setting = (astral.sunset_utc(
                utc_today + timedelta(days=mod), latitude, longitude))
            if next_setting > utc_now:
                break
            mod += 1

        # Track sunset
        runs = []
        with patch('homeassistant.util.dt.utcnow', return_value=utc_now):
            unsub = track_sunset(self.hass, lambda: runs.append(1))

        offset_runs = []
        offset = timedelta(minutes=30)
        with patch('homeassistant.util.dt.utcnow', return_value=utc_now):
            unsub2 = track_sunset(
                self.hass, lambda: offset_runs.append(1), offset)

        # Run tests
        self._send_time_changed(next_setting - offset)
        self.hass.block_till_done()
        self.assertEqual(0, len(runs))
        self.assertEqual(0, len(offset_runs))

        self._send_time_changed(next_setting)
        self.hass.block_till_done()
        self.assertEqual(1, len(runs))
        self.assertEqual(0, len(offset_runs))

        self._send_time_changed(next_setting + offset)
        self.hass.block_till_done()
        self.assertEqual(1, len(runs))
        self.assertEqual(1, len(offset_runs))

        unsub()
        unsub2()

        self._send_time_changed(next_setting + offset)
        self.hass.block_till_done()
        self.assertEqual(1, len(runs))
        self.assertEqual(1, len(offset_runs))
开发者ID:tmcarr,项目名称:home-assistant,代码行数:60,代码来源:test_event.py

示例5: test_track_sunset

# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunset_utc [as 别名]
    def test_track_sunset(self):
        """Test track the sunset."""
        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_setting = (astral.sunset_utc(utc_now +
                            timedelta(days=mod), latitude, longitude))
            if next_setting > utc_now:
                break
            mod += 1

        # Track sunset
        runs = []
        unsub = track_sunset(self.hass, lambda: runs.append(1))

        offset_runs = []
        offset = timedelta(minutes=30)
        unsub2 = track_sunset(self.hass, lambda: offset_runs.append(1), offset)

        # Run tests
        self._send_time_changed(next_setting - offset)
        self.hass.block_till_done()
        self.assertEqual(0, len(runs))
        self.assertEqual(0, len(offset_runs))

        self._send_time_changed(next_setting)
        self.hass.block_till_done()
        self.assertEqual(1, len(runs))
        self.assertEqual(0, len(offset_runs))

        self._send_time_changed(next_setting + offset)
        self.hass.block_till_done()
        self.assertEqual(2, len(runs))
        self.assertEqual(1, len(offset_runs))

        unsub()
        unsub2()

        self._send_time_changed(next_setting + offset)
        self.hass.block_till_done()
        self.assertEqual(2, len(runs))
        self.assertEqual(1, len(offset_runs))
开发者ID:DavidLP,项目名称:home-assistant,代码行数:56,代码来源:test_event.py

示例6: test_track_sunset

# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunset_utc [as 别名]
    def test_track_sunset(self):
        """ Test track sunset 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_setting = (astral.sunset_utc(utc_now +
                            timedelta(days=mod), latitude, longitude))
            if next_setting > utc_now:
                break
            mod += 1

        # use decorator
        runs = []
        decor = track_sunset()
        decor(lambda x: runs.append(1))

        offset_runs = []
        offset = timedelta(minutes=30)
        decor = track_sunset(offset)
        decor(lambda x: offset_runs.append(1))

        # run tests
        self._send_time_changed(next_setting - offset)
        self.hass.pool.block_till_done()
        self.assertEqual(0, len(runs))
        self.assertEqual(0, len(offset_runs))

        self._send_time_changed(next_setting)
        self.hass.pool.block_till_done()
        self.assertEqual(1, len(runs))
        self.assertEqual(0, len(offset_runs))

        self._send_time_changed(next_setting + offset)
        self.hass.pool.block_till_done()
        self.assertEqual(2, len(runs))
        self.assertEqual(1, len(offset_runs))
开发者ID:100dayproject,项目名称:home-assistant,代码行数:49,代码来源:test_event_decorators.py

示例7: test_setting_rising

# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunset_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'))
开发者ID:DavidLP,项目名称:home-assistant,代码行数:42,代码来源:test_sun.py

示例8: test_setting_rising

# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunset_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"))
开发者ID:naggie,项目名称:home-assistant,代码行数:40,代码来源:test_sun.py

示例9: test_next_events

# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunset_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)
开发者ID:ManHammer,项目名称:home-assistant,代码行数:75,代码来源:test_sun.py

示例10: is_it_daytime

# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunset_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)
开发者ID:IrishMarineInstitute,项目名称:uwobs,代码行数:7,代码来源:daytimes.py

示例11: test_setting_rising

# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunset_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]))
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:81,代码来源:test_sun.py

示例12: str

# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import sunset_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))
开发者ID:justinpoiroux,项目名称:Python-Scripts,代码行数:32,代码来源:SunlightCal.py


注:本文中的astral.Astral.sunset_utc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。