8000 Use expected behvaior for above/below by emlove · Pull Request #7857 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use expected behvaior for above/below #7857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions homeassistant/helpers/condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ def async_numeric_state(hass: HomeAssistant, entity, below=None, above=None,
_LOGGER.warning("Value cannot be processed as a number: %s", value)
return False

if below is not None and value > below:
if below is not None and value >= below:
return False

if above is not None and value < above:
if above is not None and value <= above:
return False

return True
Expand Down
58 changes: 52 additions & 6 deletions tests/components/automation/test_numeric_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,29 @@ def test_if_not_fires_on_entity_change_below_to_below(self):
self.hass.block_till_done()
self.assertEqual(0, 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)
self.hass.block_till_done()

assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
'entity_id': 'test.entity',
'below': 10,
},
'action': {
'service': 'test.automation'
}
}
})

# 10 is not below 10 so this should not fire again
self.hass.states.set('test.entity', 10)
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))

def test_if_fires_on_entity_change_above(self):
""""Test the firing with changed entity."""
assert setup_component(self.hass, automation.DOMAIN, {
Expand Down Expand Up @@ -169,6 +192,30 @@ def test_if_not_fires_on_entity_change_above_to_above(self):
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))

def test_if_not_above_fires_on_entity_change_to_equal(self):
""""Test the firing with changed entity."""
# set initial state
self.hass.states.set('test.entity', 9)
self.hass.block_till_done()

assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
E51B 'platform': 'numeric_state',
'entity_id': 'test.entity',
'above': 10,
},
'action': {
'service': 'test.automation'
}
}
})

# 10 is not above 10 so this should not fire again
self.hass.states.set('test.entity', 10)
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))

def test_if_fires_on_entity_change_below_range(self):
""""Test the firing with changed entity."""
assert setup_component(self.hass, automation.DOMAIN, {
Expand Down Expand Up @@ -494,7 +541,6 @@ def test_not_fires_on_attr_change_with_attr_not_below_multiple_attr(self):
def test_if_action(self):
""""Test if action."""
entity_id = 'domain.test_entity'
test_state = 10
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
Expand All @@ -504,28 +550,28 @@ def test_if_action(self):
'condition': {
'condition': 'numeric_state',
'entity_id': entity_id,
'above': test_state,
'below': test_state + 2
'above': 8,
'below': 12,
},
'action': {
'service': 'test.automation'
}
}
})

self.hass.states.set(entity_id, test_state)
self.hass.states.set(entity_id, 10)
self.hass.bus.fire('test_event')
self.hass.block_till_done()

self.assertEqual(1, len(self.calls))

self.hass.states.set(entity_id, test_state - 1)
self.hass.states.set(entity_id, 8)
self.hass.bus.fire('test_event')
self.hass.block_till_done()

self.assertEqual(1, len(self.calls))

self.hass.states.set(entity_id, test_state + 1)
self.hass.states.set(entity_id, 9)
self.hass.bus.fire('test_event')
self.hass.block_till_done()

Expand Down
0