Bugfix trigger state with multible entities (#10857)

* Bugfix trigger state with multible entities

* Fix numeric state

* fix lint

* fix dict

* fix unsub

* fix logic

* fix name

* fix new logic

* add test for state

* add numeric state test for unsub

* add test for multible entities

* Update numeric_state.py

* Update numeric_state.py

* Update state.py

* Fix logic for triple match

* Add clear to numeric state

* clear for state trigger
This commit is contained in:
Pascal Vizeli 2017-11-30 21:03:52 +01:00 committed by GitHub
parent bfc61c268a
commit ea6ca9252c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 134 additions and 16 deletions

View file

@ -84,6 +84,36 @@ class TestAutomationNumericState(unittest.TestCase):
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
def test_if_fires_on_entities_change_over_to_below(self):
""""Test the firing with changed entities."""
self.hass.states.set('test.entity_1', 11)
self.hass.states.set('test.entity_2', 11)
self.hass.block_till_done()
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
'entity_id': [
'test.entity_1',
'test.entity_2',
],
'below': 10,
},
'action': {
'service': 'test.automation'
}
}
})
# 9 is below 10
self.hass.states.set('test.entity_1', 9)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
self.hass.states.set('test.entity_2', 9)
self.hass.block_till_done()
self.assertEqual(2, len(self.calls))
def test_if_not_fires_on_entity_change_below_to_below(self):
""""Test the firing with changed entity."""
self.hass.states.set('test.entity', 11)
@ -112,6 +142,11 @@ class TestAutomationNumericState(unittest.TestCase):
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
# still below so should not fire again
self.hass.states.set('test.entity', 3)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
def test_if_not_below_fires_on_entity_change_to_equal(self):
""""Test the firing with changed entity."""
self.hass.states.set('test.entity', 11)
@ -701,6 +736,48 @@ class TestAutomationNumericState(unittest.TestCase):
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
def test_if_not_fires_on_entities_change_with_for_afte_stop(self):
"""Test for not firing on entities change with for after stop."""
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
'entity_id': [
'test.entity_1',
'test.entity_2',
],
'above': 8,
'below': 12,
'for': {
'seconds': 5
},
},
'action': {
'service': 'test.automation'
}
}
})
self.hass.states.set('test.entity_1', 9)
self.hass.states.set('test.entity_2', 9)
self.hass.block_till_done()
fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=10))
self.hass.block_till_done()
self.assertEqual(2, len(self.calls))
self.hass.states.set('test.entity_1', 15)
self.hass.states.set('test.entity_2', 15)
self.hass.block_till_done()
self.hass.states.set('test.entity_1', 9)
self.hass.states.set('test.entity_2', 9)
self.hass.block_till_done()
automation.turn_off(self.hass)
self.hass.block_till_done()
fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=10))
self.hass.block_till_done()
self.assertEqual(2, len(self.calls))
def test_if_fires_on_entity_change_with_for_attribute_change(self):
"""Test for firing on entity change with for and attribute change."""
assert setup_component(self.hass, automation.DOMAIN, {