mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Freeze time for sun automation test
This commit is contained in:
parent
9bec0316ea
commit
95eabe7c0e
@ -6,6 +6,7 @@ Tests sun automation.
|
|||||||
"""
|
"""
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import unittest
|
import unittest
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
from homeassistant.components import sun
|
from homeassistant.components import sun
|
||||||
@ -38,19 +39,22 @@ class TestAutomationSun(unittest.TestCase):
|
|||||||
sun.STATE_ATTR_NEXT_SETTING: '02:00:00 16-09-2015',
|
sun.STATE_ATTR_NEXT_SETTING: '02:00:00 16-09-2015',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
now = datetime(2015, 9, 15, 23, tzinfo=dt_util.UTC)
|
||||||
trigger_time = datetime(2015, 9, 16, 2, tzinfo=dt_util.UTC)
|
trigger_time = datetime(2015, 9, 16, 2, tzinfo=dt_util.UTC)
|
||||||
|
|
||||||
self.assertTrue(automation.setup(self.hass, {
|
with patch('homeassistant.components.automation.sun.dt_util.utcnow',
|
||||||
automation.DOMAIN: {
|
return_value=now):
|
||||||
'trigger': {
|
self.assertTrue(automation.setup(self.hass, {
|
||||||
'platform': 'sun',
|
automation.DOMAIN: {
|
||||||
'event': 'sunset',
|
'trigger': {
|
||||||
},
|
'platform': 'sun',
|
||||||
'action': {
|
'event': 'sunset',
|
||||||
'execute_service': 'test.automation',
|
},
|
||||||
|
'action': {
|
||||||
|
'execute_service': 'test.automation',
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}))
|
||||||
}))
|
|
||||||
|
|
||||||
fire_time_changed(self.hass, trigger_time)
|
fire_time_changed(self.hass, trigger_time)
|
||||||
self.hass.pool.block_till_done()
|
self.hass.pool.block_till_done()
|
||||||
@ -61,19 +65,22 @@ class TestAutomationSun(unittest.TestCase):
|
|||||||
sun.STATE_ATTR_NEXT_RISING: '14:00:00 16-09-2015',
|
sun.STATE_ATTR_NEXT_RISING: '14:00:00 16-09-2015',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
now = datetime(2015, 9, 13, 23, tzinfo=dt_util.UTC)
|
||||||
trigger_time = datetime(2015, 9, 16, 14, tzinfo=dt_util.UTC)
|
trigger_time = datetime(2015, 9, 16, 14, tzinfo=dt_util.UTC)
|
||||||
|
|
||||||
self.assertTrue(automation.setup(self.hass, {
|
with patch('homeassistant.components.automation.sun.dt_util.utcnow',
|
||||||
automation.DOMAIN: {
|
return_value=now):
|
||||||
'trigger': {
|
self.assertTrue(automation.setup(self.hass, {
|
||||||
'platform': 'sun',
|
automation.DOMAIN: {
|
||||||
'event': 'sunrise',
|
'trigger': {
|
||||||
},
|
'platform': 'sun',
|
||||||
'action': {
|
'event': 'sunrise',
|
||||||
'execute_service': 'test.automation',
|
},
|
||||||
|
'action': {
|
||||||
|
'execute_service': 'test.automation',
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}))
|
||||||
}))
|
|
||||||
|
|
||||||
fire_time_changed(self.hass, trigger_time)
|
fire_time_changed(self.hass, trigger_time)
|
||||||
self.hass.pool.block_till_done()
|
self.hass.pool.block_till_done()
|
||||||
@ -84,20 +91,23 @@ class TestAutomationSun(unittest.TestCase):
|
|||||||
sun.STATE_ATTR_NEXT_SETTING: '02:00:00 16-09-2015',
|
sun.STATE_ATTR_NEXT_SETTING: '02:00:00 16-09-2015',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
now = datetime(2015, 9, 15, 23, tzinfo=dt_util.UTC)
|
||||||
trigger_time = datetime(2015, 9, 16, 2, 30, tzinfo=dt_util.UTC)
|
trigger_time = datetime(2015, 9, 16, 2, 30, tzinfo=dt_util.UTC)
|
||||||
|
|
||||||
self.assertTrue(automation.setup(self.hass, {
|
with patch('homeassistant.components.automation.sun.dt_util.utcnow',
|
||||||
automation.DOMAIN: {
|
return_value=now):
|
||||||
'trigger': {
|
self.assertTrue(automation.setup(self.hass, {
|
||||||
'platform': 'sun',
|
automation.DOMAIN: {
|
||||||
'event': 'sunset',
|
'trigger': {
|
||||||
'offset': '0:30:00'
|
'platform': 'sun',
|
||||||
},
|
'event': 'sunset',
|
||||||
'action': {
|
'offset': '0:30:00'
|
||||||
'execute_service': 'test.automation',
|
},
|
||||||
|
'action': {
|
||||||
|
'execute_service': 'test.automation',
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}))
|
||||||
}))
|
|
||||||
|
|
||||||
fire_time_changed(self.hass, trigger_time)
|
fire_time_changed(self.hass, trigger_time)
|
||||||
self.hass.pool.block_till_done()
|
self.hass.pool.block_till_done()
|
||||||
@ -108,20 +118,23 @@ class TestAutomationSun(unittest.TestCase):
|
|||||||
sun.STATE_ATTR_NEXT_RISING: '14:00:00 16-09-2015',
|
sun.STATE_ATTR_NEXT_RISING: '14:00:00 16-09-2015',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
now = datetime(2015, 9, 13, 23, tzinfo=dt_util.UTC)
|
||||||
trigger_time = datetime(2015, 9, 16, 13, 30, tzinfo=dt_util.UTC)
|
trigger_time = datetime(2015, 9, 16, 13, 30, tzinfo=dt_util.UTC)
|
||||||
|
|
||||||
self.assertTrue(automation.setup(self.hass, {
|
with patch('homeassistant.components.automation.sun.dt_util.utcnow',
|
||||||
automation.DOMAIN: {
|
return_value=now):
|
||||||
'trigger': {
|
self.assertTrue(automation.setup(self.hass, {
|
||||||
'platform': 'sun',
|
automation.DOMAIN: {
|
||||||
'event': 'sunrise',
|
'trigger': {
|
||||||
'offset': '-0:30:00'
|
'platform': 'sun',
|
||||||
},
|
'event': 'sunrise',
|
||||||
'action': {
|
'offset': '-0:30:00'
|
||||||
'execute_service': 'test.automation',
|
},
|
||||||
|
'action': {
|
||||||
|
'execute_service': 'test.automation',
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}))
|
||||||
}))
|
|
||||||
|
|
||||||
fire_time_changed(self.hass, trigger_time)
|
fire_time_changed(self.hass, trigger_time)
|
||||||
self.hass.pool.block_till_done()
|
self.hass.pool.block_till_done()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user