Fix state for trigger with forced updates (#11595)

This commit is contained in:
Adam Mills 2018-01-12 01:06:09 -05:00 committed by Paulus Schoutsen
parent 88161cd5c9
commit 6918993c75
2 changed files with 35 additions and 1 deletions

View File

@ -55,7 +55,7 @@ def async_trigger(hass, config, action):
# Ignore changes to state attributes if from/to is in use
if (not match_all and from_s is not None and to_s is not None and
from_s.last_changed == to_s.last_changed):
from_s.state == to_s.state):
return
if not time_delta:

View File

@ -409,6 +409,40 @@ class TestAutomationState(unittest.TestCase):
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
def test_if_fires_on_entity_change_with_for_multiple_force_update(self):
"""Test for firing on entity change with for and force update."""
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'state',
'entity_id': 'test.force_entity',
'to': 'world',
'for': {
'seconds': 5
},
},
'action': {
'service': 'test.automation'
}
}
})
utcnow = dt_util.utcnow()
with patch('homeassistant.core.dt_util.utcnow') as mock_utcnow:
mock_utcnow.return_value = utcnow
self.hass.states.set('test.force_entity', 'world', None, True)
self.hass.block_till_done()
for _ in range(0, 4):
mock_utcnow.return_value += timedelta(seconds=1)
fire_time_changed(self.hass, mock_utcnow.return_value)
self.hass.states.set('test.force_entity', 'world', None, True)
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
mock_utcnow.return_value += timedelta(seconds=4)
fire_time_changed(self.hass, mock_utcnow.return_value)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
def test_if_fires_on_entity_change_with_for(self):
"""Test for firing on entity change with for."""
assert setup_component(self.hass, automation.DOMAIN, {