'Test if the state changes at next setting/rising.'

def test_state_change(self):

    now = datetime(2016, 6, 1, 8, 0, 0, tzinfo=dt_util.UTC)
    with patch('homeassistant.helpers.condition.dt_util.utcnow', return_value=now):
        setup_component(self.hass, sun.DOMAIN, {sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
    self.hass.block_till_done()
    test_time = dt_util.parse_datetime(self.hass.states.get(sun.ENTITY_ID).attributes[sun.STATE_ATTR_NEXT_RISING])
    self.assertIsNotNone(test_time)
    self.assertEqual(sun.STATE_BELOW_HORIZON, self.hass.states.get(sun.ENTITY_ID).state)
    self.hass.bus.fire(ha.EVENT_TIME_CHANGED, {ha.ATTR_NOW: (test_time + timedelta(seconds=5))})
    self.hass.block_till_done()
    self.assertEqual(sun.STATE_ABOVE_HORIZON, self.hass.states.get(sun.ENTITY_ID).state)
