Here are the examples of the python api homeassistant.bootstrap.setup_component taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
199 Examples
3
Example 1
Project: home-assistant Source File: test_template.py
def test_if_fires_on_change_with_bad_template(self):
"""Test for firing on change with bad template."""
with assert_setup_component(0):
assert not setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'template',
'value_template': '{{ ',
},
'action': {
'service': 'test.automation'
}
}
})
3
Example 2
Project: home-assistant Source File: test_command_line.py
def test_setup_bad_config(self):
"""Test the setup with a bad configuration."""
config = {'name': 'test',
'platform': 'not_command_line',
}
self.assertFalse(bootstrap.setup_component(self.hass, 'test', {
'command_line': config,
}))
3
Example 3
Project: home-assistant Source File: test_numeric_state.py
def test_if_not_fires_on_entity_change_not_below_with_attribute(self):
""""Test attributes."""
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
'entity_id': 'test.entity',
'below': 10,
},
'action': {
'service': 'test.automation'
}
}
})
# 11 is not below 10
self.hass.states.set('test.entity', 11, {'test_attribute': 9})
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
3
Example 4
Project: home-assistant Source File: test_state.py
def test_if_fails_setup_if_from_boolean_value(self):
"""Test for setup failure for boolean from."""
with assert_setup_component(0):
assert not setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'state',
'entity_id': 'test.entity',
'from': True,
},
'action': {
'service': 'homeassistant.turn_on',
}
}})
3
Example 5
Project: home-assistant Source File: test_numeric_state.py
def test_if_not_fires_on_entity_change_with_not_attribute_below(self):
""""Test attributes change."""
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'
}
}
})
# 11 is not below 10, entity state value should not be tested
self.hass.states.set('test.entity', 'entity')
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
3
Example 6
Project: home-assistant Source File: test_numeric_state.py
def test_if_fires_on_entity_change_below_range(self):
""""Test the firing with changed entity."""
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'
}
}
})
# 9 is below 10
self.hass.states.set('test.entity', 9)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
3
Example 7
Project: home-assistant Source File: test_time.py
def test_if_fires_periodic_seconds(self):
"""Test for firing periodically every second."""
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
'seconds': "/2",
},
'action': {
'service': 'test.automation'
}
}
})
fire_time_changed(self.hass, dt_util.utcnow().replace(
hour=0, minute=0, second=2))
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
3
Example 8
Project: home-assistant Source File: test_event.py
def test_if_fires_on_event_with_data(self):
"""Test the firing of events with data."""
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))
3
Example 9
def test_setup_platform_invalid_config(self):
"""Check the invalid configuration."""
with assert_setup_component(0):
assert setup_component(self.hass, 'binary_sensor', {
'binary_sensor': {
'platform': 'tcp',
'porrt': 1234,
}
})
3
Example 10
Project: home-assistant Source File: test_init.py
def test_service_data_not_a_dict(self):
"""Test service data not dict."""
with assert_setup_component(0):
assert not setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'event',
'event_type': 'test_event',
},
'action': {
'service': 'test.automation',
'data': 100,
}
}
})
3
Example 11
Project: home-assistant Source File: test_state.py
def test_if_not_fires_if_entity_not_match(self):
"""Test for not firing if entity is not matching."""
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))
3
Example 12
Project: home-assistant Source File: test_state.py
def test_if_fires_on_entity_change_with_to_filter(self):
"""Test for firing on entity change with no filter."""
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))
3
Example 13
Project: home-assistant Source File: test_mqtt.py
def test_if_not_fires_on_topic_but_no_payload_match(self):
"""Test if message is not fired on topic but no payload."""
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))
3
Example 14
Project: home-assistant Source File: test_state.py
def test_if_fails_setup_for_without_to(self):
"""Test for setup failures for missing to."""
with assert_setup_component(0):
assert not setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'state',
'entity_id': 'test.entity',
'for': {
'seconds': 5
},
},
'action': {
'service': 'homeassistant.turn_on',
}
}})
3
Example 15
Project: home-assistant Source File: test_mqtt.py
def test_disarm_publishes_mqtt(self):
"""Test publishing of MQTT messages while disarmed."""
self.hass.config.components = ['mqtt']
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {
alarm_control_panel.DOMAIN: {
'platform': 'mqtt',
'name': 'test',
'state_topic': 'alarm/state',
'command_topic': 'alarm/command',
}
})
alarm_control_panel.alarm_disarm(self.hass)
self.hass.block_till_done()
self.assertEqual(('alarm/command', 'DISARM', 0, False),
self.mock_publish.mock_calls[-1][1])
3
Example 16
Project: home-assistant Source File: test_time.py
def test_if_fires_when_minute_matches(self):
"""Test for firing if minutes are matching."""
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
'minutes': 0,
},
'action': {
'service': 'test.automation'
}
}
})
fire_time_changed(self.hass, dt_util.utcnow().replace(minute=0))
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
3
Example 17
Project: home-assistant Source File: test_numeric_state.py
def test_if_not_fires_if_entity_not_match(self):
""""Test if not fired with non matching entity."""
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))
3
Example 18
Project: home-assistant Source File: test_time.py
def test_if_fires_periodic_hours(self):
"""Test for firing periodically every hour."""
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
'hours': "/2",
},
'action': {
'service': 'test.automation'
}
}
})
fire_time_changed(self.hass, dt_util.utcnow().replace(
hour=2, minute=0, second=0))
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
3
Example 19
Project: home-assistant Source File: test_mqtt.py
def test_arm_home_publishes_mqtt(self):
"""Test publishing of MQTT messages while armed."""
self.hass.config.components = ['mqtt']
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {
alarm_control_panel.DOMAIN: {
'platform': 'mqtt',
'name': 'test',
'state_topic': 'alarm/state',
'command_topic': 'alarm/command',
}
})
alarm_control_panel.alarm_arm_home(self.hass)
self.hass.block_till_done()
self.assertEqual(('alarm/command', 'ARM_HOME', 0, False),
self.mock_publish.mock_calls[-1][1])
3
Example 20
Project: home-assistant Source File: test_mqtt.py
def test_invalid_sensor_class(self):
"""Test the setting of an invalid sensor class."""
self.hass.config.components = ['mqtt']
assert setup_component(self.hass, binary_sensor.DOMAIN, {
binary_sensor.DOMAIN: {
'platform': 'mqtt',
'name': 'test',
'sensor_class': 'abc123',
'state_topic': 'test-topic',
}
})
state = self.hass.states.get('binary_sensor.test')
self.assertIsNone(state.attributes.get('sensor_class'))
3
Example 21
Project: home-assistant Source File: test_numeric_state.py
def test_if_not_fires_on_attribute_change_with_attribute_not_below(self):
""""Test attributes change."""
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'
}
}
})
# 11 is not below 10
self.hass.states.set('test.entity', 'entity', {'test_attribute': 11})
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
3
Example 22
Project: home-assistant Source File: test_numeric_state.py
def test_if_not_fires_on_entity_change_with_attribute_below(self):
""""Test attributes change."""
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'
}
}
})
# 11 is not below 10, entity state value should not be tested
self.hass.states.set('test.entity', '9', {'test_attribute': 11})
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
3
Example 23
Project: home-assistant Source File: test_mqtt.py
def test_arm_home_not_publishes_mqtt_with_invalid_code(self):
"""Test not publishing of MQTT messages with invalid code."""
self.hass.config.components = ['mqtt']
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {
alarm_control_panel.DOMAIN: {
'platform': 'mqtt',
'name': 'test',
'state_topic': 'alarm/state',
'command_topic': 'alarm/command',
'code': '1234'
}
})
call_count = self.mock_publish.call_count
alarm_control_panel.alarm_arm_home(self.hass, 'abcd')
self.hass.block_till_done()
self.assertEqual(call_count, self.mock_publish.call_count)
3
Example 24
Project: home-assistant Source File: test_state.py
def test_if_fires_on_entity_change_with_from_filter(self):
"""Test for firing on entity change with filter."""
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))
3
Example 25
Project: home-assistant Source File: test_init.py
def test_service_initial_value_off(self):
"""Test initial value off."""
entity_id = 'automation.hello'
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'alias': 'hello',
'initial_state': 'off',
'trigger': {
'platform': 'event',
'event_type': 'test_event',
},
'action': {
'service': 'test.automation',
'entity_id': ['hello.world', 'hello.world2']
}
}
})
assert not automation.is_on(self.hass, entity_id)
3
Example 26
Project: home-assistant Source File: test_state.py
def test_if_not_fires_if_to_filter_not_match(self):
"""Test for not firing if to filter is not a match."""
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))
3
Example 27
Project: home-assistant Source File: test_state.py
def test_if_fires_on_entity_change_with_state_filter(self):
"""Test for firing on entity change with state filter."""
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'state',
'entity_id': 'test.entity',
'state': 'world'
},
'action': {
'service': 'test.automation'
}
}
})
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
3
Example 28
Project: home-assistant Source File: test_mqtt.py
def test_if_fires_on_topic_and_payload_match(self):
"""Test if message is fired on topic and payload match."""
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))
3
Example 29
Project: home-assistant Source File: test_state.py
def test_if_fails_setup_if_to_boolean_value(self):
"""Test for setup failure for boolean to."""
with assert_setup_component(0):
assert not setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'state',
'entity_id': 'test.entity',
'to': True,
},
'action': {
'service': 'homeassistant.turn_on',
}
}})
3
Example 30
Project: home-assistant Source File: test_mqtt.py
def test_arm_away_not_publishes_mqtt_with_invalid_code(self):
"""Test not publishing of MQTT messages with invalid code."""
self.hass.config.components = ['mqtt']
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {
alarm_control_panel.DOMAIN: {
'platform': 'mqtt',
'name': 'test',
'state_topic': 'alarm/state',
'command_topic': 'alarm/command',
'code': '1234'
}
})
call_count = self.mock_publish.call_count
alarm_control_panel.alarm_arm_away(self.hass, 'abcd')
self.hass.block_till_done()
self.assertEqual(call_count, self.mock_publish.call_count)
3
Example 31
Project: home-assistant Source File: test_state.py
def test_if_fails_setup_bad_for(self):
"""Test for setup failure for bad for."""
with assert_setup_component(0):
assert not setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'state',
'entity_id': 'test.entity',
'to': 'world',
'for': {
'invalid': 5
},
},
'action': {
'service': 'homeassistant.turn_on',
}
}})
3
Example 32
Project: home-assistant Source File: test_numeric_state.py
def test_if_fires_on_entity_change_above(self):
""""Test the firing with changed entity."""
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
'entity_id': 'test.entity',
'above': 10,
},
'action': {
'service': 'test.automation'
}
}
})
# 11 is above 10
self.hass.states.set('test.entity', 11)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
3
Example 33
Project: home-assistant Source File: test_template.py
def test_if_fires_on_change_with_template(self):
"""Test for firing on change with template."""
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))
3
Example 34
Project: home-assistant Source File: test_mqtt.py
def test_fail_setup_without_command_topic(self):
"""Test failing with no command topic."""
self.hass.config.components = ['mqtt']
with assert_setup_component(0):
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {
alarm_control_panel.DOMAIN: {
'platform': 'mqtt',
'state_topic': 'alarm/state'
}
})
3
Example 35
Project: home-assistant Source File: test_template.py
def test_if_fires_on_change_with_bad_template_2(self):
"""Test for firing on change with bad template."""
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))
3
Example 36
Project: home-assistant Source File: test_numeric_state.py
def test_if_fires_on_entity_change_below_above_range(self):
""""Test the firing with changed entity."""
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'
}
}
})
# 4 is below 5
self.hass.states.set('test.entity', 4)
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
3
Example 37
Project: home-assistant Source File: test_time.py
def test_if_fires_when_second_matches(self):
"""Test for firing if seconds are matching."""
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
'seconds': 0,
},
'action': {
'service': 'test.automation'
}
}
})
fire_time_changed(self.hass, dt_util.utcnow().replace(second=0))
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
3
Example 38
Project: home-assistant Source File: test_mqtt.py
def test_disarm_not_publishes_mqtt_with_invalid_code(self):
"""Test not publishing of MQTT messages with invalid code."""
self.hass.config.components = ['mqtt']
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {
alarm_control_panel.DOMAIN: {
'platform': 'mqtt',
'name': 'test',
'state_topic': 'alarm/state',
'command_topic': 'alarm/command',
'code': '1234'
}
})
call_count = self.mock_publish.call_count
alarm_control_panel.alarm_disarm(self.hass, 'abcd')
self.hass.block_till_done()
self.assertEqual(call_count, self.mock_publish.call_count)
3
Example 39
Project: home-assistant Source File: test_time.py
def test_if_fires_periodic_minutes(self):
"""Test for firing periodically every minute."""
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
'minutes': "/2",
},
'action': {
'service': 'test.automation'
}
}
})
fire_time_changed(self.hass, dt_util.utcnow().replace(
hour=0, minute=2, second=0))
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
3
Example 40
Project: home-assistant Source File: test_numeric_state.py
def test_if_fires_on_entity_change_below_with_attribute(self):
""""Test attributes change."""
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
'entity_id': 'test.entity',
'below': 10,
},
'action': {
'service': 'test.automation'
}
}
})
# 9 is below 10
self.hass.states.set('test.entity', 9, {'test_attribute': 11})
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
3
Example 41
Project: home-assistant Source File: test_time.py
def test_if_not_working_if_no_values_in_conf_provided(self):
"""Test for failure if no configuration."""
with assert_setup_component(0):
assert not setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
},
'action': {
'service': 'test.automation'
}
}
})
fire_time_changed(self.hass, dt_util.utcnow().replace(
hour=5, minute=0, second=0))
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
3
Example 42
Project: home-assistant Source File: common.py
def mock_mqtt_component(hass):
"""Mock the MQTT component."""
with mock.patch('homeassistant.components.mqtt.MQTT') as mock_mqtt:
setup_component(hass, mqtt.DOMAIN, {
mqtt.DOMAIN: {
mqtt.CONF_BROKER: 'mock-broker',
}
})
return mock_mqtt
3
Example 43
Project: home-assistant Source File: test_mqtt.py
def test_valid_sensor_class(self):
"""Test the setting of a valid sensor class."""
self.hass.config.components = ['mqtt']
assert setup_component(self.hass, binary_sensor.DOMAIN, {
binary_sensor.DOMAIN: {
'platform': 'mqtt',
'name': 'test',
'sensor_class': 'motion',
'state_topic': 'test-topic',
}
})
state = self.hass.states.get('binary_sensor.test')
self.assertEqual('motion', state.attributes.get('sensor_class'))
3
Example 44
Project: home-assistant Source File: test_numeric_state.py
def test_if_fires_on_attribute_change_with_attribute_below(self):
""""Test attributes change."""
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'
}
}
})
# 9 is below 10
self.hass.states.set('test.entity', 'entity', {'test_attribute': 9})
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
3
Example 45
Project: home-assistant Source File: test_event.py
def test_if_not_fires_if_event_data_not_matches(self):
"""Test firing of event if no match."""
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))
3
Example 46
def discover(hass, service, discovered=None, component=None, hass_config=None):
"""Fire discovery event. Can ensure a component is loaded."""
if component is not None:
bootstrap.setup_component(hass, component, hass_config)
data = {
ATTR_SERVICE: service
}
if discovered is not None:
data[ATTR_DISCOVERED] = discovered
hass.bus.fire(EVENT_PLATFORM_DISCOVERED, data)
3
Example 47
Project: home-assistant Source File: test_mqtt.py
def test_fail_setup_without_state_topic(self):
"""Test for failing with no state topic."""
self.hass.config.components = ['mqtt']
with assert_setup_component(0) as config:
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {
alarm_control_panel.DOMAIN: {
'platform': 'mqtt',
'command_topic': 'alarm/command'
}
})
assert not config[alarm_control_panel.DOMAIN]
3
Example 48
Project: home-assistant Source File: test_mqtt.py
def test_arm_away_publishes_mqtt(self):
"""Test publishing of MQTT messages while armed."""
self.hass.config.components = ['mqtt']
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {
alarm_control_panel.DOMAIN: {
'platform': 'mqtt',
'name': 'test',
'state_topic': 'alarm/state',
'command_topic': 'alarm/command',
}
})
alarm_control_panel.alarm_arm_away(self.hass)
self.hass.block_till_done()
self.assertEqual(('alarm/command', 'ARM_AWAY', 0, False),
self.mock_publish.mock_calls[-1][1])
3
Example 49
Project: home-assistant Source File: test_init.py
def test_service_initial_value_on(self):
"""Test initial value on."""
entity_id = 'automation.hello'
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'alias': 'hello',
'initial_state': 'on',
'trigger': {
'platform': 'event',
'event_type': 'test_event',
},
'action': {
'service': 'test.automation',
'entity_id': ['hello.world', 'hello.world2']
}
}
})
assert automation.is_on(self.hass, entity_id)
3
Example 50
Project: home-assistant Source File: test_state.py
def test_if_fires_on_entity_change_with_both_filters(self):
"""Test for firing if both filters are a non match."""
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))