<s> """<STR_LIT>""" <EOL> import unittest <EOL> from homeassistant . bootstrap import _setup_component <EOL> import homeassistant . components . automation as automation <EOL> from tests . common import get_test_home_assistant <EOL> class TestAutomationNumericState ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass = get_test_home_assistant ( ) <EOL> self . hass . config . components . append ( '<STR_LIT>' ) <EOL> self . calls = [ ] <EOL> def record_call ( service ) : <EOL> """<STR_LIT>""" <EOL> self . calls . append ( service ) <EOL> self . hass . services . register ( '<STR_LIT:test>' , '<STR_LIT>' , record_call ) <EOL> def tearDown ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass . stop ( ) <EOL> def test_if_fires_on_entity_change_below ( self ) : <EOL> """<STR_LIT>""" <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } ) <EOL> self . hass . states . set ( '<STR_LIT>' , <NUM_LIT:9> ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . calls ) ) <EOL> def test_if_fires_on_entity_change_over_to_below ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass . states . set ( '<STR_LIT>' , <NUM_LIT:11> ) <EOL> self . hass . pool . block_till_done ( ) <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } ) <EOL> self . hass . states . set ( '<STR_LIT>' , <NUM_LIT:9> ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . calls ) ) <EOL> def test_if_not_fires_on_entity_change_below_to_below ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass . states . set ( '<STR_LIT>' , <NUM_LIT:9> ) <EOL> self . hass . pool . block_till_done ( ) <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } ) <EOL> self . hass . states . set ( '<STR_LIT>' , <NUM_LIT:8> ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( self . calls ) ) <EOL> def test_if_fires_on_entity_change_above ( self ) : <EOL> """<STR_LIT>""" <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } ) <EOL> self . hass . states . set ( '<STR_LIT>' , <NUM_LIT:11> ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . calls ) ) <EOL> def test_if_fires_on_entity_change_below_to_above ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass . states . set ( '<STR_LIT>' , <NUM_LIT:9> ) <EOL> self . hass . pool . block_till_done ( ) <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } ) <EOL> self . hass . states . set ( '<STR_LIT>' , <NUM_LIT:11> ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . calls ) ) <EOL> def test_if_not_fires_on_entity_change_above_to_above ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass . states . set ( '<STR_LIT>' , <NUM_LIT:11> ) <EOL> self . hass . pool . block_till_done ( ) <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } ) <EOL> self . hass . states . set ( '<STR_LIT>' , <NUM_LIT:12> ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( self . calls ) ) <EOL> def test_if_fires_on_entity_change_below_range ( self ) : <EOL> """<STR_LIT>""" <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } ) <EOL> self . hass . states . set ( '<STR_LIT>' , <NUM_LIT:9> ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . calls ) ) <EOL> def test_if_fires_on_entity_change_below_above_range ( self ) : <EOL> """<STR_LIT>""" <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } ) <EOL> self . hass . states . set ( '<STR_LIT>' , <NUM_LIT:4> ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( self . calls ) ) <EOL> def test_if_fires_on_entity_change_over_to_below_range ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass . states . set ( '<STR_LIT>' , <NUM_LIT:11> ) <EOL> self . hass . pool . block_till_done ( ) <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } ) <EOL> self . hass . states . set ( '<STR_LIT>' , <NUM_LIT:9> ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . calls ) ) <EOL> def test_if_fires_on_entity_change_over_to_below_above_range ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass . states . set ( '<STR_LIT>' , <NUM_LIT:11> ) <EOL> self . hass . pool . block_till_done ( ) <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } ) <EOL> self . hass . states . set ( '<STR_LIT>' , <NUM_LIT:4> ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( self . calls ) ) <EOL> def test_if_not_fires_if_entity_not_match ( self ) : <EOL> """<STR_LIT>""" <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:100> , <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } ) <EOL> self . hass . states . set ( '<STR_LIT>' , <NUM_LIT:11> ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( self . calls ) ) <EOL> def test_if_fires_on_entity_change_below_with_attribute ( self ) : <EOL> """<STR_LIT>""" <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } ) <EOL> self . hass . states . set ( '<STR_LIT>' , <NUM_LIT:9> , { '<STR_LIT>' : <NUM_LIT:11> } ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . calls ) ) <EOL> def test_if_not_fires_on_entity_change_not_below_with_attribute ( self ) : <EOL> """<STR_LIT>""" <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } ) <EOL> self . hass . states . set ( '<STR_LIT>' , <NUM_LIT:11> , { '<STR_LIT>' : <NUM_LIT:9> } ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( self . calls ) ) <EOL> def test_if_fires_on_attribute_change_with_attribute_below ( self ) : <EOL> """<STR_LIT>""" <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } ) <EOL> self . hass . states . set ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : <NUM_LIT:9> } ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . calls ) ) <EOL> def test_if_not_fires_on_attribute_change_with_attribute_not_below ( self ) : <EOL> """<STR_LIT>""" <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } ) <EOL> self . hass . states . set ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : <NUM_LIT:11> } ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( self . calls ) ) <EOL> def test_if_not_fires_on_entity_change_with_attribute_below ( self ) : <EOL> """<STR_LIT>""" <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } ) <EOL> self . hass . states . set ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : <NUM_LIT:11> } ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( self . calls ) ) <EOL> def test_if_not_fires_on_entity_change_with_not_attribute_below ( self ) : <EOL> """<STR_LIT>""" <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } ) <EOL> self . hass . states . set ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( self . calls ) ) <EOL> def test_fires_on_attr_change_with_attribute_below_and_multiple_attr ( self ) : <EOL> """<STR_LIT>""" <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } ) <EOL> self . hass . states . set ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : <NUM_LIT:9> , '<STR_LIT>' : <NUM_LIT:11> } ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . calls ) ) <EOL> def test_template_list ( self ) : <EOL> """<STR_LIT>""" <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } ) <EOL> self . hass . states . set ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : [ <NUM_LIT:11> , <NUM_LIT:15> , <NUM_LIT:3> ] } ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . calls ) ) <EOL> def test_template_string ( self ) : <EOL> """<STR_LIT>""" <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' % '<STR_LIT>' . join ( ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> } , <EOL> } <EOL> } <EOL> } ) <EOL> self . hass . states . set ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . hass . states . set ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . calls ) ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> self . calls [ <NUM_LIT:0> ] . data [ '<STR_LIT>' ] ) <EOL> def test_not_fires_on_attr_change_with_attr_not_below_multiple_attr ( self ) : <EOL> """<STR_LIT>""" <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } ) <EOL> self . hass . states . set ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : <NUM_LIT:11> , '<STR_LIT>' : <NUM_LIT:9> } ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( self . calls ) ) <EOL> def test_if_action ( self ) : <EOL> """<STR_LIT>""" <EOL> entity_id = '<STR_LIT>' <EOL> test_state = <NUM_LIT:10> <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : entity_id , <EOL> '<STR_LIT>' : test_state , <EOL> '<STR_LIT>' : test_state + <NUM_LIT:2> <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } ) <EOL> self . hass . states . set ( entity_id , test_state ) <EOL> self . hass . bus . fire ( '<STR_LIT>' ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . calls ) ) <EOL> self . hass . states . set ( entity_id , test_state - <NUM_LIT:1> ) <EOL> self . hass . bus . fire ( '<STR_LIT>' ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . calls ) ) <EOL> self . hass . states . set ( entity_id , test_state + <NUM_LIT:1> ) <EOL> self . hass . bus . fire ( '<STR_LIT>' ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( self . calls ) ) </s>
