From ff8f22854c96e7f807161ebbf373cd88eaefbc68 Mon Sep 17 00:00:00 2001 From: Philip Lundrigan Date: Mon, 21 Dec 2015 16:28:26 -0700 Subject: [PATCH] Add test --- tests/components/automation/test_sun.py | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/components/automation/test_sun.py b/tests/components/automation/test_sun.py index 3c4b2783c72..87f04a325e8 100644 --- a/tests/components/automation/test_sun.py +++ b/tests/components/automation/test_sun.py @@ -230,6 +230,36 @@ class TestAutomationSun(unittest.TestCase): self.hass.pool.block_till_done() self.assertEqual(0, len(self.calls)) + def test_if_action_after_after(self): + self.hass.states.set(sun.ENTITY_ID, sun.STATE_ABOVE_HORIZON, { + sun.STATE_ATTR_NEXT_SETTING: '14:00:00 16-09-2015', + }) + + now = datetime(2015, 9, 16, 15, tzinfo=dt_util.UTC) + entity_id = 'domain.test_entity' + + with patch('homeassistant.components.automation.sun.dt_util.utcnow', + return_value=now): + automation.setup(self.hass, { + automation.DOMAIN: { + 'trigger': { + 'platform': 'event', + 'event_type': 'test_event', + }, + 'condition': { + 'platform': 'sun', + 'after': 'sunset', + }, + 'action': { + 'service': 'test.automation' + } + } + }) + + self.hass.bus.fire('test_event') + self.hass.pool.block_till_done() + self.assertEqual(1, len(self.calls)) + def test_if_action_before_and_after_during(self): self.hass.states.set(sun.ENTITY_ID, sun.STATE_ABOVE_HORIZON, { sun.STATE_ATTR_NEXT_RISING: '10:00:00 16-09-2015',