desc
stringlengths 3
26.7k
| decl
stringlengths 11
7.89k
| bodies
stringlengths 8
553k
|
---|---|---|
'Test for action with a list of weekdays.'
| def test_if_action_list_weekday(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'event', 'event_type': 'test_event'}, 'condition': {'condition': 'time', 'weekday': ['mon', 'tue']}, 'action': {'service': 'test.automation'}}})
days_past_monday = dt_util.now().weekday()
monday = (dt_util.now() - timedelta(days=days_past_monday))
tuesday = (monday + timedelta(days=1))
wednesday = (tuesday + timedelta(days=1))
with patch('homeassistant.helpers.condition.dt_util.now', return_value=monday):
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
with patch('homeassistant.helpers.condition.dt_util.now', return_value=tuesday):
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(2, len(self.calls))
with patch('homeassistant.helpers.condition.dt_util.now', return_value=wednesday):
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(2, len(self.calls))
|
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
mock_component(self.hass, 'group')
self.calls = []
@callback
def record_call(service):
'Helper for recording the call.'
self.calls.append(service)
self.hass.services.register('test', 'automation', record_call)
|
'"Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test the firing of events.'
| def test_if_fires_on_event(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'event', 'event_type': 'test_event'}, 'action': {'service': 'test.automation'}}})
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
automation.turn_off(self.hass)
self.hass.block_till_done()
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test the firing of events with data.'
| def test_if_fires_on_event_with_data(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'event', 'event_type': 'test_event', 'event_data': {'some_attr': 'some_value'}}, 'action': {'service': 'test.automation'}}})
self.hass.bus.fire('test_event', {'some_attr': 'some_value', 'another': 'value'})
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test firing of event if no match.'
| def test_if_not_fires_if_event_data_not_matches(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'event', 'event_type': 'test_event', 'event_data': {'some_attr': 'some_value'}}, 'action': {'service': 'test.automation'}}})
self.hass.bus.fire('test_event', {'some_attr': 'some_other_value'})
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
mock_component(self.hass, 'group')
mock_mqtt_component(self.hass)
self.calls = []
@callback
def record_call(service):
'Helper to record calls.'
self.calls.append(service)
self.hass.services.register('test', 'automation', record_call)
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test if message is fired on topic match.'
| def test_if_fires_on_topic_match(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'mqtt', 'topic': 'test-topic'}, 'action': {'service': 'test.automation', 'data_template': {'some': '{{ trigger.platform }} - {{ trigger.topic }} - {{ trigger.payload }} - {{ trigger.payload_json.hello }}'}}}})
fire_mqtt_message(self.hass, 'test-topic', '{ "hello": "world" }')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
self.assertEqual('mqtt - test-topic - { "hello": "world" } - world', self.calls[0].data['some'])
automation.turn_off(self.hass)
self.hass.block_till_done()
fire_mqtt_message(self.hass, 'test-topic', 'test_payload')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test if message is fired on topic and payload match.'
| def test_if_fires_on_topic_and_payload_match(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'mqtt', 'topic': 'test-topic', 'payload': 'hello'}, 'action': {'service': 'test.automation'}}})
fire_mqtt_message(self.hass, 'test-topic', 'hello')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test if message is not fired on topic but no payload.'
| def test_if_not_fires_on_topic_but_no_payload_match(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'mqtt', 'topic': 'test-topic', 'payload': 'hello'}, 'action': {'service': 'test.automation'}}})
fire_mqtt_message(self.hass, 'test-topic', 'no-hello')
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'Setup things to be run when tests are started.'
| @mock.patch('pylitejet.LiteJet')
def setup_method(self, method, mock_pylitejet):
| self.hass = get_test_home_assistant()
self.hass.start()
self.switch_pressed_callbacks = {}
self.switch_released_callbacks = {}
self.calls = []
def get_switch_name(number):
return ('Mock Switch #' + str(number))
def on_switch_pressed(number, callback):
self.switch_pressed_callbacks[number] = callback
def on_switch_released(number, callback):
self.switch_released_callbacks[number] = callback
def record_call(service):
self.calls.append(service)
self.mock_lj = mock_pylitejet.return_value
self.mock_lj.loads.return_value = range(0)
self.mock_lj.button_switches.return_value = range(1, 3)
self.mock_lj.all_switches.return_value = range(1, 6)
self.mock_lj.scenes.return_value = range(0)
self.mock_lj.get_switch_name.side_effect = get_switch_name
self.mock_lj.on_switch_pressed.side_effect = on_switch_pressed
self.mock_lj.on_switch_released.side_effect = on_switch_released
config = {'litejet': {'port': '/tmp/this_will_be_mocked'}}
assert setup.setup_component(self.hass, litejet.DOMAIN, config)
self.hass.services.register('test', 'automation', record_call)
self.hass.block_till_done()
self.start_time = dt_util.utcnow()
self.last_delta = timedelta(0)
|
'Stop everything that was started.'
| def teardown_method(self, method):
| self.hass.stop()
|
'Test to simulate a press.'
| def simulate_press(self, number):
| _LOGGER.info('*** simulate press of %d', number)
callback = self.switch_pressed_callbacks.get(number)
with mock.patch('homeassistant.helpers.condition.dt_util.utcnow', return_value=(self.start_time + self.last_delta)):
if (callback is not None):
callback()
self.hass.block_till_done()
|
'Test to simulate releasing.'
| def simulate_release(self, number):
| _LOGGER.info('*** simulate release of %d', number)
callback = self.switch_released_callbacks.get(number)
with mock.patch('homeassistant.helpers.condition.dt_util.utcnow', return_value=(self.start_time + self.last_delta)):
if (callback is not None):
callback()
self.hass.block_till_done()
|
'Test to simulate time.'
| def simulate_time(self, delta):
| _LOGGER.info('*** simulate time change by %s: %s', delta, (self.start_time + delta))
self.last_delta = delta
with mock.patch('homeassistant.helpers.condition.dt_util.utcnow', return_value=(self.start_time + delta)):
_LOGGER.info('now=%s', dt_util.utcnow())
fire_time_changed(self.hass, (self.start_time + delta))
self.hass.block_till_done()
_LOGGER.info('done with now=%s', dt_util.utcnow())
|
'Test setting up the automation.'
| def setup_automation(self, trigger):
| assert setup.setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: [{'alias': 'My Test', 'trigger': trigger, 'action': {'service': 'test.automation'}}]})
self.hass.block_till_done()
|
'Test the simplest form of a LiteJet trigger.'
| def test_simple(self):
| self.setup_automation({'platform': 'litejet', 'number': ENTITY_OTHER_SWITCH_NUMBER})
self.simulate_press(ENTITY_OTHER_SWITCH_NUMBER)
self.simulate_release(ENTITY_OTHER_SWITCH_NUMBER)
assert (len(self.calls) == 1)
|
'Test a too short hold.'
| def test_held_more_than_short(self):
| self.setup_automation({'platform': 'litejet', 'number': ENTITY_OTHER_SWITCH_NUMBER, 'held_more_than': {'milliseconds': '200'}})
self.simulate_press(ENTITY_OTHER_SWITCH_NUMBER)
self.simulate_time(timedelta(seconds=0.1))
self.simulate_release(ENTITY_OTHER_SWITCH_NUMBER)
assert (len(self.calls) == 0)
|
'Test a hold that is long enough.'
| def test_held_more_than_long(self):
| self.setup_automation({'platform': 'litejet', 'number': ENTITY_OTHER_SWITCH_NUMBER, 'held_more_than': {'milliseconds': '200'}})
self.simulate_press(ENTITY_OTHER_SWITCH_NUMBER)
assert (len(self.calls) == 0)
self.simulate_time(timedelta(seconds=0.3))
assert (len(self.calls) == 1)
self.simulate_release(ENTITY_OTHER_SWITCH_NUMBER)
assert (len(self.calls) == 1)
|
'Test a hold that is short enough.'
| def test_held_less_than_short(self):
| self.setup_automation({'platform': 'litejet', 'number': ENTITY_OTHER_SWITCH_NUMBER, 'held_less_than': {'milliseconds': '200'}})
self.simulate_press(ENTITY_OTHER_SWITCH_NUMBER)
self.simulate_time(timedelta(seconds=0.1))
assert (len(self.calls) == 0)
self.simulate_release(ENTITY_OTHER_SWITCH_NUMBER)
assert (len(self.calls) == 1)
|
'Test a hold that is too long.'
| def test_held_less_than_long(self):
| self.setup_automation({'platform': 'litejet', 'number': ENTITY_OTHER_SWITCH_NUMBER, 'held_less_than': {'milliseconds': '200'}})
self.simulate_press(ENTITY_OTHER_SWITCH_NUMBER)
assert (len(self.calls) == 0)
self.simulate_time(timedelta(seconds=0.3))
assert (len(self.calls) == 0)
self.simulate_release(ENTITY_OTHER_SWITCH_NUMBER)
assert (len(self.calls) == 0)
|
'Test an in-range trigger with a too short hold.'
| def test_held_in_range_short(self):
| self.setup_automation({'platform': 'litejet', 'number': ENTITY_OTHER_SWITCH_NUMBER, 'held_more_than': {'milliseconds': '100'}, 'held_less_than': {'milliseconds': '300'}})
self.simulate_press(ENTITY_OTHER_SWITCH_NUMBER)
self.simulate_time(timedelta(seconds=0.05))
self.simulate_release(ENTITY_OTHER_SWITCH_NUMBER)
assert (len(self.calls) == 0)
|
'Test an in-range trigger with a just right hold.'
| def test_held_in_range_just_right(self):
| self.setup_automation({'platform': 'litejet', 'number': ENTITY_OTHER_SWITCH_NUMBER, 'held_more_than': {'milliseconds': '100'}, 'held_less_than': {'milliseconds': '300'}})
self.simulate_press(ENTITY_OTHER_SWITCH_NUMBER)
assert (len(self.calls) == 0)
self.simulate_time(timedelta(seconds=0.2))
assert (len(self.calls) == 0)
self.simulate_release(ENTITY_OTHER_SWITCH_NUMBER)
assert (len(self.calls) == 1)
|
'Test an in-range trigger with a too long hold.'
| def test_held_in_range_long(self):
| self.setup_automation({'platform': 'litejet', 'number': ENTITY_OTHER_SWITCH_NUMBER, 'held_more_than': {'milliseconds': '100'}, 'held_less_than': {'milliseconds': '300'}})
self.simulate_press(ENTITY_OTHER_SWITCH_NUMBER)
assert (len(self.calls) == 0)
self.simulate_time(timedelta(seconds=0.4))
assert (len(self.calls) == 0)
self.simulate_release(ENTITY_OTHER_SWITCH_NUMBER)
assert (len(self.calls) == 0)
|
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
mock_component(self.hass, 'group')
self.hass.states.set('test.entity', 'hello')
self.calls = []
@callback
def record_call(service):
'Helper to record calls.'
self.calls.append(service)
self.hass.services.register('test', 'automation', record_call)
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test for firing on boolean change.'
| def test_if_fires_on_change_bool(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'template', 'value_template': '{{ true }}'}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
automation.turn_off(self.hass)
self.hass.block_till_done()
self.hass.states.set('test.entity', 'planet')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test for firing on change.'
| def test_if_fires_on_change_str(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'template', 'value_template': 'true'}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test for firing on change.'
| def test_if_fires_on_change_str_crazy(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'template', 'value_template': 'TrUE'}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test for not firing on boolean change.'
| def test_if_not_fires_on_change_bool(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'template', 'value_template': '{{ false }}'}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'Test for not firing on string change.'
| def test_if_not_fires_on_change_str(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'template', 'value_template': 'False'}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'Test for not firing on string change.'
| def test_if_not_fires_on_change_str_crazy(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'template', 'value_template': 'Anything other than "true" is false.'}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'Test for firing on no change.'
| def test_if_fires_on_no_change(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'template', 'value_template': '{{ true }}'}, 'action': {'service': 'test.automation'}}})
self.hass.block_till_done()
self.calls = []
self.hass.states.set('test.entity', 'hello')
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'Test for firing on two changes.'
| def test_if_fires_on_two_change(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'template', 'value_template': '{{ true }}'}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test for firing on change with template.'
| def test_if_fires_on_change_with_template(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'template', 'value_template': '{{ is_state("test.entity", "world") }}'}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test for not firing on change with template.'
| def test_if_not_fires_on_change_with_template(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'template', 'value_template': '{{ is_state("test.entity", "hello") }}'}, 'action': {'service': 'test.automation'}}})
self.hass.block_till_done()
self.calls = []
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
assert (len(self.calls) == 0)
|
'Test for firing on change with template advanced.'
| def test_if_fires_on_change_with_template_advanced(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'template', 'value_template': '{%- if is_state("test.entity", "world") -%}\n true\n {%- else -%}\n false\n {%- endif -%}'}, 'action': {'service': 'test.automation', 'data_template': {'some': ('{{ trigger.%s }}' % '}} - {{ trigger.'.join(('platform', 'entity_id', 'from_state.state', 'to_state.state')))}}}})
self.hass.block_till_done()
self.calls = []
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
self.assertEqual('template - test.entity - hello - world', self.calls[0].data['some'])
|
'Test for firing on no change with template advanced.'
| def test_if_fires_on_no_change_with_template_advanced(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'template', 'value_template': '{%- if is_state("test.entity", "world") -%}\n true\n {%- else -%}\n false\n {%- endif -%}'}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'worldz')
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
self.hass.states.set('test.entity', 'hello')
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'Test for firing on change with template.'
| def test_if_fires_on_change_with_template_2(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'template', 'value_template': '{{ not is_state("test.entity", "world") }}'}, 'action': {'service': 'test.automation'}}})
self.hass.block_till_done()
self.calls = []
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
assert (len(self.calls) == 0)
self.hass.states.set('test.entity', 'home')
self.hass.block_till_done()
assert (len(self.calls) == 1)
self.hass.states.set('test.entity', 'work')
self.hass.block_till_done()
assert (len(self.calls) == 1)
self.hass.states.set('test.entity', 'not_home')
self.hass.block_till_done()
assert (len(self.calls) == 1)
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
assert (len(self.calls) == 1)
self.hass.states.set('test.entity', 'home')
self.hass.block_till_done()
assert (len(self.calls) == 2)
|
'Test for firing if action.'
| def test_if_action(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'event', 'event_type': 'test_event'}, 'condition': [{'condition': 'template', 'value_template': '{{ is_state("test.entity", "world") }}'}], 'action': {'service': 'test.automation'}}})
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test for firing on change with bad template.'
| def test_if_fires_on_change_with_bad_template(self):
| with assert_setup_component(0):
assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'template', 'value_template': '{{ '}, 'action': {'service': 'test.automation'}}})
|
'Test for firing on change with bad template.'
| def test_if_fires_on_change_with_bad_template_2(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'template', 'value_template': '{{ xyz | round(0) }}'}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
mock_component(self.hass, 'group')
assert setup_component(self.hass, zone.DOMAIN, {'zone': {'name': 'test', 'latitude': 32.880837, 'longitude': (-117.237561), 'radius': 250}})
self.calls = []
@callback
def record_call(service):
'Helper to record calls.'
self.calls.append(service)
self.hass.services.register('test', 'automation', record_call)
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test for firing on zone enter.'
| def test_if_fires_on_zone_enter(self):
| self.hass.states.set('test.entity', 'hello', {'latitude': 32.881011, 'longitude': (-117.234758)})
self.hass.block_till_done()
assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'zone', 'entity_id': 'test.entity', 'zone': 'zone.test', 'event': 'enter'}, 'action': {'service': 'test.automation', 'data_template': {'some': ('{{ trigger.%s }}' % '}} - {{ trigger.'.join(('platform', 'entity_id', 'from_state.state', 'to_state.state', 'zone.name')))}}}})
self.hass.states.set('test.entity', 'hello', {'latitude': 32.880586, 'longitude': (-117.237564)})
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
self.assertEqual('zone - test.entity - hello - hello - test', self.calls[0].data['some'])
self.hass.states.set('test.entity', 'hello', {'latitude': 32.881011, 'longitude': (-117.234758)})
self.hass.block_till_done()
automation.turn_off(self.hass)
self.hass.block_till_done()
self.hass.states.set('test.entity', 'hello', {'latitude': 32.880586, 'longitude': (-117.237564)})
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test for not firing on zone leave.'
| def test_if_not_fires_for_enter_on_zone_leave(self):
| self.hass.states.set('test.entity', 'hello', {'latitude': 32.880586, 'longitude': (-117.237564)})
self.hass.block_till_done()
assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'zone', 'entity_id': 'test.entity', 'zone': 'zone.test', 'event': 'enter'}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'hello', {'latitude': 32.881011, 'longitude': (-117.234758)})
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'Test for firing on zone leave.'
| def test_if_fires_on_zone_leave(self):
| self.hass.states.set('test.entity', 'hello', {'latitude': 32.880586, 'longitude': (-117.237564)})
self.hass.block_till_done()
assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'zone', 'entity_id': 'test.entity', 'zone': 'zone.test', 'event': 'leave'}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'hello', {'latitude': 32.881011, 'longitude': (-117.234758)})
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test for not firing on zone enter.'
| def test_if_not_fires_for_leave_on_zone_enter(self):
| self.hass.states.set('test.entity', 'hello', {'latitude': 32.881011, 'longitude': (-117.234758)})
self.hass.block_till_done()
assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'zone', 'entity_id': 'test.entity', 'zone': 'zone.test', 'event': 'leave'}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'hello', {'latitude': 32.880586, 'longitude': (-117.237564)})
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'Test for zone condition.'
| def test_zone_condition(self):
| self.hass.states.set('test.entity', 'hello', {'latitude': 32.880586, 'longitude': (-117.237564)})
self.hass.block_till_done()
assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'event', 'event_type': 'test_event'}, 'condition': {'condition': 'zone', 'entity_id': 'test.entity', 'zone': 'zone.test'}, 'action': {'service': 'test.automation'}}})
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
mock_component(self.hass, 'group')
setup_component(self.hass, sun.DOMAIN, {sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
self.calls = []
@callback
def record_call(service):
'Call recorder.'
self.calls.append(service)
self.hass.services.register('test', 'automation', record_call)
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test the sunset trigger.'
| def test_sunset_trigger(self):
| now = datetime(2015, 9, 15, 23, tzinfo=dt_util.UTC)
trigger_time = datetime(2015, 9, 16, 2, tzinfo=dt_util.UTC)
with patch('homeassistant.util.dt.utcnow', return_value=now):
setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'sun', 'event': 'sunset'}, 'action': {'service': 'test.automation'}}})
automation.turn_off(self.hass)
self.hass.block_till_done()
fire_time_changed(self.hass, trigger_time)
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
with patch('homeassistant.util.dt.utcnow', return_value=now):
automation.turn_on(self.hass)
self.hass.block_till_done()
fire_time_changed(self.hass, trigger_time)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test the sunrise trigger.'
| def test_sunrise_trigger(self):
| now = datetime(2015, 9, 13, 23, tzinfo=dt_util.UTC)
trigger_time = datetime(2015, 9, 16, 14, tzinfo=dt_util.UTC)
with patch('homeassistant.util.dt.utcnow', return_value=now):
setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'sun', 'event': 'sunrise'}, 'action': {'service': 'test.automation'}}})
fire_time_changed(self.hass, trigger_time)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test the sunset trigger with offset.'
| def test_sunset_trigger_with_offset(self):
| now = datetime(2015, 9, 15, 23, tzinfo=dt_util.UTC)
trigger_time = datetime(2015, 9, 16, 2, 30, tzinfo=dt_util.UTC)
with patch('homeassistant.util.dt.utcnow', return_value=now):
setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'sun', 'event': 'sunset', 'offset': '0:30:00'}, 'action': {'service': 'test.automation', 'data_template': {'some': ('{{ trigger.%s }}' % '}} - {{ trigger.'.join(('platform', 'event', 'offset')))}}}})
fire_time_changed(self.hass, trigger_time)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
self.assertEqual('sun - sunset - 0:30:00', self.calls[0].data['some'])
|
'Test the runrise trigger with offset.'
| def test_sunrise_trigger_with_offset(self):
| now = datetime(2015, 9, 13, 23, tzinfo=dt_util.UTC)
trigger_time = datetime(2015, 9, 16, 13, 30, tzinfo=dt_util.UTC)
with patch('homeassistant.util.dt.utcnow', return_value=now):
setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'sun', 'event': 'sunrise', 'offset': '-0:30:00'}, 'action': {'service': 'test.automation'}}})
fire_time_changed(self.hass, trigger_time)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test if action was before.'
| def test_if_action_before(self):
| setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'event', 'event_type': 'test_event'}, 'condition': {'condition': 'sun', 'before': 'sunrise'}, 'action': {'service': 'test.automation'}}})
now = datetime(2015, 9, 16, 15, tzinfo=dt_util.UTC)
with patch('homeassistant.util.dt.utcnow', return_value=now):
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
now = datetime(2015, 9, 16, 10, tzinfo=dt_util.UTC)
with patch('homeassistant.util.dt.utcnow', return_value=now):
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test if action was after.'
| def test_if_action_after(self):
| setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'event', 'event_type': 'test_event'}, 'condition': {'condition': 'sun', 'after': 'sunrise'}, 'action': {'service': 'test.automation'}}})
now = datetime(2015, 9, 16, 13, tzinfo=dt_util.UTC)
with patch('homeassistant.util.dt.utcnow', return_value=now):
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
now = datetime(2015, 9, 16, 15, tzinfo=dt_util.UTC)
with patch('homeassistant.util.dt.utcnow', return_value=now):
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test if action was before offset.'
| def test_if_action_before_with_offset(self):
| setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'event', 'event_type': 'test_event'}, 'condition': {'condition': 'sun', 'before': 'sunrise', 'before_offset': '+1:00:00'}, 'action': {'service': 'test.automation'}}})
now = datetime(2015, 9, 16, 14, 32, 44, tzinfo=dt_util.UTC)
with patch('homeassistant.util.dt.utcnow', return_value=now):
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
now = datetime(2015, 9, 16, 14, 32, 43, tzinfo=dt_util.UTC)
with patch('homeassistant.util.dt.utcnow', return_value=now):
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test if action was after offset.'
| def test_if_action_after_with_offset(self):
| setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'event', 'event_type': 'test_event'}, 'condition': {'condition': 'sun', 'after': 'sunrise', 'after_offset': '+1:00:00'}, 'action': {'service': 'test.automation'}}})
now = datetime(2015, 9, 16, 14, 32, 42, tzinfo=dt_util.UTC)
with patch('homeassistant.util.dt.utcnow', return_value=now):
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
now = datetime(2015, 9, 16, 14, 32, 43, tzinfo=dt_util.UTC)
with patch('homeassistant.util.dt.utcnow', return_value=now):
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test if action was before and after during.'
| def test_if_action_before_and_after_during(self):
| setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'event', 'event_type': 'test_event'}, 'condition': {'condition': 'sun', 'after': 'sunrise', 'before': 'sunset'}, 'action': {'service': 'test.automation'}}})
now = datetime(2015, 9, 16, 13, 8, 51, tzinfo=dt_util.UTC)
with patch('homeassistant.util.dt.utcnow', return_value=now):
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
now = datetime(2015, 9, 17, 2, 25, 18, tzinfo=dt_util.UTC)
with patch('homeassistant.util.dt.utcnow', return_value=now):
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
now = datetime(2015, 9, 16, 16, tzinfo=dt_util.UTC)
with patch('homeassistant.util.dt.utcnow', return_value=now):
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
mock_component(self.hass, 'group')
self.calls = []
@callback
def record_call(service):
'Helper to record calls.'
self.calls.append(service)
self.hass.services.register('test', 'automation', record_call)
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'"Test the firing with changed entity.'
| def test_if_fires_on_entity_change_below(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'numeric_state', 'entity_id': 'test.entity', 'below': 10}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 9)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
self.hass.states.set('test.entity', 12)
automation.turn_off(self.hass)
self.hass.block_till_done()
self.hass.states.set('test.entity', 9)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'"Test the firing with changed entity.'
| def test_if_fires_on_entity_change_over_to_below(self):
| 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'}}})
self.hass.states.set('test.entity', 9)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'"Test the firing with changed entity.'
| def test_if_not_fires_on_entity_change_below_to_below(self):
| self.hass.states.set('test.entity', 9)
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'}}})
self.hass.states.set('test.entity', 8)
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'"Test the firing with changed entity.'
| def test_if_not_below_fires_on_entity_change_to_equal(self):
| 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'}}})
self.hass.states.set('test.entity', 10)
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'"Test the firing with changed entity.'
| def test_if_fires_on_entity_change_above(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'numeric_state', 'entity_id': 'test.entity', 'above': 10}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 11)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'"Test the firing with changed entity.'
| def test_if_fires_on_entity_change_below_to_above(self):
| self.hass.states.set('test.entity', 9)
self.hass.block_till_done()
assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'numeric_state', 'entity_id': 'test.entity', 'above': 10}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 11)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'"Test the firing with changed entity.'
| def test_if_not_fires_on_entity_change_above_to_above(self):
| 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', 'above': 10}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 12)
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'"Test the firing with changed entity.'
| def test_if_not_above_fires_on_entity_change_to_equal(self):
| self.hass.states.set('test.entity', 9)
self.hass.block_till_done()
assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'numeric_state', 'entity_id': 'test.entity', 'above': 10}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 10)
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'"Test the firing with changed entity.'
| def test_if_fires_on_entity_change_below_range(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'numeric_state', 'entity_id': 'test.entity', 'below': 10, 'above': 5}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 9)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'"Test the firing with changed entity.'
| def test_if_fires_on_entity_change_below_above_range(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'numeric_state', 'entity_id': 'test.entity', 'below': 10, 'above': 5}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 4)
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'"Test the firing with changed entity.'
| def test_if_fires_on_entity_change_over_to_below_range(self):
| 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, 'above': 5}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 9)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'"Test the firing with changed entity.'
| def test_if_fires_on_entity_change_over_to_below_above_range(self):
| 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, 'above': 5}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 4)
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'"Test if not fired with non matching entity.'
| def test_if_not_fires_if_entity_not_match(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'numeric_state', 'entity_id': 'test.another_entity', 'below': 100}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 11)
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'"Test attributes change.'
| def test_if_fires_on_entity_change_below_with_attribute(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'numeric_state', 'entity_id': 'test.entity', 'below': 10}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 9, {'test_attribute': 11})
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'"Test attributes.'
| def test_if_not_fires_on_entity_change_not_below_with_attribute(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'numeric_state', 'entity_id': 'test.entity', 'below': 10}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 11, {'test_attribute': 9})
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'"Test attributes change.'
| def test_if_fires_on_attribute_change_with_attribute_below(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'numeric_state', 'entity_id': 'test.entity', 'value_template': '{{ state.attributes.test_attribute }}', 'below': 10}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'entity', {'test_attribute': 9})
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'"Test attributes change.'
| def test_if_not_fires_on_attribute_change_with_attribute_not_below(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'numeric_state', 'entity_id': 'test.entity', 'value_template': '{{ state.attributes.test_attribute }}', 'below': 10}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'entity', {'test_attribute': 11})
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'"Test attributes change.'
| def test_if_not_fires_on_entity_change_with_attribute_below(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'numeric_state', 'entity_id': 'test.entity', 'value_template': '{{ state.attributes.test_attribute }}', 'below': 10}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', '9', {'test_attribute': 11})
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'"Test attributes change.'
| def test_if_not_fires_on_entity_change_with_not_attribute_below(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'numeric_state', 'entity_id': 'test.entity', 'value_template': '{{ state.attributes.test_attribute }}', 'below': 10}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'entity')
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'"Test attributes change.'
| def test_fires_on_attr_change_with_attribute_below_and_multiple_attr(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'numeric_state', 'entity_id': 'test.entity', 'value_template': '{{ state.attributes.test_attribute }}', 'below': 10}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'entity', {'test_attribute': 9, 'not_test_attribute': 11})
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'"Test template list.'
| def test_template_list(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'numeric_state', 'entity_id': 'test.entity', 'value_template': '{{ state.attributes.test_attribute[2] }}', 'below': 10}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'entity', {'test_attribute': [11, 15, 3]})
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'"Test template string.'
| def test_template_string(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'numeric_state', 'entity_id': 'test.entity', 'value_template': '{{ state.attributes.test_attribute | multiply(10) }}', 'below': 10}, 'action': {'service': 'test.automation', 'data_template': {'some': ('{{ trigger.%s }}' % '}} - {{ trigger.'.join(('platform', 'entity_id', 'below', 'above', 'from_state.state', 'to_state.state')))}}}})
self.hass.states.set('test.entity', 'test state 1', {'test_attribute': '1.2'})
self.hass.block_till_done()
self.hass.states.set('test.entity', 'test state 2', {'test_attribute': '0.9'})
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
self.assertEqual('numeric_state - test.entity - 10.0 - None - test state 1 - test state 2', self.calls[0].data['some'])
|
'"Test if not fired changed attributes.'
| def test_not_fires_on_attr_change_with_attr_not_below_multiple_attr(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'numeric_state', 'entity_id': 'test.entity', 'value_template': '{{ state.attributes.test_attribute }}', 'below': 10}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'entity', {'test_attribute': 11, 'not_test_attribute': 9})
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'"Test if action.'
| def test_if_action(self):
| entity_id = 'domain.test_entity'
assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'event', 'event_type': 'test_event'}, 'condition': {'condition': 'numeric_state', 'entity_id': entity_id, 'above': 8, 'below': 12}, 'action': {'service': 'test.automation'}}})
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, 8)
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
self.hass.states.set(entity_id, 9)
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(2, len(self.calls))
|
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
mock_component(self.hass, 'group')
self.hass.states.set('test.entity', 'hello')
self.calls = []
@callback
def record_call(service):
'Call recorder.'
self.calls.append(service)
self.hass.services.register('test', 'automation', record_call)
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test for firing on entity change.'
| def test_if_fires_on_entity_change(self):
| self.hass.states.set('test.entity', 'hello')
self.hass.block_till_done()
assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'state', 'entity_id': 'test.entity'}, 'action': {'service': 'test.automation', 'data_template': {'some': ('{{ trigger.%s }}' % '}} - {{ trigger.'.join(('platform', 'entity_id', 'from_state.state', 'to_state.state', 'for')))}}}})
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
self.assertEqual('state - test.entity - hello - world - None', self.calls[0].data['some'])
automation.turn_off(self.hass)
self.hass.block_till_done()
self.hass.states.set('test.entity', 'planet')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test for firing on entity change with filter.'
| def test_if_fires_on_entity_change_with_from_filter(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'state', 'entity_id': 'test.entity', 'from': 'hello'}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test for firing on entity change with no filter.'
| def test_if_fires_on_entity_change_with_to_filter(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'state', 'entity_id': 'test.entity', 'to': 'world'}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test for not firing on attribute change.'
| def test_if_fires_on_attribute_change_with_to_filter(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'state', 'entity_id': 'test.entity', 'to': 'world'}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'world', {'test_attribute': 11})
self.hass.states.set('test.entity', 'world', {'test_attribute': 12})
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test for firing if both filters are a non match.'
| def test_if_fires_on_entity_change_with_both_filters(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'state', 'entity_id': 'test.entity', 'from': 'hello', 'to': 'world'}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test for not firing if to filter is not a match.'
| def test_if_not_fires_if_to_filter_not_match(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'state', 'entity_id': 'test.entity', 'from': 'hello', 'to': 'world'}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'moon')
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'Test for not firing if from filter is not a match.'
| def test_if_not_fires_if_from_filter_not_match(self):
| self.hass.states.set('test.entity', 'bye')
assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'state', 'entity_id': 'test.entity', 'from': 'hello', 'to': 'world'}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'Test for not firing if entity is not matching.'
| def test_if_not_fires_if_entity_not_match(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'state', 'entity_id': 'test.anoter_entity'}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
|
'Test for to action.'
| def test_if_action(self):
| entity_id = 'domain.test_entity'
test_state = 'new_state'
assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'event', 'event_type': 'test_event'}, 'condition': [{'condition': 'state', 'entity_id': entity_id, 'state': test_state}], 'action': {'service': 'test.automation'}}})
self.hass.states.set(entity_id, test_state)
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 + 'something'))
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
|
'Test for setup failure for boolean to.'
| def test_if_fails_setup_if_to_boolean_value(self):
| with assert_setup_component(0):
assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'state', 'entity_id': 'test.entity', 'to': True}, 'action': {'service': 'homeassistant.turn_on'}}})
|
'Test for setup failure for boolean from.'
| def test_if_fails_setup_if_from_boolean_value(self):
| with assert_setup_component(0):
assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'state', 'entity_id': 'test.entity', 'from': True}, 'action': {'service': 'homeassistant.turn_on'}}})
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.