mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Fix state for trigger with forced updates (#11595)
This commit is contained in:
parent
88161cd5c9
commit
6918993c75
@ -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:
|
||||
|
@ -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, {
|
||||
|
Loading…
x
Reference in New Issue
Block a user