desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Test that all data from the service gets forwarded to service.'
def test_method_forwards_correct_data(self):
self._setup_notify() notify.send_message(self.hass, 'my message', 'my title', {'hello': 'world'}) self.hass.block_till_done() self.assertTrue((len(self.events) == 1)) data = self.events[0].data assert ({'message': 'my message', 'title': 'my title', 'data': {'hello': 'world'}} == data...
'Test if we can call a notify from a script.'
def test_calling_notify_from_script_loaded_from_yaml_without_title(self):
self._setup_notify() conf = {'service': 'notify.notify', 'data': {'data': {'push': {'sound': 'US-EN-Morgan-Freeman-Roommate-Is-Arriving.wav'}}}, 'data_template': {'message': 'Test 123 {{ 2 + 2 }}\n'}} script.call_from_config(self.hass, conf) self.hass.block_till_done() self.assertT...
'Test if we can call a notify from a script.'
def test_calling_notify_from_script_loaded_from_yaml_with_title(self):
self._setup_notify() conf = {'service': 'notify.notify', 'data': {'data': {'push': {'sound': 'US-EN-Morgan-Freeman-Roommate-Is-Arriving.wav'}}}, 'data_template': {'message': 'Test 123 {{ 2 + 2 }}\n', 'title': 'Test'}} script.call_from_config(self.hass, conf) self.hass.block_till_done()...
'Test that all targets are exposed as individual services.'
def test_targets_are_services(self):
self._setup_notify() self.assertIsNotNone(self.hass.services.has_service('notify', 'demo')) service = 'demo_test_target_name' self.assertIsNotNone(self.hass.services.has_service('notify', service))
'Test message routing to specific target services.'
def test_messages_to_targets_route(self):
self._setup_notify() self.hass.bus.listen_once('notify', self.record_calls) self.hass.services.call('notify', 'demo_test_target_name', {'message': 'my message', 'title': 'my title', 'data': {'hello': 'world'}}) self.hass.block_till_done() data = self.calls[0][0].data assert ({'message': 'm...
'Setup things to be run when tests are started.'
def setUp(self):
self.hass = get_test_home_assistant()
'Stop down everything that was started.'
def tearDown(self):
self.hass.stop()
'Test setup.'
def test_setup(self):
with assert_setup_component(1) as handle_config: assert setup_component(self.hass, 'notify', {'notify': {'name': 'test', 'platform': 'command_line', 'command': 'echo $(cat); exit 1'}}) assert handle_config[notify.DOMAIN]
'Test set up the platform with bad/missing configuration.'
def test_bad_config(self):
config = {notify.DOMAIN: {'name': 'test', 'platform': 'command_line'}} with assert_setup_component(0) as handle_config: assert setup_component(self.hass, notify.DOMAIN, config) assert (not handle_config[notify.DOMAIN])
'Test the command line output.'
def test_command_line_output(self):
with tempfile.TemporaryDirectory() as tempdirname: filename = os.path.join(tempdirname, 'message.txt') message = 'one, two, testing, testing' with assert_setup_component(1) as handle_config: self.assertTrue(setup_component(self.hass, notify.DOMAIN, {'notify': {'name': 't...
'Test if an error is logged for non zero exit codes.'
@patch('homeassistant.components.notify.command_line._LOGGER.error') def test_error_for_none_zero_exit_code(self, mock_error):
with assert_setup_component(1) as handle_config: self.assertTrue(setup_component(self.hass, notify.DOMAIN, {'notify': {'name': 'test', 'platform': 'command_line', 'command': 'echo $(cat); exit 1'}})) assert handle_config[notify.DOMAIN] self.assertTrue(self.hass.services.call('notify', 'test...
'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()
'Test setup component with no devices.'
def test_setup_component_with_no_devices(self):
self.hass.data[dyson.DYSON_DEVICES] = [] add_devices = mock.MagicMock() dyson.setup_platform(self.hass, {}, add_devices) add_devices.assert_called_with([])
'Test setup component with devices.'
def test_setup_component(self):
def _add_device(devices): assert (len(devices) == 1) assert (devices[0].name == 'Device_Vacuum') device_vacuum = _get_vacuum_device_cleaning() device_non_vacuum = _get_non_vacuum_device() self.hass.data[dyson.DYSON_DEVICES] = [device_vacuum, device_non_vacuum] dyson.setup_platform(se...
'Test when message is received.'
def test_on_message(self):
device = _get_vacuum_device_cleaning() component = Dyson360EyeDevice(device) component.entity_id = 'entity_id' component.schedule_update_ha_state = mock.Mock() component.on_message(mock.Mock()) self.assertTrue(component.schedule_update_ha_state.called)
'Test polling is disable.'
def test_should_poll(self):
device = _get_vacuum_device_cleaning() component = Dyson360EyeDevice(device) self.assertFalse(component.should_poll)
'Test component properties.'
def test_properties(self):
device1 = _get_vacuum_device_cleaning() device2 = _get_vacuum_device_unknown_state() device3 = _get_vacuum_device_charging() component = Dyson360EyeDevice(device1) component2 = Dyson360EyeDevice(device2) component3 = Dyson360EyeDevice(device3) self.assertEqual(component.name, 'Device_Vacuum'...
'Test turn on vacuum.'
def test_turn_on(self):
device1 = _get_vacuum_device_charging() component1 = Dyson360EyeDevice(device1) component1.turn_on() self.assertTrue(device1.start.called) device2 = _get_vacuum_device_pause() component2 = Dyson360EyeDevice(device2) component2.turn_on() self.assertTrue(device2.resume.called)
'Test turn off vacuum.'
def test_turn_off(self):
device1 = _get_vacuum_device_cleaning() component1 = Dyson360EyeDevice(device1) component1.turn_off() self.assertTrue(device1.pause.called)
'Test stop vacuum.'
def test_stop(self):
device1 = _get_vacuum_device_cleaning() component1 = Dyson360EyeDevice(device1) component1.stop() self.assertTrue(device1.pause.called)
'Test set fan speed vacuum.'
def test_set_fan_speed(self):
device1 = _get_vacuum_device_cleaning() component1 = Dyson360EyeDevice(device1) component1.set_fan_speed('Max') device1.set_power_mode.assert_called_with(PowerMode.MAX)
'Test start/pause.'
def test_start_pause(self):
device1 = _get_vacuum_device_charging() component1 = Dyson360EyeDevice(device1) component1.start_pause() self.assertTrue(device1.start.called) device2 = _get_vacuum_device_pause() component2 = Dyson360EyeDevice(device2) component2.start_pause() self.assertTrue(device2.resume.called) ...
'Test return to base.'
def test_return_to_base(self):
device = _get_vacuum_device_pause() component = Dyson360EyeDevice(device) component.return_to_base() self.assertTrue(device.abort.called)
'Setup things to be run when tests are started.'
def setUp(self):
self.hass = get_test_home_assistant() self.assertTrue(setup_component(self.hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: 'demo'}}))
'Stop down everything that was started.'
def tearDown(self):
self.hass.stop()
'Test vacuum supported features.'
def test_supported_features(self):
state = self.hass.states.get(ENTITY_VACUUM_COMPLETE) self.assertEqual(2047, state.attributes.get(ATTR_SUPPORTED_FEATURES)) self.assertEqual('Charging', state.attributes.get(ATTR_STATUS)) self.assertEqual(100, state.attributes.get(ATTR_BATTERY_LEVEL)) self.assertEqual('medium', state.attributes.get(A...
'Test if methods call the services as expected.'
def test_methods(self):
self.hass.states.set(ENTITY_VACUUM_BASIC, STATE_ON) self.hass.block_till_done() self.assertTrue(vacuum.is_on(self.hass, ENTITY_VACUUM_BASIC)) self.hass.states.set(ENTITY_VACUUM_BASIC, STATE_OFF) self.hass.block_till_done() self.assertFalse(vacuum.is_on(self.hass, ENTITY_VACUUM_BASIC)) self.h...
'Test service calls for unsupported vacuums.'
def test_unsupported_methods(self):
self.hass.states.set(ENTITY_VACUUM_NONE, STATE_ON) self.hass.block_till_done() self.assertTrue(vacuum.is_on(self.hass, ENTITY_VACUUM_NONE)) vacuum.turn_off(self.hass, ENTITY_VACUUM_NONE) self.hass.block_till_done() self.assertTrue(vacuum.is_on(self.hass, ENTITY_VACUUM_NONE)) vacuum.stop(self...
'Test vacuum services.'
def test_services(self):
send_command_calls = mock_service(self.hass, DOMAIN, SERVICE_SEND_COMMAND) params = {'rotate': 150, 'speed': 20} vacuum.send_command(self.hass, 'test_command', entity_id=ENTITY_VACUUM_BASIC, params=params) self.hass.block_till_done() self.assertEqual(1, len(send_command_calls)) call = send_comma...
'Test vacuum service to set the fan speed.'
def test_set_fan_speed(self):
group_vacuums = ','.join([ENTITY_VACUUM_BASIC, ENTITY_VACUUM_COMPLETE]) old_state_basic = self.hass.states.get(ENTITY_VACUUM_BASIC) old_state_complete = self.hass.states.get(ENTITY_VACUUM_COMPLETE) vacuum.set_fan_speed(self.hass, FAN_SPEEDS[0], entity_id=group_vacuums) self.hass.block_till_done() ...
'Test vacuum service to send a command.'
def test_send_command(self):
group_vacuums = ','.join([ENTITY_VACUUM_BASIC, ENTITY_VACUUM_COMPLETE]) old_state_basic = self.hass.states.get(ENTITY_VACUUM_BASIC) old_state_complete = self.hass.states.get(ENTITY_VACUUM_COMPLETE) vacuum.send_command(self.hass, 'test_command', params={'p1': 3}, entity_id=group_vacuums) self.hass.bl...
'Setup things to be run when tests are started.'
def setUp(self):
self.hass = get_test_home_assistant() dt_util.set_default_time_zone(dt_util.get_time_zone('America/Regina'))
'Stop everything that was started.'
def tearDown(self):
dt_util.set_default_time_zone(dt_util.get_time_zone('UTC')) self.hass.stop()
'Test that we can create an event trigger on device.'
@patch('homeassistant.components.calendar.google.GoogleCalendarData') def test_all_day_event(self, mock_next_event):
week_from_today = (dt_util.dt.date.today() + dt_util.dt.timedelta(days=7)) event = {'summary': 'Test All Day Event', 'start': {'date': week_from_today.isoformat()}, 'end': {'date': (week_from_today + dt_util.dt.timedelta(days=1)).isoformat()}, 'location': 'Test Cases', 'description': "We're just ...
'Test that we can create an event trigger on device.'
@patch('homeassistant.components.calendar.google.GoogleCalendarData') def test_future_event(self, mock_next_event):
one_hour_from_now = (dt_util.now() + dt_util.dt.timedelta(minutes=30)) event = {'start': {'dateTime': one_hour_from_now.isoformat()}, 'end': {'dateTime': (one_hour_from_now + dt_util.dt.timedelta(minutes=60)).isoformat()}, 'summary': 'Test Event in 30 minutes', 'reminders': {'useDefault': True}, 'id...
'Test that we can create an event trigger on device.'
@patch('homeassistant.components.calendar.google.GoogleCalendarData') def test_in_progress_event(self, mock_next_event):
middle_of_event = (dt_util.now() - dt_util.dt.timedelta(minutes=30)) event = {'start': {'dateTime': middle_of_event.isoformat()}, 'end': {'dateTime': (middle_of_event + dt_util.dt.timedelta(minutes=60)).isoformat()}, 'summary': 'Test Event in Progress', 'reminders': {'useDefault': True}, 'id': 'aioehgn...
'Test that we can create an event trigger on device.'
@patch('homeassistant.components.calendar.google.GoogleCalendarData') def test_offset_in_progress_event(self, mock_next_event):
middle_of_event = (dt_util.now() + dt_util.dt.timedelta(minutes=14)) event_summary = 'Test Event in Progress' event = {'start': {'dateTime': middle_of_event.isoformat()}, 'end': {'dateTime': (middle_of_event + dt_util.dt.timedelta(minutes=60)).isoformat()}, 'summary': '{} !!-15'.format(event_sum...
'Test that we can create an event trigger on device.'
@pytest.mark.skip @patch('homeassistant.components.calendar.google.GoogleCalendarData') def test_all_day_offset_in_progress_event(self, mock_next_event):
tomorrow = (dt_util.dt.date.today() + dt_util.dt.timedelta(days=1)) event_summary = 'Test All Day Event Offset In Progress' event = {'summary': '{} !!-25:0'.format(event_summary), 'start': {'date': tomorrow.isoformat()}, 'end': {'date': (tomorrow + dt_util.dt.timedelta(days=1)).isoforma...
'Test that we can create an event trigger on device.'
@patch('homeassistant.components.calendar.google.GoogleCalendarData') def test_all_day_offset_event(self, mock_next_event):
tomorrow = (dt_util.dt.date.today() + dt_util.dt.timedelta(days=2)) offset_hours = (1 + dt_util.now().hour) event_summary = 'Test All Day Event Offset' event = {'summary': '{} !!-{}:0'.format(event_summary, offset_hours), 'start': {'date': tomorrow.isoformat()}, 'end': {'date': (tomorrow ...
'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 the controlling state via topic.'
def test_controlling_state_via_topic(self):
assert setup_component(self.hass, switch.DOMAIN, {switch.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'state_topic': 'state-topic', 'command_topic': 'command-topic', 'payload_on': 1, 'payload_off': 0}}) state = self.hass.states.get('switch.test') self.assertEqual(STATE_OFF, state.state) self.assertFalse...
'Test the sending MQTT commands in optimistic mode.'
def test_sending_mqtt_commands_and_optimistic(self):
assert setup_component(self.hass, switch.DOMAIN, {switch.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'command_topic': 'command-topic', 'payload_on': 'beer on', 'payload_off': 'beer off', 'qos': '2'}}) state = self.hass.states.get('switch.test') self.assertEqual(STATE_OFF, state.state) self.assert...
'Test the controlling state via topic and JSON message.'
def test_controlling_state_via_topic_and_json_message(self):
assert setup_component(self.hass, switch.DOMAIN, {switch.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'state_topic': 'state-topic', 'command_topic': 'command-topic', 'payload_on': 'beer on', 'payload_off': 'beer off', 'value_template': '{{ value_json.val }}'}}) state = self.hass.states.get('switch.t...
'Test the controlling state via topic.'
def test_controlling_availability(self):
assert setup_component(self.hass, switch.DOMAIN, {switch.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'state_topic': 'state-topic', 'command_topic': 'command-topic', 'availability_topic': 'availability_topic', 'payload_on': 1, 'payload_off': 0}}) state = self.hass.states.get('switch.test') self.assertEqual(...
'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 = {} def get_switch_name(number): return ('Mock Switch #' + str(number)) def on_switch_pressed(number, callback): self.switch_pressed_callbacks[number] ...
'Stop everything that was started.'
def teardown_method(self, method):
self.hass.stop()
'Return the switch state.'
def switch(self):
return self.hass.states.get(ENTITY_SWITCH)
'Return the other switch state.'
def other_switch(self):
return self.hass.states.get(ENTITY_OTHER_SWITCH)
'Test that switches are ignored by default.'
def test_include_switches_unspecified(self):
self.mock_lj.button_switches.assert_not_called() self.mock_lj.all_switches.assert_not_called()
'Test that switches can be explicitly ignored.'
def test_include_switches_False(self):
self.mock_lj.button_switches.assert_not_called() self.mock_lj.all_switches.assert_not_called()
'Test turning the switch on and off.'
def test_on_off(self):
assert (self.switch().state == 'off') assert (self.other_switch().state == 'off') assert (not switch.is_on(self.hass, ENTITY_SWITCH)) switch.turn_on(self.hass, ENTITY_SWITCH) self.hass.block_till_done() self.mock_lj.press_switch.assert_called_with(ENTITY_SWITCH_NUMBER) switch.turn_off(self.h...
'Test handling an event from LiteJet.'
def test_pressed_event(self):
_LOGGER.info(self.switch_pressed_callbacks[ENTITY_SWITCH_NUMBER]) self.switch_pressed_callbacks[ENTITY_SWITCH_NUMBER]() self.hass.block_till_done() assert switch.is_on(self.hass, ENTITY_SWITCH) assert (not switch.is_on(self.hass, ENTITY_OTHER_SWITCH)) assert (self.switch().state == 'on') ass...
'Test handling an event from LiteJet.'
def test_released_event(self):
self.switch_pressed_callbacks[ENTITY_OTHER_SWITCH_NUMBER]() self.hass.block_till_done() assert switch.is_on(self.hass, ENTITY_OTHER_SWITCH) self.switch_released_callbacks[ENTITY_OTHER_SWITCH_NUMBER]() self.hass.block_till_done() assert (not switch.is_on(self.hass, ENTITY_OTHER_SWITCH)) asser...
'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, 'switch', {'switch': {'platform': 'rfxtrx', 'automatic_add': True, 'devices': {'0b1100cd0213c7f210010f51': {'name': 'Test', rfxtrx_core.ATTR_FIREEVENT: True}}}}))
'Test configuration.'
def test_valid_config_int_device_id(self):
self.assertTrue(setup_component(self.hass, 'switch', {'switch': {'platform': 'rfxtrx', 'automatic_add': True, 'devices': {710000141010170: {'name': 'Test', rfxtrx_core.ATTR_FIREEVENT: True}}}}))
'Test invalid configuration.'
def test_invalid_config1(self):
self.assertFalse(setup_component(self.hass, 'switch', {'switch': {'platform': 'rfxtrx', 'automatic_add': True, 'devices': {'2FF7f216': {'name': 'Test', 'packetid': '0b1100cd0213c7f210010f51', 'signal_repetitions': 3}}}}))
'Test invalid configuration.'
def test_invalid_config2(self):
self.assertFalse(setup_component(self.hass, 'switch', {'switch': {'platform': 'rfxtrx', 'automatic_add': True, 'invalid_key': 'afda', 'devices': {'213c7f216': {'name': 'Test', 'packetid': '0b1100cd0213c7f210010f51', rfxtrx_core.ATTR_FIREEVENT: True}}}}))
'Test invalid configuration.'
def test_invalid_config3(self):
self.assertFalse(setup_component(self.hass, 'switch', {'switch': {'platform': 'rfxtrx', 'automatic_add': True, 'devices': {'213c7f216': {'name': 'Test', 'packetid': 'AA1100cd0213c7f210010f51', rfxtrx_core.ATTR_FIREEVENT: True}}}}))
'Test configuration.'
def test_invalid_config4(self):
self.assertFalse(setup_component(self.hass, 'switch', {'switch': {'platform': 'rfxtrx', 'automatic_add': True, 'devices': {'213c7f216': {'name': 'Test', rfxtrx_core.ATTR_FIREEVENT: True}}}}))
'Test with 0 switches.'
def test_default_config(self):
self.assertTrue(setup_component(self.hass, 'switch', {'switch': {'platform': 'rfxtrx', 'devices': {}}})) self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
'Test with 1 switch.'
def test_old_config(self):
self.assertTrue(setup_component(self.hass, 'switch', {'switch': {'platform': 'rfxtrx', 'devices': {'123efab1': {'name': 'Test', 'packetid': '0b1100cd0213c7f210010f51'}}}})) import RFXtrx as rfxtrxmod rfxtrx_core.RFXOBJECT = rfxtrxmod.Core('', transport_protocol=rfxtrxmod.DummyTransport) self.assertEqual...
'Test with 1 switch.'
def test_one_switch(self):
self.assertTrue(setup_component(self.hass, 'switch', {'switch': {'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_...
'Test with 3 switches.'
def test_several_switches(self):
self.assertTrue(setup_component(self.hass, 'switch', {'switch': {'platform': 'rfxtrx', 'signal_repetitions': 3, 'devices': {'0b1100cd0213c7f230010f71': {'name': 'Test'}, '0b1100100118cdea02010f70': {'name': 'Bath'}, '0b1100101118cdea02010f70': {'name': 'Living'}}}})) self.assertEqual(3, len(rfxtrx_core.RFX_DEVI...
'Test with discovery of switches.'
def test_discover_switch(self):
self.assertTrue(setup_component(self.hass, 'switch', {'switch': {'platform': 'rfxtrx', 'automatic_add': True, 'devices': {}}})) event = rfxtrx_core.get_rfx_object('0b1100100118cdea02010f70') event.data = bytearray([11, 17, 0, 16, 1, 24, 205, 234, 1, 1, 15, 112]) rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](e...
'Test with discovery of switch when auto add is False.'
def test_discover_switch_noautoadd(self):
self.assertTrue(setup_component(self.hass, 'switch', {'switch': {'platform': 'rfxtrx', 'automatic_add': False, 'devices': {}}})) event = rfxtrx_core.get_rfx_object('0b1100100118cdea02010f70') event.data = bytearray([11, 17, 0, 16, 1, 24, 205, 234, 1, 1, 15, 112]) rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](...
'Setup things to be run when tests are started.'
def setUp(self):
self.hass = get_test_home_assistant() platform = loader.get_component('switch.test') platform.init() (self.switch_1, self.switch_2, self.switch_3) = platform.DEVICES
'Stop everything that was started.'
def tearDown(self):
self.hass.stop()
'Test is_on, turn_on, turn_off methods.'
def test_methods(self):
self.assertTrue(setup_component(self.hass, switch.DOMAIN, {switch.DOMAIN: {CONF_PLATFORM: 'test'}})) self.assertTrue(switch.is_on(self.hass)) self.assertEqual(STATE_ON, self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state) self.assertTrue(switch.is_on(self.hass, self.switch_1.entity_id)) self.a...
'Test with bad configuration.'
def test_setup_two_platforms(self):
test_platform = loader.get_component('switch.test') test_platform.init(True) loader.set_component('switch.test2', test_platform) test_platform.init(False) self.assertTrue(setup_component(self.hass, switch.DOMAIN, {switch.DOMAIN: {CONF_PLATFORM: 'test'}, '{} 2'.format(switch.DOMAIN): {CONF_PLATFOR...
'Test if setup adds devices.'
@mock.patch('mficlient.client.MFiClient') @mock.patch('homeassistant.components.switch.mfi.MfiSwitch') def test_setup_adds_proper_devices(self, mock_switch, mock_client):
ports = {i: mock.MagicMock(model=model) for (i, model) in enumerate(mfi.SWITCH_MODELS)} ports['bad'] = mock.MagicMock(model='notaswitch') print ports['bad'].model mock_client.return_value.get_devices.return_value = [mock.MagicMock(ports=ports)] assert setup_component(self.hass, switch.DOMAIN, self.G...
'Setup things to be run when tests are started.'
def setup_method(self, method):
self.hass = get_test_home_assistant() self.port = mock.MagicMock() self.switch = mfi.MfiSwitch(self.port)
'Stop everything that was started.'
def teardown_method(self, method):
self.hass.stop()
'Test the name.'
def test_name(self):
self.assertEqual(self.port.label, self.switch.name)
'Test update.'
def test_update(self):
self.switch.update() self.assertEqual(self.port.refresh.call_count, 1) self.assertEqual(self.port.refresh.call_args, mock.call())
'Test update with target state.'
def test_update_with_target_state(self):
self.switch._target_state = True self.port.data = {} self.port.data['output'] = 'stale' self.switch.update() self.assertEqual(1.0, self.port.data['output']) self.assertEqual(None, self.switch._target_state) self.port.data['output'] = 'untouched' self.switch.update() self.assertEqual(...
'Test turn_on.'
def test_turn_on(self):
self.switch.turn_on() self.assertEqual(self.port.control.call_count, 1) self.assertEqual(self.port.control.call_args, mock.call(True)) self.assertTrue(self.switch._target_state)
'Test turn_off.'
def test_turn_off(self):
self.switch.turn_off() self.assertEqual(self.port.control.call_count, 1) self.assertEqual(self.port.control.call_args, mock.call(False)) self.assertFalse(self.switch._target_state)
'Test current power.'
def test_current_power_w(self):
self.port.data = {'active_pwr': 10} self.assertEqual(10, self.switch.current_power_w)
'Test current power if there is no data.'
def test_current_power_w_no_data(self):
self.port.data = {'notpower': 123} self.assertEqual(0, self.switch.current_power_w)
'Test the state attributes.'
def test_device_state_attributes(self):
self.port.data = {'v_rms': 1.25, 'i_rms': 2.75} self.assertEqual({'volts': 1.2, 'amps': 2.8}, self.switch.device_state_attributes)
'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()
'Test configuration.'
def test_valid_config(self):
assert setup_component(self.hass, 'switch', {'switch': {'platform': 'flux', 'name': 'flux', 'lights': ['light.desk', 'light.lamp']}})
'Test configuration.'
def test_valid_config_with_info(self):
assert setup_component(self.hass, 'switch', {'switch': {'platform': 'flux', 'name': 'flux', 'lights': ['light.desk', 'light.lamp'], 'stop_time': '22:59', 'start_time': '7:22', 'start_colortemp': '1000', 'sunset_colortemp': '2000', 'stop_colortemp': '4000'}})
'Test configuration.'
def test_valid_config_no_name(self):
with assert_setup_component(1, 'switch'): assert setup_component(self.hass, 'switch', {'switch': {'platform': 'flux', 'lights': ['light.desk', 'light.lamp']}})
'Test configuration.'
def test_invalid_config_no_lights(self):
with assert_setup_component(0, 'switch'): assert setup_component(self.hass, 'switch', {'switch': {'platform': 'flux', 'name': 'flux'}})
'Test the flux switch when it is off.'
def test_flux_when_switch_is_off(self):
platform = loader.get_component('light.test') platform.init() self.assertTrue(setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: 'test'}})) dev1 = platform.DEVICES[0] state = self.hass.states.get(dev1.entity_id) self.assertEqual(STATE_ON, state.state) self.assertIsNone(s...
'Test the flux switch before sunrise.'
def test_flux_before_sunrise(self):
platform = loader.get_component('light.test') platform.init() self.assertTrue(setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: 'test'}})) dev1 = platform.DEVICES[0] state = self.hass.states.get(dev1.entity_id) self.assertEqual(STATE_ON, state.state) self.assertIsNone(s...
'Test the flux switch after sunrise and before sunset.'
def test_flux_after_sunrise_before_sunset(self):
platform = loader.get_component('light.test') platform.init() self.assertTrue(setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: 'test'}})) dev1 = platform.DEVICES[0] state = self.hass.states.get(dev1.entity_id) self.assertEqual(STATE_ON, state.state) self.assertIsNone(s...
'Test the flux switch after sunset and before stop.'
def test_flux_after_sunset_before_stop(self):
platform = loader.get_component('light.test') platform.init() self.assertTrue(setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: 'test'}})) dev1 = platform.DEVICES[0] state = self.hass.states.get(dev1.entity_id) self.assertEqual(STATE_ON, state.state) self.assertIsNone(s...
'Test the flux switch after stop and before sunrise.'
def test_flux_after_stop_before_sunrise(self):
platform = loader.get_component('light.test') platform.init() self.assertTrue(setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: 'test'}})) dev1 = platform.DEVICES[0] state = self.hass.states.get(dev1.entity_id) self.assertEqual(STATE_ON, state.state) self.assertIsNone(s...
'Test the flux with custom start and stop times.'
def test_flux_with_custom_start_stop_times(self):
platform = loader.get_component('light.test') platform.init() self.assertTrue(setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: 'test'}})) dev1 = platform.DEVICES[0] state = self.hass.states.get(dev1.entity_id) self.assertEqual(STATE_ON, state.state) self.assertIsNone(s...
'Test the flux with custom start and stop colortemps.'
def test_flux_with_custom_colortemps(self):
platform = loader.get_component('light.test') platform.init() self.assertTrue(setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: 'test'}})) dev1 = platform.DEVICES[0] state = self.hass.states.get(dev1.entity_id) self.assertEqual(STATE_ON, state.state) self.assertIsNone(s...
'Test the flux with custom start and stop colortemps.'
def test_flux_with_custom_brightness(self):
platform = loader.get_component('light.test') platform.init() self.assertTrue(setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: 'test'}})) dev1 = platform.DEVICES[0] state = self.hass.states.get(dev1.entity_id) self.assertEqual(STATE_ON, state.state) self.assertIsNone(s...
'Test the flux switch with multiple light entities.'
def test_flux_with_multiple_lights(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 light.turn_on(self.hass, entity_id=dev2.entity_id) self.hass.block_till_done() light.turn_on(...
'Test the flux switchÂŽs mode mired.'
def test_flux_with_mired(self):
platform = loader.get_component('light.test') platform.init() self.assertTrue(setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: 'test'}})) dev1 = platform.DEVICES[0] state = self.hass.states.get(dev1.entity_id) self.assertEqual(STATE_ON, state.state) self.assertIsNone(s...