desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Test event listener.'
| @mock.patch('statsd.StatsClient')
def test_event_listener_attr_details(self, mock_client):
| config = {'statsd': {'host': 'host', 'log_attributes': True}}
config['statsd'][statsd.CONF_RATE] = statsd.DEFAULT_RATE
self.hass.bus.listen = mock.MagicMock()
setup_component(self.hass, statsd.DOMAIN, config)
self.assertTrue(self.hass.bus.listen.called)
handler_method = self.hass.bus.listen.call... |
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
self.hass.states.set('zone.home', 'zoning', {'name': 'home', 'latitude': 2.1, 'longitude': 1.1, 'radius': 10})
self.hass.states.set('zone.work', 'zoning', {'name': 'work', 'latitude': 2.3, 'longitude': 1.3, 'radius': 10})
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test a list of proximities.'
| def test_proximities(self):
| config = {'proximity': {'home': {'ignored_zones': ['work'], 'devices': ['device_tracker.test1', 'device_tracker.test2'], 'tolerance': '1'}, 'work': {'devices': ['device_tracker.test1'], 'tolerance': '1'}}}
self.assertTrue(setup_component(self.hass, DOMAIN, config))
proximities = ['home', 'work']
for pro... |
'Test a list of proximities with missing devices.'
| def test_proximities_setup(self):
| config = {'proximity': {'home': {'ignored_zones': ['work'], 'devices': ['device_tracker.test1', 'device_tracker.test2'], 'tolerance': '1'}, 'work': {'tolerance': '1'}}}
self.assertTrue(setup_component(self.hass, DOMAIN, config))
|
'Test the proximity.'
| def test_proximity(self):
| config = {'proximity': {'home': {'ignored_zones': ['work'], 'devices': ['device_tracker.test1', 'device_tracker.test2'], 'tolerance': '1'}}}
self.assertTrue(setup_component(self.hass, DOMAIN, config))
state = self.hass.states.get('proximity.home')
assert (state.state == 'not set')
assert (state.a... |
'Test for tracker in zone.'
| def test_device_tracker_test1_in_zone(self):
| config = {'proximity': {'home': {'ignored_zones': ['work'], 'devices': ['device_tracker.test1'], 'tolerance': '1'}}}
self.assertTrue(setup_component(self.hass, DOMAIN, config))
self.hass.states.set('device_tracker.test1', 'home', {'friendly_name': 'test1', 'latitude': 2.1, 'longitude': 1.1})
self.hass.b... |
'Test for trackers in zone.'
| def test_device_trackers_in_zone(self):
| config = {'proximity': {'home': {'ignored_zones': ['work'], 'devices': ['device_tracker.test1', 'device_tracker.test2'], 'tolerance': '1'}}}
self.assertTrue(setup_component(self.hass, DOMAIN, config))
self.hass.states.set('device_tracker.test1', 'home', {'friendly_name': 'test1', 'latitude': 2.1, 'longitude... |
'Test for tracker state away.'
| def test_device_tracker_test1_away(self):
| config = {'proximity': {'home': {'ignored_zones': ['work'], 'devices': ['device_tracker.test1'], 'tolerance': '1'}}}
self.assertTrue(setup_component(self.hass, DOMAIN, config))
self.hass.states.set('device_tracker.test1', 'not_home', {'friendly_name': 'test1', 'latitude': 20.1, 'longitude': 10.1})
self.... |
'Test for tracker state away further.'
| def test_device_tracker_test1_awayfurther(self):
| config = {'proximity': {'home': {'ignored_zones': ['work'], 'devices': ['device_tracker.test1'], 'tolerance': '1'}}}
self.assertTrue(setup_component(self.hass, DOMAIN, config))
self.hass.states.set('device_tracker.test1', 'not_home', {'friendly_name': 'test1', 'latitude': 20.1, 'longitude': 10.1})
self.... |
'Test for tracker state away closer.'
| def test_device_tracker_test1_awaycloser(self):
| config = {'proximity': {'home': {'ignored_zones': ['work'], 'devices': ['device_tracker.test1'], 'tolerance': '1'}}}
self.assertTrue(setup_component(self.hass, DOMAIN, config))
self.hass.states.set('device_tracker.test1', 'not_home', {'friendly_name': 'test1', 'latitude': 40.1, 'longitude': 20.1})
self.... |
'Test for tracker in ignored zone.'
| def test_all_device_trackers_in_ignored_zone(self):
| config = {'proximity': {'home': {'ignored_zones': ['work'], 'devices': ['device_tracker.test1'], 'tolerance': '1'}}}
self.assertTrue(setup_component(self.hass, DOMAIN, config))
self.hass.states.set('device_tracker.test1', 'work', {'friendly_name': 'test1'})
self.hass.block_till_done()
state = self.h... |
'Test for tracker with no coordinates.'
| def test_device_tracker_test1_no_coordinates(self):
| config = {'proximity': {'home': {'ignored_zones': ['work'], 'devices': ['device_tracker.test1'], 'tolerance': '1'}}}
self.assertTrue(setup_component(self.hass, DOMAIN, config))
self.hass.states.set('device_tracker.test1', 'not_home', {'friendly_name': 'test1'})
self.hass.block_till_done()
state = se... |
'Test for tracker ordering.'
| def test_device_tracker_test1_awayfurther_than_test2_first_test1(self):
| self.hass.states.set('device_tracker.test1', 'not_home', {'friendly_name': 'test1'})
self.hass.block_till_done()
self.hass.states.set('device_tracker.test2', 'not_home', {'friendly_name': 'test2'})
self.hass.block_till_done()
assert proximity.setup(self.hass, {'proximity': {'home': {'ignored_zones':... |
'Test for tracker ordering.'
| def test_device_tracker_test1_awayfurther_than_test2_first_test2(self):
| self.hass.states.set('device_tracker.test1', 'not_home', {'friendly_name': 'test1'})
self.hass.block_till_done()
self.hass.states.set('device_tracker.test2', 'not_home', {'friendly_name': 'test2'})
self.hass.block_till_done()
assert proximity.setup(self.hass, {'proximity': {'home': {'ignored_zones':... |
'Test for tracker states.'
| def test_device_tracker_test1_awayfurther_test2_in_ignored_zone(self):
| self.hass.states.set('device_tracker.test1', 'not_home', {'friendly_name': 'test1'})
self.hass.block_till_done()
self.hass.states.set('device_tracker.test2', 'work', {'friendly_name': 'test2'})
self.hass.block_till_done()
assert proximity.setup(self.hass, {'proximity': {'home': {'ignored_zones': ['w... |
'Test for tracker state.'
| def test_device_tracker_test1_awayfurther_test2_first(self):
| self.hass.states.set('device_tracker.test1', 'not_home', {'friendly_name': 'test1'})
self.hass.block_till_done()
self.hass.states.set('device_tracker.test2', 'not_home', {'friendly_name': 'test2'})
self.hass.block_till_done()
assert proximity.setup(self.hass, {'proximity': {'home': {'ignored_zones':... |
'Test for tracker states.'
| def test_device_tracker_test1_awayfurther_a_bit(self):
| assert proximity.setup(self.hass, {'proximity': {'home': {'ignored_zones': ['work'], 'devices': ['device_tracker.test1'], 'tolerance': 1000, 'zone': 'home'}}})
self.hass.states.set('device_tracker.test1', 'not_home', {'friendly_name': 'test1', 'latitude': 20.1000001, 'longitude': 10.1000001})
self.hass.bloc... |
'Test for tracker states.'
| def test_device_tracker_test1_nearest_after_test2_in_ignored_zone(self):
| self.hass.states.set('device_tracker.test1', 'not_home', {'friendly_name': 'test1'})
self.hass.block_till_done()
self.hass.states.set('device_tracker.test2', 'not_home', {'friendly_name': 'test2'})
self.hass.block_till_done()
assert proximity.setup(self.hass, {'proximity': {'home': {'ignored_zones':... |
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
self.mock_publish = mock_mqtt_component(self.hass)
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test if command fails with command topic.'
| def test_fail_setup_if_no_command_topic(self):
| with assert_setup_component(0, light.DOMAIN):
assert setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {'platform': 'mqtt', 'name': 'test'}})
self.assertIsNone(self.hass.states.get('light.test'))
|
'Test if there is no color and brightness if no topic.'
| def test_no_color_brightness_color_temp_white_xy_if_no_topics(self):
| with assert_setup_component(1, light.DOMAIN):
assert setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'state_topic': 'test_light_rgb/status', 'command_topic': 'test_light_rgb/set'}})
state = self.hass.states.get('light.test')
self.assertEqual(STATE_OFF, st... |
'Test the controlling of the state via topic.'
| def test_controlling_state_via_topic(self):
| config = {light.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'state_topic': 'test_light_rgb/status', 'command_topic': 'test_light_rgb/set', 'brightness_state_topic': 'test_light_rgb/brightness/status', 'brightness_command_topic': 'test_light_rgb/brightness/set', 'rgb_state_topic': 'test_light_rgb/rgb/status', 'rgb_... |
'Test the brightness controlling scale.'
| def test_brightness_controlling_scale(self):
| with assert_setup_component(1, light.DOMAIN):
assert setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'state_topic': 'test_scale/status', 'command_topic': 'test_scale/set', 'brightness_state_topic': 'test_scale/brightness/status', 'brightness_command_topic': 'test... |
'Test the white_value controlling scale.'
| def test_white_value_controlling_scale(self):
| with assert_setup_component(1, light.DOMAIN):
assert setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'state_topic': 'test_scale/status', 'command_topic': 'test_scale/set', 'white_value_state_topic': 'test_scale/white_value/status', 'white_value_command_topic': 't... |
'Test the setting og the state with a template.'
| def test_controlling_state_via_topic_with_templates(self):
| config = {light.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'state_topic': 'test_light_rgb/status', 'command_topic': 'test_light_rgb/set', 'brightness_state_topic': 'test_light_rgb/brightness/status', 'color_temp_state_topic': 'test_light_rgb/color_temp/status', 'effect_state_topic': 'test_light_rgb/effect/status'... |
'Test the sending of command in optimistic mode.'
| def test_sending_mqtt_commands_and_optimistic(self):
| config = {light.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'command_topic': 'test_light_rgb/set', 'brightness_command_topic': 'test_light_rgb/brightness/set', 'rgb_command_topic': 'test_light_rgb/rgb/set', 'color_temp_command_topic': 'test_light_rgb/color_temp/set', 'effect_command_topic': 'test_light_rgb/effect/... |
'Test the brightness if only a command topic is present.'
| def test_show_brightness_if_only_command_topic(self):
| config = {light.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'brightness_command_topic': 'test_light_rgb/brightness/set', 'command_topic': 'test_light_rgb/set', 'state_topic': 'test_light_rgb/status'}}
with assert_setup_component(1, light.DOMAIN):
assert setup_component(self.hass, light.DOMAIN, config)
... |
'Test the color temp only if a command topic is present.'
| def test_show_color_temp_only_if_command_topic(self):
| config = {light.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'color_temp_command_topic': 'test_light_rgb/brightness/set', 'command_topic': 'test_light_rgb/set', 'state_topic': 'test_light_rgb/status'}}
with assert_setup_component(1, light.DOMAIN):
assert setup_component(self.hass, light.DOMAIN, config)
... |
'Test the color temp only if a command topic is present.'
| def test_show_effect_only_if_command_topic(self):
| config = {light.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'effect_command_topic': 'test_light_rgb/effect/set', 'command_topic': 'test_light_rgb/set', 'state_topic': 'test_light_rgb/status'}}
with assert_setup_component(1, light.DOMAIN):
assert setup_component(self.hass, light.DOMAIN, config)
stat... |
'Test the white_value if only a command topic is present.'
| def test_show_white_value_if_only_command_topic(self):
| config = {light.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'white_value_command_topic': 'test_light_rgb/white_value/set', 'command_topic': 'test_light_rgb/set', 'state_topic': 'test_light_rgb/status'}}
with assert_setup_component(1, light.DOMAIN):
assert setup_component(self.hass, light.DOMAIN, config... |
'Test the xy if only a command topic is present.'
| def test_show_xy_if_only_command_topic(self):
| config = {light.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'xy_command_topic': 'test_light_rgb/xy/set', 'command_topic': 'test_light_rgb/set', 'state_topic': 'test_light_rgb/status'}}
with assert_setup_component(1, light.DOMAIN):
assert setup_component(self.hass, light.DOMAIN, config)
state = self... |
'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.load_activated_callbacks = {}
self.load_deactivated_callbacks = {}
def get_load_name(number):
return ('Mock Load #' + str(number))
def on_load_activated(number, callback):
self.load_activated_callbacks[number] = c... |
'Test for main light entity.'
| def light(self):
| return self.hass.states.get(ENTITY_LIGHT)
|
'Test the other light.'
| def other_light(self):
| return self.hass.states.get(ENTITY_OTHER_LIGHT)
|
'Stop everything that was started.'
| def teardown_method(self, method):
| self.hass.stop()
|
'Test turning the light on with brightness.'
| def test_on_brightness(self):
| assert (self.light().state == 'off')
assert (self.other_light().state == 'off')
assert (not light.is_on(self.hass, ENTITY_LIGHT))
light.turn_on(self.hass, ENTITY_LIGHT, brightness=102)
self.hass.block_till_done()
self.mock_lj.activate_load_at.assert_called_with(ENTITY_LIGHT_NUMBER, 39, 0)
|
'Test turning the light on and off.'
| def test_on_off(self):
| assert (self.light().state == 'off')
assert (self.other_light().state == 'off')
assert (not light.is_on(self.hass, ENTITY_LIGHT))
light.turn_on(self.hass, ENTITY_LIGHT)
self.hass.block_till_done()
self.mock_lj.activate_load.assert_called_with(ENTITY_LIGHT_NUMBER)
light.turn_off(self.hass, EN... |
'Test handling an event from LiteJet.'
| def test_activated_event(self):
| self.mock_lj.get_load_level.return_value = 99
_LOGGER.info(self.load_activated_callbacks[ENTITY_LIGHT_NUMBER])
self.load_activated_callbacks[ENTITY_LIGHT_NUMBER]()
self.hass.block_till_done()
self.mock_lj.get_load_level.assert_called_once_with(ENTITY_LIGHT_NUMBER)
assert light.is_on(self.hass, E... |
'Test handling an event from LiteJet.'
| def test_deactivated_event(self):
| self.mock_lj.get_load_level.return_value = 99
self.load_activated_callbacks[ENTITY_OTHER_LIGHT_NUMBER]()
self.hass.block_till_done()
assert light.is_on(self.hass, ENTITY_OTHER_LIGHT)
self.mock_lj.get_load_level.reset_mock()
self.mock_lj.get_load_level.return_value = 0
self.load_deactivated_c... |
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
mock_component(self.hass, 'rfxtrx')
|
'Stop everything that was started.'
| def tearDown(self):
| rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS = []
rfxtrx_core.RFX_DEVICES = {}
if rfxtrx_core.RFXOBJECT:
rfxtrx_core.RFXOBJECT.close_connection()
self.hass.stop()
|
'Test configuration.'
| def test_valid_config(self):
| self.assertTrue(setup_component(self.hass, 'light', {'light': {'platform': 'rfxtrx', 'automatic_add': True, 'devices': {'0b1100cd0213c7f210010f51': {'name': 'Test', rfxtrx_core.ATTR_FIREEVENT: True}}}}))
self.assertTrue(setup_component(self.hass, 'light', {'light': {'platform': 'rfxtrx', 'automatic_add': True, ... |
'Test configuration.'
| def test_invalid_config(self):
| self.assertFalse(setup_component(self.hass, 'light', {'light': {'platform': 'rfxtrx', 'automatic_add': True, 'invalid_key': 'afda', 'devices': {'213c7f216': {'name': 'Test', 'packetid': '0b1100cd0213c7f210010f51', rfxtrx_core.ATTR_FIREEVENT: True}}}}))
|
'Test with 0 switches.'
| def test_default_config(self):
| self.assertTrue(setup_component(self.hass, 'light', {'light': {'platform': 'rfxtrx', 'devices': {}}}))
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
'Test with 1 light.'
| def test_old_config(self):
| self.assertTrue(setup_component(self.hass, 'light', {'light': {'platform': 'rfxtrx', 'devices': {'123efab1': {'name': 'Test', 'packetid': '0b1100cd0213c7f210010f51'}}}}))
import RFXtrx as rfxtrxmod
rfxtrx_core.RFXOBJECT = rfxtrxmod.Core('', transport_protocol=rfxtrxmod.DummyTransport)
self.assertEqual(1... |
'Test with 1 light.'
| def test_one_light(self):
| self.assertTrue(setup_component(self.hass, 'light', {'light': {'platform': 'rfxtrx', 'devices': {'0b1100cd0213c7f210010f51': {'name': 'Test'}}}}))
import RFXtrx as rfxtrxmod
rfxtrx_core.RFXOBJECT = rfxtrxmod.Core('', transport_protocol=rfxtrxmod.DummyTransport)
self.assertEqual(1, len(rfxtrx_core.RFX_DE... |
'Test with 3 lights.'
| def test_several_lights(self):
| self.assertTrue(setup_component(self.hass, 'light', {'light': {'platform': 'rfxtrx', 'signal_repetitions': 3, 'devices': {'0b1100cd0213c7f230010f71': {'name': 'Test'}, '0b1100100118cdea02010f70': {'name': 'Bath'}, '0b1100101118cdea02010f70': {'name': 'Living'}}}}))
self.assertEqual(3, len(rfxtrx_core.RFX_DEVICE... |
'Test with discovery of lights.'
| def test_discover_light(self):
| self.assertTrue(setup_component(self.hass, 'light', {'light': {'platform': 'rfxtrx', 'automatic_add': True, 'devices': {}}}))
event = rfxtrx_core.get_rfx_object('0b11009e00e6116202020070')
event.data = bytearray('\x0b\x11\x00\x9e\x00\xe6\x11b\x02\x02\x00p')
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)... |
'Test with discover of light when auto add is False.'
| def test_discover_light_noautoadd(self):
| self.assertTrue(setup_component(self.hass, 'light', {'light': {'platform': 'rfxtrx', 'automatic_add': False, 'devices': {}}}))
event = rfxtrx_core.get_rfx_object('0b1100120118cdea02020070')
event.data = bytearray([11, 17, 0, 18, 1, 24, 205, 234, 2, 2, 0, 112])
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](eve... |
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
user_light_file = self.hass.config.path(light.LIGHT_PROFILES_FILE)
if os.path.isfile(user_light_file):
os.remove(user_light_file)
|
'Test if methods call the services as expected.'
| def test_methods(self):
| self.hass.states.set('light.test', STATE_ON)
self.assertTrue(light.is_on(self.hass, 'light.test'))
self.hass.states.set('light.test', STATE_OFF)
self.assertFalse(light.is_on(self.hass, 'light.test'))
self.hass.states.set(light.ENTITY_ID_ALL_LIGHTS, STATE_ON)
self.assertTrue(light.is_on(self.hass... |
'Test the provided services.'
| def test_services(self):
| platform = loader.get_component('light.test')
platform.init()
self.assertTrue(setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: 'test'}}))
(dev1, dev2, dev3) = platform.DEVICES
self.assertTrue(light.is_on(self.hass, dev1.entity_id))
self.assertFalse(light.is_on(self.hass, d... |
'Test light profiles.'
| def test_broken_light_profiles(self):
| platform = loader.get_component('light.test')
platform.init()
user_light_file = self.hass.config.path(light.LIGHT_PROFILES_FILE)
with open(user_light_file, 'w') as user_file:
user_file.write('id,x,y,brightness\n')
user_file.write('I,WILL,NOT,WORK\n')
self.assertFalse(setup_component(... |
'Test light profiles.'
| def test_light_profiles(self):
| platform = loader.get_component('light.test')
platform.init()
user_light_file = self.hass.config.path(light.LIGHT_PROFILES_FILE)
with open(user_light_file, 'w') as user_file:
user_file.write('id,x,y,brightness\n')
user_file.write('test,.4,.6,100\n')
self.assertTrue(setup_component(se... |
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
self.mock_publish = mock_mqtt_component(self.hass)
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test that setup fails with missing required configuration items.'
| def test_setup_fails(self):
| with assert_setup_component(0, light.DOMAIN):
assert setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {'platform': 'mqtt_template', 'name': 'test'}})
self.assertIsNone(self.hass.states.get('light.test'))
|
'Test state change via topic.'
| def test_state_change_via_topic(self):
| with assert_setup_component(1, light.DOMAIN):
assert setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {'platform': 'mqtt_template', 'name': 'test', 'state_topic': 'test_light_rgb', 'command_topic': 'test_light_rgb/set', 'command_on_template': 'on,{{ brightness|d }},{{ color_temp|d }},{{ ... |
'Test state, bri, color, effect, color temp, white val change.'
| def test_state_brightness_color_effect_temp_white_change_via_topic(self):
| with assert_setup_component(1, light.DOMAIN):
assert setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {'platform': 'mqtt_template', 'name': 'test', 'effect_list': ['rainbow', 'colorloop'], 'state_topic': 'test_light_rgb', 'command_topic': 'test_light_rgb/set', 'command_on_template': 'on,{{ brightn... |
'Test optimistic mode.'
| def test_optimistic(self):
| with assert_setup_component(1, light.DOMAIN):
assert setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {'platform': 'mqtt_template', 'name': 'test', 'command_topic': 'test_light_rgb/set', 'command_on_template': 'on,{{ brightness|d }},{{ color_temp|d }},{{ white_value|d }},{{ red|d... |
'Test flash.'
| def test_flash(self):
| with assert_setup_component(1, light.DOMAIN):
assert setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {'platform': 'mqtt_template', 'name': 'test', 'command_topic': 'test_light_rgb/set', 'command_on_template': 'on,{{ flash }}', 'command_off_template': 'off', 'qos': 0}})
state = self.hass.st... |
'Test for transition time being sent when included.'
| def test_transition(self):
| with assert_setup_component(1, light.DOMAIN):
assert setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {'platform': 'mqtt_template', 'name': 'test', 'command_topic': 'test_light_rgb/set', 'command_on_template': 'on,{{ transition }}', 'command_off_template': 'off,{{ transition|d }}'}})
... |
'Test that invalid values are ignored.'
| def test_invalid_values(self):
| with assert_setup_component(1, light.DOMAIN):
assert setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {'platform': 'mqtt_template', 'name': 'test', 'effect_list': ['rainbow', 'colorloop'], 'state_topic': 'test_light_rgb', 'command_topic': 'test_light_rgb/set', 'command_on_template': 'on,{{ brightn... |
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
self.mock_publish = mock_mqtt_component(self.hass)
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test if setup fails with no command topic.'
| def test_fail_setup_if_no_command_topic(self):
| with assert_setup_component(0, light.DOMAIN):
assert setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {'platform': 'mqtt_json', 'name': 'test'}})
self.assertIsNone(self.hass.states.get('light.test'))
|
'Test for no RGB, brightness, color temp, effect, white val or XY.'
| def test_no_color_brightness_color_temp_white_val_if_no_topics(self):
| assert setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {'platform': 'mqtt_json', 'name': 'test', 'state_topic': 'test_light_rgb', 'command_topic': 'test_light_rgb/set'}})
state = self.hass.states.get('light.test')
self.assertEqual(STATE_OFF, state.state)
self.assertEqual(40, state.attributes.get... |
'Test the controlling of the state via topic.'
| def test_controlling_state_via_topic(self):
| assert setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {'platform': 'mqtt_json', 'name': 'test', 'state_topic': 'test_light_rgb', 'command_topic': 'test_light_rgb/set', 'brightness': True, 'color_temp': True, 'effect': True, 'rgb': True, 'white_value': True, 'xy': True, 'qos': '0'}})
state = self.hass.s... |
'Test the sending of command in optimistic mode.'
| def test_sending_mqtt_commands_and_optimistic(self):
| assert setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {'platform': 'mqtt_json', 'name': 'test', 'command_topic': 'test_light_rgb/set', 'brightness': True, 'color_temp': True, 'effect': True, 'rgb': True, 'white_value': True, 'qos': 2}})
state = self.hass.states.get('light.test')
self.assertEqual(ST... |
'Test for flash length being sent when included.'
| def test_flash_short_and_long(self):
| assert setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {'platform': 'mqtt_json', 'name': 'test', 'state_topic': 'test_light_rgb', 'command_topic': 'test_light_rgb/set', 'flash_time_short': 5, 'flash_time_long': 15, 'qos': 0}})
state = self.hass.states.get('light.test')
self.assertEqual(STATE_OFF, st... |
'Test for transition time being sent when included.'
| def test_transition(self):
| assert setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {'platform': 'mqtt_json', 'name': 'test', 'state_topic': 'test_light_rgb', 'command_topic': 'test_light_rgb/set', 'qos': 0}})
state = self.hass.states.get('light.test')
self.assertEqual(STATE_OFF, state.state)
self.assertEqual(40, state.attr... |
'Test that invalid color/brightness/white values are ignored.'
| def test_invalid_color_brightness_and_white_values(self):
| assert setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {'platform': 'mqtt_json', 'name': 'test', 'state_topic': 'test_light_rgb', 'command_topic': 'test_light_rgb/set', 'brightness': True, 'rgb': True, 'white_value': True, 'qos': '0'}})
state = self.hass.states.get('light.test')
self.assertEqual(STA... |
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
|
'Stop everyhing that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test if setup adds devices.'
| @mock.patch('homeassistant.components.light.mochad.MochadLight')
def test_setup_adds_proper_devices(self, mock_light):
| good_config = {'mochad': {}, 'light': {'platform': 'mochad', 'devices': [{'name': 'Light1', 'address': 'a1'}]}}
self.assertTrue(setup_component(self.hass, light.DOMAIN, good_config))
|
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
controller_mock = mock.MagicMock()
dev_dict = {'address': 'a1', 'name': 'fake_light'}
self.light = mochad.MochadLight(self.hass, controller_mock, dev_dict)
|
'Stop everything that was started.'
| def teardown_method(self, method):
| self.hass.stop()
|
'Test the name.'
| def test_name(self):
| self.assertEqual('fake_light', self.light.name)
|
'Test turn_on.'
| def test_turn_on_with_no_brightness(self):
| self.light.turn_on()
self.light.device.send_cmd.assert_called_once_with('xdim 255')
|
'Test turn_on.'
| def test_turn_on_with_brightness(self):
| self.light.turn_on(brightness=45)
self.light.device.send_cmd.assert_called_once_with('xdim 45')
|
'Test turn_off.'
| def test_turn_off(self):
| self.light.turn_off()
self.light.device.send_cmd.assert_called_once_with('off')
|
'Initialize the mock zwave values.'
| def __init__(self, **kwargs):
| self.dimming_duration = None
self.color = None
self.color_channels = None
super().__init__(**kwargs)
|
'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 for firing if hour is matching.'
| def test_if_fires_when_hour_matches(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'time', 'hours': 0}, 'action': {'service': 'test.automation'}}})
fire_time_changed(self.hass, dt_util.utcnow().replace(hour=0))
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
automatio... |
'Test for firing if minutes are matching.'
| def test_if_fires_when_minute_matches(self):
| 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))
|
'Test for firing if seconds are matching.'
| def test_if_fires_when_second_matches(self):
| 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))
|
'Test for firing if everything matches.'
| def test_if_fires_when_all_matches(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'time', 'hours': 1, 'minutes': 2, 'seconds': 3}, 'action': {'service': 'test.automation'}}})
fire_time_changed(self.hass, dt_util.utcnow().replace(hour=1, minute=2, second=3))
self.hass.block_till_done()
se... |
'Test for firing periodically every second.'
| def test_if_fires_periodic_seconds(self):
| 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(s... |
'Test for firing periodically every minute.'
| def test_if_fires_periodic_minutes(self):
| 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(s... |
'Test for firing periodically every hour.'
| def test_if_fires_periodic_hours(self):
| 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(sel... |
'Test for firing at.'
| def test_if_fires_using_at(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'time', 'at': '5:00:00'}, 'action': {'service': 'test.automation', 'data_template': {'some': '{{ trigger.platform }} - {{ trigger.now.hour }}'}}}})
fire_time_changed(self.hass, dt_util.utcnow().re... |
'Test for failure if no configuration.'
| def test_if_not_working_if_no_values_in_conf_provided(self):
| with assert_setup_component(0):
assert 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()
se... |
'YAML translates time values to total seconds.
This should break the before rule.'
| def test_if_not_fires_using_wrong_at(self):
| with assert_setup_component(0):
assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'time', 'at': 3605}, 'action': {'service': 'test.automation'}}})
fire_time_changed(self.hass, dt_util.utcnow().replace(hour=1, minute=0, second=5))
self.hass.block_till_d... |
'Test for if action before.'
| def test_if_action_before(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'event', 'event_type': 'test_event'}, 'condition': {'condition': 'time', 'before': '10:00'}, 'action': {'service': 'test.automation'}}})
before_10 = dt_util.now().replace(hour=8)
after_10 = dt_util.now().replac... |
'Test for if action after.'
| def test_if_action_after(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'event', 'event_type': 'test_event'}, 'condition': {'condition': 'time', 'after': '10:00'}, 'action': {'service': 'test.automation'}}})
before_10 = dt_util.now().replace(hour=8)
after_10 = dt_util.now().replace... |
'Test for if action with one weekday.'
| def test_if_action_one_weekday(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'event', 'event_type': 'test_event'}, 'condition': {'condition': 'time', 'weekday': 'mon'}, 'action': {'service': 'test.automation'}}})
days_past_monday = dt_util.now().weekday()
monday = (dt_util.now() - timed... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.