Пример #1
0
def ensure_sun_set(hass):
    """ Trigger sun to set if above horizon. """
    if sun.is_on(hass):
        hass.bus.fire(
            EVENT_TIME_CHANGED,
            {'now':
             sun.next_setting_utc(hass) + timedelta(seconds=10)})
Пример #2
0
def ensure_sun_risen(hass):
    """ Trigger sun to rise if below horizon. """
    if not sun.is_on(hass):
        hass.bus.fire(
            EVENT_TIME_CHANGED,
            {'now':
             sun.next_rising_utc(hass) + timedelta(seconds=10)})
Пример #3
0
    def test_state_change(self):
        """Test if the state changes at next setting/rising."""
        sun.setup(self.hass, {sun.DOMAIN: {sun.CONF_ELEVATION: 0}})

        if sun.is_on(self.hass):
            test_state = sun.STATE_BELOW_HORIZON
            test_time = sun.next_setting(self.hass)
        else:
            test_state = sun.STATE_ABOVE_HORIZON
            test_time = sun.next_rising(self.hass)

        self.assertIsNotNone(test_time)

        self.hass.bus.fire(ha.EVENT_TIME_CHANGED, {ha.ATTR_NOW: test_time + timedelta(seconds=5)})

        self.hass.pool.block_till_done()

        self.assertEqual(test_state, self.hass.states.get(sun.ENTITY_ID).state)
Пример #4
0
    def test_state_change(self):
        """ Test if the state changes at next setting/rising. """
        self.hass.config.latitude = "32.87336"
        self.hass.config.longitude = "117.22743"
        sun.setup(self.hass, {})

        if sun.is_on(self.hass):
            test_state = sun.STATE_BELOW_HORIZON
            test_time = sun.next_setting(self.hass)
        else:
            test_state = sun.STATE_ABOVE_HORIZON
            test_time = sun.next_rising(self.hass)

        self.assertIsNotNone(test_time)

        self.hass.bus.fire(ha.EVENT_TIME_CHANGED, {ha.ATTR_NOW: test_time + timedelta(seconds=5)})

        self.hass.pool.block_till_done()

        self.assertEqual(test_state, self.hass.states.get(sun.ENTITY_ID).state)
Пример #5
0
    def test_state_change(self):
        """ Test if the state changes at next setting/rising. """
        self.assertTrue(sun.setup(
            self.hass,
            {ha.DOMAIN: {
                CONF_LATITUDE: '32.87336',
                CONF_LONGITUDE: '117.22743'
            }}))

        if sun.is_on(self.hass):
            test_state = sun.STATE_BELOW_HORIZON
            test_time = sun.next_setting(self.hass)
        else:
            test_state = sun.STATE_ABOVE_HORIZON
            test_time = sun.next_rising(self.hass)

        self.assertIsNotNone(test_time)

        self.hass.bus.fire(ha.EVENT_TIME_CHANGED,
                           {ha.ATTR_NOW: test_time + dt.timedelta(seconds=5)})

        self.hass._pool.block_till_done()

        self.assertEqual(test_state, self.hass.states.get(sun.ENTITY_ID).state)
Пример #6
0
 def test_is_on(self):
     """Test is_on method."""
     self.hass.states.set(sun.ENTITY_ID, sun.STATE_ABOVE_HORIZON)
     self.assertTrue(sun.is_on(self.hass))
     self.hass.states.set(sun.ENTITY_ID, sun.STATE_BELOW_HORIZON)
     self.assertFalse(sun.is_on(self.hass))
Пример #7
0
def ensure_sun_set(hass):
    """ Trigger sun to set if above horizon. """
    if not sun.is_on(hass):
        return
    fire_time_changed(hass, sun.next_setting_utc(hass) + timedelta(seconds=10))
Пример #8
0
def ensure_sun_risen(hass):
    """ Trigger sun to rise if below horizon. """
    if sun.is_on(hass):
        return
    fire_time_changed(hass, sun.next_rising_utc(hass) + timedelta(seconds=10))
Пример #9
0
def ensure_sun_risen(hass):
    """Trigger sun to rise if below horizon."""
    if sun.is_on(hass):
        return
    fire_time_changed(hass, sun.next_rising_utc(hass) + timedelta(seconds=10))
Пример #10
0
def ensure_sun_set(hass):
    """Trigger sun to set if above horizon."""
    if not sun.is_on(hass):
        return
    fire_time_changed(hass, sun.next_setting_utc(hass) + timedelta(seconds=10))
Пример #11
0
 def test_is_on(self):
     """Test is_on method."""
     self.hass.states.set(sun.ENTITY_ID, sun.STATE_ABOVE_HORIZON)
     self.assertTrue(sun.is_on(self.hass))
     self.hass.states.set(sun.ENTITY_ID, sun.STATE_BELOW_HORIZON)
     self.assertFalse(sun.is_on(self.hass))