'Test retrieving next sun events.'

def test_next_events(self):

    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):
        self.assertEqual(next_dawn, sun.get_astral_event_next(self.hass, 'dawn'))
        self.assertEqual(next_dusk, sun.get_astral_event_next(self.hass, 'dusk'))
        self.assertEqual(next_midnight, sun.get_astral_event_next(self.hass, 'solar_midnight'))
        self.assertEqual(next_noon, sun.get_astral_event_next(self.hass, 'solar_noon'))
        self.assertEqual(next_rising, sun.get_astral_event_next(self.hass, 'sunrise'))
        self.assertEqual(next_setting, sun.get_astral_event_next(self.hass, 'sunset'))
