desc
stringlengths 3
26.7k
| decl
stringlengths 11
7.89k
| bodies
stringlengths 8
553k
|
---|---|---|
'Test the flux switchÂŽs mode rgb.'
| def test_flux_with_rgb(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(state.attributes.get('color_temp'))
test_time = dt_util.now().replace(hour=8, minute=30, second=0)
sunset_time = test_time.replace(hour=17, minute=0, second=0)
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
def event_date(hass, event, now=None):
if (event == 'sunrise'):
return sunrise_time
else:
return sunset_time
with patch('homeassistant.util.dt.now', return_value=test_time):
with patch('homeassistant.helpers.sun.get_astral_event_date', side_effect=event_date):
assert setup_component(self.hass, switch.DOMAIN, {switch.DOMAIN: {'platform': 'flux', 'name': 'flux', 'lights': [dev1.entity_id], 'mode': 'rgb'}})
turn_on_calls = mock_service(self.hass, light.DOMAIN, SERVICE_TURN_ON)
switch.turn_on(self.hass, 'switch.flux')
self.hass.block_till_done()
fire_time_changed(self.hass, test_time)
self.hass.block_till_done()
call = turn_on_calls[(-1)]
rgb = (255, 198, 152)
rounded_call = tuple(map(round, call.data[light.ATTR_RGB_COLOR]))
self.assertEqual(rounded_call, rgb)
|
'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.switch.mochad.MochadSwitch')
def test_setup_adds_proper_devices(self, mock_switch):
| good_config = {'mochad': {}, 'switch': {'platform': 'mochad', 'devices': [{'name': 'Switch1', 'address': 'a1'}]}}
self.assertTrue(setup_component(self.hass, switch.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_switch'}
self.switch = mochad.MochadSwitch(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_switch', self.switch.name)
|
'Test turn_on.'
| def test_turn_on(self):
| self.switch.turn_on()
self.switch.device.send_cmd.assert_called_once_with('on')
|
'Test turn_off.'
| def test_turn_off(self):
| self.switch.turn_off()
self.switch.device.send_cmd.assert_called_once_with('off')
|
'Setup things to be run when tests are started.'
| def setup_method(self):
| self.hass = get_test_home_assistant()
|
'Stop everything that was started.'
| def teardown_method(self):
| self.hass.stop()
|
'Test setup with configuration missing required entries.'
| def test_setup_missing_config(self):
| assert (not run_coroutine_threadsafe(rest.async_setup_platform(self.hass, {'platform': 'rest'}, None), self.hass.loop).result())
|
'Test setup with resource missing schema.'
| def test_setup_missing_schema(self):
| assert (not run_coroutine_threadsafe(rest.async_setup_platform(self.hass, {'platform': 'rest', 'resource': 'localhost'}, None), self.hass.loop).result())
|
'Test setup when connection error occurs.'
| def test_setup_failed_connect(self, aioclient_mock):
| aioclient_mock.get('http://localhost', exc=aiohttp.ClientError)
assert (not run_coroutine_threadsafe(rest.async_setup_platform(self.hass, {'platform': 'rest', 'resource': 'http://localhost'}, None), self.hass.loop).result())
|
'Test setup when connection timeout occurs.'
| def test_setup_timeout(self, aioclient_mock):
| aioclient_mock.get('http://localhost', exc=asyncio.TimeoutError())
assert (not run_coroutine_threadsafe(rest.async_setup_platform(self.hass, {'platform': 'rest', 'resource': 'http://localhost'}, None), self.hass.loop).result())
|
'Test setup with minimum configuration.'
| def test_setup_minimum(self, aioclient_mock):
| aioclient_mock.get('http://localhost', status=200)
with assert_setup_component(1, 'switch'):
assert setup_component(self.hass, 'switch', {'switch': {'platform': 'rest', 'resource': 'http://localhost'}})
assert (aioclient_mock.call_count == 1)
|
'Test setup with valid configuration.'
| def test_setup(self, aioclient_mock):
| aioclient_mock.get('http://localhost', status=200)
assert setup_component(self.hass, 'switch', {'switch': {'platform': 'rest', 'name': 'foo', 'resource': 'http://localhost', 'body_on': 'custom on text', 'body_off': 'custom off text'}})
assert (aioclient_mock.call_count == 1)
assert_setup_component(1, 'switch')
|
'Setup things to be run when tests are started.'
| def setup_method(self):
| self.hass = get_test_home_assistant()
self.name = 'foo'
self.method = 'post'
self.resource = 'http://localhost/'
self.body_on = Template('on', self.hass)
self.body_off = Template('off', self.hass)
self.switch = rest.RestSwitch(self.hass, self.name, self.resource, self.method, self.body_on, self.body_off, None, 10)
|
'Stop everything that was started.'
| def teardown_method(self):
| self.hass.stop()
|
'Test the name.'
| def test_name(self):
| assert (self.name == self.switch.name)
|
'Test is_on in initial state.'
| def test_is_on_before_update(self):
| assert (self.switch.is_on is None)
|
'Test turn_on.'
| def test_turn_on_success(self, aioclient_mock):
| aioclient_mock.post(self.resource, status=200)
run_coroutine_threadsafe(self.switch.async_turn_on(), self.hass.loop).result()
assert (self.body_on.template == aioclient_mock.mock_calls[(-1)][2].decode())
assert self.switch.is_on
|
'Test turn_on when error status returned.'
| def test_turn_on_status_not_ok(self, aioclient_mock):
| aioclient_mock.post(self.resource, status=500)
run_coroutine_threadsafe(self.switch.async_turn_on(), self.hass.loop).result()
assert (self.body_on.template == aioclient_mock.mock_calls[(-1)][2].decode())
assert (self.switch.is_on is None)
|
'Test turn_on when timeout occurs.'
| def test_turn_on_timeout(self, aioclient_mock):
| aioclient_mock.post(self.resource, status=500)
run_coroutine_threadsafe(self.switch.async_turn_on(), self.hass.loop).result()
assert (self.switch.is_on is None)
|
'Test turn_off.'
| def test_turn_off_success(self, aioclient_mock):
| aioclient_mock.post(self.resource, status=200)
run_coroutine_threadsafe(self.switch.async_turn_off(), self.hass.loop).result()
assert (self.body_off.template == aioclient_mock.mock_calls[(-1)][2].decode())
assert (not self.switch.is_on)
|
'Test turn_off when error status returned.'
| def test_turn_off_status_not_ok(self, aioclient_mock):
| aioclient_mock.post(self.resource, status=500)
run_coroutine_threadsafe(self.switch.async_turn_off(), self.hass.loop).result()
assert (self.body_off.template == aioclient_mock.mock_calls[(-1)][2].decode())
assert (self.switch.is_on is None)
|
'Test turn_off when timeout occurs.'
| def test_turn_off_timeout(self, aioclient_mock):
| aioclient_mock.post(self.resource, exc=asyncio.TimeoutError())
run_coroutine_threadsafe(self.switch.async_turn_on(), self.hass.loop).result()
assert (self.switch.is_on is None)
|
'Test update when switch is on.'
| def test_update_when_on(self, aioclient_mock):
| aioclient_mock.get(self.resource, text=self.body_on.template)
run_coroutine_threadsafe(self.switch.async_update(), self.hass.loop).result()
assert self.switch.is_on
|
'Test update when switch is off.'
| def test_update_when_off(self, aioclient_mock):
| aioclient_mock.get(self.resource, text=self.body_off.template)
run_coroutine_threadsafe(self.switch.async_update(), self.hass.loop).result()
assert (not self.switch.is_on)
|
'Test update when unknown status returned.'
| def test_update_when_unknown(self, aioclient_mock):
| aioclient_mock.get(self.resource, text='unknown status')
run_coroutine_threadsafe(self.switch.async_update(), self.hass.loop).result()
assert (self.switch.is_on is None)
|
'Test update when timeout occurs.'
| def test_update_timeout(self, aioclient_mock):
| aioclient_mock.get(self.resource, exc=asyncio.TimeoutError())
run_coroutine_threadsafe(self.switch.async_update(), self.hass.loop).result()
assert (self.switch.is_on is None)
|
'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 with none state.'
| def test_state_none(self):
| with tempfile.TemporaryDirectory() as tempdirname:
path = os.path.join(tempdirname, 'switch_status')
test_switch = {'command_on': 'echo 1 > {}'.format(path), 'command_off': 'echo 0 > {}'.format(path)}
self.assertTrue(setup_component(self.hass, switch.DOMAIN, {'switch': {'platform': 'command_line', 'switches': {'test': test_switch}}}))
state = self.hass.states.get('switch.test')
self.assertEqual(STATE_OFF, state.state)
switch.turn_on(self.hass, 'switch.test')
self.hass.block_till_done()
state = self.hass.states.get('switch.test')
self.assertEqual(STATE_ON, state.state)
switch.turn_off(self.hass, 'switch.test')
self.hass.block_till_done()
state = self.hass.states.get('switch.test')
self.assertEqual(STATE_OFF, state.state)
|
'Test with state value.'
| def test_state_value(self):
| with tempfile.TemporaryDirectory() as tempdirname:
path = os.path.join(tempdirname, 'switch_status')
test_switch = {'command_state': 'cat {}'.format(path), 'command_on': 'echo 1 > {}'.format(path), 'command_off': 'echo 0 > {}'.format(path), 'value_template': '{{ value=="1" }}'}
self.assertTrue(setup_component(self.hass, switch.DOMAIN, {'switch': {'platform': 'command_line', 'switches': {'test': test_switch}}}))
state = self.hass.states.get('switch.test')
self.assertEqual(STATE_OFF, state.state)
switch.turn_on(self.hass, 'switch.test')
self.hass.block_till_done()
state = self.hass.states.get('switch.test')
self.assertEqual(STATE_ON, state.state)
switch.turn_off(self.hass, 'switch.test')
self.hass.block_till_done()
state = self.hass.states.get('switch.test')
self.assertEqual(STATE_OFF, state.state)
|
'Test with state JSON value.'
| def test_state_json_value(self):
| with tempfile.TemporaryDirectory() as tempdirname:
path = os.path.join(tempdirname, 'switch_status')
oncmd = json.dumps({'status': 'ok'})
offcmd = json.dumps({'status': 'nope'})
test_switch = {'command_state': 'cat {}'.format(path), 'command_on': "echo '{}' > {}".format(oncmd, path), 'command_off': "echo '{}' > {}".format(offcmd, path), 'value_template': '{{ value_json.status=="ok" }}'}
self.assertTrue(setup_component(self.hass, switch.DOMAIN, {'switch': {'platform': 'command_line', 'switches': {'test': test_switch}}}))
state = self.hass.states.get('switch.test')
self.assertEqual(STATE_OFF, state.state)
switch.turn_on(self.hass, 'switch.test')
self.hass.block_till_done()
state = self.hass.states.get('switch.test')
self.assertEqual(STATE_ON, state.state)
switch.turn_off(self.hass, 'switch.test')
self.hass.block_till_done()
state = self.hass.states.get('switch.test')
self.assertEqual(STATE_OFF, state.state)
|
'Test with state code.'
| def test_state_code(self):
| with tempfile.TemporaryDirectory() as tempdirname:
path = os.path.join(tempdirname, 'switch_status')
test_switch = {'command_state': 'cat {}'.format(path), 'command_on': 'echo 1 > {}'.format(path), 'command_off': 'echo 0 > {}'.format(path)}
self.assertTrue(setup_component(self.hass, switch.DOMAIN, {'switch': {'platform': 'command_line', 'switches': {'test': test_switch}}}))
state = self.hass.states.get('switch.test')
self.assertEqual(STATE_OFF, state.state)
switch.turn_on(self.hass, 'switch.test')
self.hass.block_till_done()
state = self.hass.states.get('switch.test')
self.assertEqual(STATE_ON, state.state)
switch.turn_off(self.hass, 'switch.test')
self.hass.block_till_done()
state = self.hass.states.get('switch.test')
self.assertEqual(STATE_ON, state.state)
|
'Test with state value.'
| def test_assumed_state_should_be_true_if_command_state_is_none(self):
| init_args = [self.hass, 'test_device_name', 'Test friendly name!', "echo 'on command'", "echo 'off command'", None, None]
no_state_device = command_line.CommandSwitch(*init_args)
self.assertTrue(no_state_device.assumed_state)
init_args[(-2)] = 'cat {}'
state_device = command_line.CommandSwitch(*init_args)
self.assertFalse(state_device.assumed_state)
|
'Test that entity_id is set correctly from object_id.'
| def test_entity_id_set_correctly(self):
| init_args = [self.hass, 'test_device_name', 'Test friendly name!', "echo 'on command'", "echo 'off command'", False, None]
test_switch = command_line.CommandSwitch(*init_args)
self.assertEqual(test_switch.entity_id, 'switch.test_device_name')
self.assertEqual(test_switch.name, 'Test friendly name!')
|
'Cleanup any data created from the tests.'
| def cleanup(self):
| if os.path.isfile(self.cache):
os.remove(self.cache)
|
'Initialize values for this test case class.'
| def setUp(self):
| self.hass = get_test_home_assistant()
self.cache = get_test_config_dir(ring.DEFAULT_CACHEDB)
self.config = VALID_CONFIG
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
self.cleanup()
|
'Test the setup.'
| @requests_mock.Mocker()
def test_setup(self, mock):
| mock.post('https://api.ring.com/clients_api/session', text=load_fixture('ring_session.json'))
response = ring.setup(self.hass, self.config)
self.assertTrue(response)
|
'Test the setup when no login is configured.'
| @requests_mock.Mocker()
def test_setup_component_no_login(self, mock):
| mock.post('https://api.ring.com/clients_api/session', text=load_fixture('ring_session.json'))
conf = self.config.copy()
del conf['ring']['username']
assert (not setup.setup_component(self.hass, ring.DOMAIN, conf))
|
'Test the setup when no password is configured.'
| @requests_mock.Mocker()
def test_setup_component_no_pwd(self, mock):
| mock.post('https://api.ring.com/clients_api/session', text=load_fixture('ring_session.json'))
conf = self.config.copy()
del conf['ring']['password']
assert (not setup.setup_component(self.hass, ring.DOMAIN, conf))
|
'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 down stuff we started.'
| def tearDown(self):
| self.hass.stop()
|
'Test for failing with no state topic.'
| def test_fail_setup_without_state_topic(self):
| 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])
|
'Test failing with no command topic.'
| def test_fail_setup_without_command_topic(self):
| with assert_setup_component(0):
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {alarm_control_panel.DOMAIN: {'platform': 'mqtt', 'state_topic': 'alarm/state'}})
|
'Test updating with via state topic.'
| def test_update_state_via_state_topic(self):
| 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'}})
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_UNKNOWN, self.hass.states.get(entity_id).state)
for state in (STATE_ALARM_DISARMED, STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_AWAY, STATE_ALARM_PENDING, STATE_ALARM_TRIGGERED):
fire_mqtt_message(self.hass, 'alarm/state', state)
self.hass.block_till_done()
self.assertEqual(state, self.hass.states.get(entity_id).state)
|
'Test ignoring updates via state topic.'
| def test_ignore_update_state_if_unknown_via_state_topic(self):
| 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'}})
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_UNKNOWN, self.hass.states.get(entity_id).state)
fire_mqtt_message(self.hass, 'alarm/state', 'unsupported state')
self.hass.block_till_done()
self.assertEqual(STATE_UNKNOWN, self.hass.states.get(entity_id).state)
|
'Test publishing of MQTT messages while armed.'
| def test_arm_home_publishes_mqtt(self):
| 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[(-2)][1])
|
'Test not publishing of MQTT messages with invalid code.'
| def test_arm_home_not_publishes_mqtt_with_invalid_code(self):
| 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)
|
'Test publishing of MQTT messages while armed.'
| def test_arm_away_publishes_mqtt(self):
| 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[(-2)][1])
|
'Test not publishing of MQTT messages with invalid code.'
| def test_arm_away_not_publishes_mqtt_with_invalid_code(self):
| 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)
|
'Test publishing of MQTT messages while disarmed.'
| def test_disarm_publishes_mqtt(self):
| 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[(-2)][1])
|
'Test not publishing of MQTT messages with invalid code.'
| def test_disarm_not_publishes_mqtt_with_invalid_code(self):
| 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)
|
'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 arm home method.'
| def test_arm_home_no_pending(self):
| self.assertTrue(setup_component(self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': {'platform': 'manual', 'name': 'test', 'code': CODE, 'pending_time': 0, 'disarm_after_trigger': False}}))
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_arm_home(self.hass, CODE)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_ARMED_HOME, self.hass.states.get(entity_id).state)
|
'Test arm home method.'
| def test_arm_home_with_pending(self):
| self.assertTrue(setup_component(self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': {'platform': 'manual', 'name': 'test', 'code': CODE, 'pending_time': 1, 'disarm_after_trigger': False}}))
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_arm_home(self.hass, CODE, entity_id)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_PENDING, self.hass.states.get(entity_id).state)
future = (dt_util.utcnow() + timedelta(seconds=1))
with patch('homeassistant.components.alarm_control_panel.manual.dt_util.utcnow', return_value=future):
fire_time_changed(self.hass, future)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_ARMED_HOME, self.hass.states.get(entity_id).state)
|
'Attempt to arm home without a valid code.'
| def test_arm_home_with_invalid_code(self):
| self.assertTrue(setup_component(self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': {'platform': 'manual', 'name': 'test', 'code': CODE, 'pending_time': 1, 'disarm_after_trigger': False}}))
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_arm_home(self.hass, (CODE + '2'))
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
|
'Test arm home method.'
| def test_arm_away_no_pending(self):
| self.assertTrue(setup_component(self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': {'platform': 'manual', 'name': 'test', 'code': CODE, 'pending_time': 0, 'disarm_after_trigger': False}}))
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_arm_away(self.hass, CODE, entity_id)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_ARMED_AWAY, self.hass.states.get(entity_id).state)
|
'Test arm home method.'
| def test_arm_away_with_pending(self):
| self.assertTrue(setup_component(self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': {'platform': 'manual', 'name': 'test', 'code': CODE, 'pending_time': 1, 'disarm_after_trigger': False}}))
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_arm_away(self.hass, CODE)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_PENDING, self.hass.states.get(entity_id).state)
future = (dt_util.utcnow() + timedelta(seconds=1))
with patch('homeassistant.components.alarm_control_panel.manual.dt_util.utcnow', return_value=future):
fire_time_changed(self.hass, future)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_ARMED_AWAY, self.hass.states.get(entity_id).state)
|
'Attempt to arm away without a valid code.'
| def test_arm_away_with_invalid_code(self):
| self.assertTrue(setup_component(self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': {'platform': 'manual', 'name': 'test', 'code': CODE, 'pending_time': 1, 'disarm_after_trigger': False}}))
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_arm_away(self.hass, (CODE + '2'))
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
|
'Test triggering when no pending submitted method.'
| def test_trigger_no_pending(self):
| self.assertTrue(setup_component(self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': {'platform': 'manual', 'name': 'test', 'trigger_time': 1, 'disarm_after_trigger': False}}))
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_trigger(self.hass, entity_id=entity_id)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_PENDING, self.hass.states.get(entity_id).state)
future = (dt_util.utcnow() + timedelta(seconds=60))
with patch('homeassistant.components.alarm_control_panel.manual.dt_util.utcnow', return_value=future):
fire_time_changed(self.hass, future)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_TRIGGERED, self.hass.states.get(entity_id).state)
|
'Test arm home method.'
| def test_trigger_with_pending(self):
| self.assertTrue(setup_component(self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': {'platform': 'manual', 'name': 'test', 'pending_time': 2, 'trigger_time': 3, 'disarm_after_trigger': False}}))
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_trigger(self.hass)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_PENDING, self.hass.states.get(entity_id).state)
future = (dt_util.utcnow() + timedelta(seconds=2))
with patch('homeassistant.components.alarm_control_panel.manual.dt_util.utcnow', return_value=future):
fire_time_changed(self.hass, future)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_TRIGGERED, self.hass.states.get(entity_id).state)
future = (dt_util.utcnow() + timedelta(seconds=5))
with patch('homeassistant.components.alarm_control_panel.manual.dt_util.utcnow', return_value=future):
fire_time_changed(self.hass, future)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
|
'Test disarm after trigger.'
| def test_trigger_with_disarm_after_trigger(self):
| self.assertTrue(setup_component(self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': {'platform': 'manual', 'name': 'test', 'trigger_time': 5, 'pending_time': 0, 'disarm_after_trigger': True}}))
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_trigger(self.hass, entity_id=entity_id)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_TRIGGERED, self.hass.states.get(entity_id).state)
future = (dt_util.utcnow() + timedelta(seconds=5))
with patch('homeassistant.components.alarm_control_panel.manual.dt_util.utcnow', return_value=future):
fire_time_changed(self.hass, future)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
|
'Test disarming while pending state.'
| def test_disarm_while_pending_trigger(self):
| self.assertTrue(setup_component(self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': {'platform': 'manual', 'name': 'test', 'trigger_time': 5, 'disarm_after_trigger': False}}))
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_trigger(self.hass)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_PENDING, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_disarm(self.hass, entity_id=entity_id)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
future = (dt_util.utcnow() + timedelta(seconds=5))
with patch('homeassistant.components.alarm_control_panel.manual.dt_util.utcnow', return_value=future):
fire_time_changed(self.hass, future)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
|
'Test disarming while code is invalid.'
| def test_disarm_during_trigger_with_invalid_code(self):
| self.assertTrue(setup_component(self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': {'platform': 'manual', 'name': 'test', 'pending_time': 5, 'code': (CODE + '2'), 'disarm_after_trigger': False}}))
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_trigger(self.hass)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_PENDING, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_disarm(self.hass, entity_id=entity_id)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_PENDING, self.hass.states.get(entity_id).state)
future = (dt_util.utcnow() + timedelta(seconds=5))
with patch('homeassistant.components.alarm_control_panel.manual.dt_util.utcnow', return_value=future):
fire_time_changed(self.hass, future)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_TRIGGERED, self.hass.states.get(entity_id).state)
|
'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 down everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test for failing with no state topic.'
| def test_fail_setup_without_state_topic(self):
| with assert_setup_component(0) as config:
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {alarm_control_panel.DOMAIN: {'platform': 'mqtt_alarm', 'command_topic': 'alarm/command'}})
assert (not config[alarm_control_panel.DOMAIN])
|
'Test failing with no command topic.'
| def test_fail_setup_without_command_topic(self):
| with assert_setup_component(0):
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {alarm_control_panel.DOMAIN: {'platform': 'mqtt_alarm', 'state_topic': 'alarm/state'}})
|
'Test arm home method.'
| def test_arm_home_no_pending(self):
| self.assertTrue(setup_component(self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': {'platform': 'manual_mqtt', 'name': 'test', 'code': CODE, 'pending_time': 0, 'disarm_after_trigger': False, 'command_topic': 'alarm/command', 'state_topic': 'alarm/state'}}))
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_arm_home(self.hass, CODE)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_ARMED_HOME, self.hass.states.get(entity_id).state)
|
'Test arm home method.'
| def test_arm_home_with_pending(self):
| self.assertTrue(setup_component(self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': {'platform': 'manual_mqtt', 'name': 'test', 'code': CODE, 'pending_time': 1, 'disarm_after_trigger': False, 'command_topic': 'alarm/command', 'state_topic': 'alarm/state'}}))
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_arm_home(self.hass, CODE, entity_id)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_PENDING, self.hass.states.get(entity_id).state)
future = (dt_util.utcnow() + timedelta(seconds=1))
with patch('homeassistant.components.alarm_control_panel.manual_mqtt.dt_util.utcnow', return_value=future):
fire_time_changed(self.hass, future)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_ARMED_HOME, self.hass.states.get(entity_id).state)
|
'Attempt to arm home without a valid code.'
| def test_arm_home_with_invalid_code(self):
| self.assertTrue(setup_component(self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': {'platform': 'manual_mqtt', 'name': 'test', 'code': CODE, 'pending_time': 1, 'disarm_after_trigger': False, 'command_topic': 'alarm/command', 'state_topic': 'alarm/state'}}))
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_arm_home(self.hass, (CODE + '2'))
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
|
'Test arm home method.'
| def test_arm_away_no_pending(self):
| self.assertTrue(setup_component(self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': {'platform': 'manual_mqtt', 'name': 'test', 'code': CODE, 'pending_time': 0, 'disarm_after_trigger': False, 'command_topic': 'alarm/command', 'state_topic': 'alarm/state'}}))
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_arm_away(self.hass, CODE, entity_id)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_ARMED_AWAY, self.hass.states.get(entity_id).state)
|
'Test arm home method.'
| def test_arm_away_with_pending(self):
| self.assertTrue(setup_component(self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': {'platform': 'manual_mqtt', 'name': 'test', 'code': CODE, 'pending_time': 1, 'disarm_after_trigger': False, 'command_topic': 'alarm/command', 'state_topic': 'alarm/state'}}))
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_arm_away(self.hass, CODE)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_PENDING, self.hass.states.get(entity_id).state)
future = (dt_util.utcnow() + timedelta(seconds=1))
with patch('homeassistant.components.alarm_control_panel.manual_mqtt.dt_util.utcnow', return_value=future):
fire_time_changed(self.hass, future)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_ARMED_AWAY, self.hass.states.get(entity_id).state)
|
'Attempt to arm away without a valid code.'
| def test_arm_away_with_invalid_code(self):
| self.assertTrue(setup_component(self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': {'platform': 'manual_mqtt', 'name': 'test', 'code': CODE, 'pending_time': 1, 'disarm_after_trigger': False, 'command_topic': 'alarm/command', 'state_topic': 'alarm/state'}}))
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_arm_away(self.hass, (CODE + '2'))
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
|
'Test triggering when no pending submitted method.'
| def test_trigger_no_pending(self):
| self.assertTrue(setup_component(self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': {'platform': 'manual_mqtt', 'name': 'test', 'trigger_time': 1, 'disarm_after_trigger': False, 'command_topic': 'alarm/command', 'state_topic': 'alarm/state'}}))
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_trigger(self.hass, entity_id=entity_id)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_PENDING, self.hass.states.get(entity_id).state)
future = (dt_util.utcnow() + timedelta(seconds=60))
with patch('homeassistant.components.alarm_control_panel.manual_mqtt.dt_util.utcnow', return_value=future):
fire_time_changed(self.hass, future)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_TRIGGERED, self.hass.states.get(entity_id).state)
|
'Test arm home method.'
| def test_trigger_with_pending(self):
| self.assertTrue(setup_component(self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': {'platform': 'manual_mqtt', 'name': 'test', 'pending_time': 2, 'trigger_time': 3, 'disarm_after_trigger': False, 'command_topic': 'alarm/command', 'state_topic': 'alarm/state'}}))
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_trigger(self.hass)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_PENDING, self.hass.states.get(entity_id).state)
future = (dt_util.utcnow() + timedelta(seconds=2))
with patch('homeassistant.components.alarm_control_panel.manual_mqtt.dt_util.utcnow', return_value=future):
fire_time_changed(self.hass, future)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_TRIGGERED, self.hass.states.get(entity_id).state)
future = (dt_util.utcnow() + timedelta(seconds=5))
with patch('homeassistant.components.alarm_control_panel.manual_mqtt.dt_util.utcnow', return_value=future):
fire_time_changed(self.hass, future)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
|
'Test disarm after trigger.'
| def test_trigger_with_disarm_after_trigger(self):
| self.assertTrue(setup_component(self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': {'platform': 'manual_mqtt', 'name': 'test', 'trigger_time': 5, 'pending_time': 0, 'disarm_after_trigger': True, 'command_topic': 'alarm/command', 'state_topic': 'alarm/state'}}))
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_trigger(self.hass, entity_id=entity_id)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_TRIGGERED, self.hass.states.get(entity_id).state)
future = (dt_util.utcnow() + timedelta(seconds=5))
with patch('homeassistant.components.alarm_control_panel.manual_mqtt.dt_util.utcnow', return_value=future):
fire_time_changed(self.hass, future)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
|
'Test disarming while pending state.'
| def test_disarm_while_pending_trigger(self):
| self.assertTrue(setup_component(self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': {'platform': 'manual_mqtt', 'name': 'test', 'trigger_time': 5, 'disarm_after_trigger': False, 'command_topic': 'alarm/command', 'state_topic': 'alarm/state'}}))
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_trigger(self.hass)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_PENDING, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_disarm(self.hass, entity_id=entity_id)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
future = (dt_util.utcnow() + timedelta(seconds=5))
with patch('homeassistant.components.alarm_control_panel.manual_mqtt.dt_util.utcnow', return_value=future):
fire_time_changed(self.hass, future)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
|
'Test disarming while code is invalid.'
| def test_disarm_during_trigger_with_invalid_code(self):
| self.assertTrue(setup_component(self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': {'platform': 'manual_mqtt', 'name': 'test', 'pending_time': 5, 'code': (CODE + '2'), 'disarm_after_trigger': False, 'command_topic': 'alarm/command', 'state_topic': 'alarm/state'}}))
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_trigger(self.hass)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_PENDING, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_disarm(self.hass, entity_id=entity_id)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_PENDING, self.hass.states.get(entity_id).state)
future = (dt_util.utcnow() + timedelta(seconds=5))
with patch('homeassistant.components.alarm_control_panel.manual_mqtt.dt_util.utcnow', return_value=future):
fire_time_changed(self.hass, future)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_TRIGGERED, self.hass.states.get(entity_id).state)
|
'Test arming home via command topic.'
| def test_arm_home_via_command_topic(self):
| assert setup_component(self.hass, alarm_control_panel.DOMAIN, {alarm_control_panel.DOMAIN: {'platform': 'manual_mqtt', 'name': 'test', 'pending_time': 1, 'state_topic': 'alarm/state', 'command_topic': 'alarm/command', 'payload_arm_home': 'ARM_HOME'}})
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
fire_mqtt_message(self.hass, 'alarm/command', 'ARM_HOME')
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_PENDING, self.hass.states.get(entity_id).state)
future = (dt_util.utcnow() + timedelta(seconds=1))
with patch('homeassistant.components.alarm_control_panel.manual_mqtt.dt_util.utcnow', return_value=future):
fire_time_changed(self.hass, future)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_ARMED_HOME, self.hass.states.get(entity_id).state)
|
'Test arming away via command topic.'
| def test_arm_away_via_command_topic(self):
| assert setup_component(self.hass, alarm_control_panel.DOMAIN, {alarm_control_panel.DOMAIN: {'platform': 'manual_mqtt', 'name': 'test', 'pending_time': 1, 'state_topic': 'alarm/state', 'command_topic': 'alarm/command', 'payload_arm_away': 'ARM_AWAY'}})
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
fire_mqtt_message(self.hass, 'alarm/command', 'ARM_AWAY')
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_PENDING, self.hass.states.get(entity_id).state)
future = (dt_util.utcnow() + timedelta(seconds=1))
with patch('homeassistant.components.alarm_control_panel.manual_mqtt.dt_util.utcnow', return_value=future):
fire_time_changed(self.hass, future)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_ARMED_AWAY, self.hass.states.get(entity_id).state)
|
'Test disarming pending alarm via command topic.'
| def test_disarm_pending_via_command_topic(self):
| assert setup_component(self.hass, alarm_control_panel.DOMAIN, {alarm_control_panel.DOMAIN: {'platform': 'manual_mqtt', 'name': 'test', 'pending_time': 1, 'state_topic': 'alarm/state', 'command_topic': 'alarm/command', 'payload_disarm': 'DISARM'}})
entity_id = 'alarm_control_panel.test'
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
alarm_control_panel.alarm_trigger(self.hass)
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_PENDING, self.hass.states.get(entity_id).state)
fire_mqtt_message(self.hass, 'alarm/command', 'DISARM')
self.hass.block_till_done()
self.assertEqual(STATE_ALARM_DISARMED, self.hass.states.get(entity_id).state)
|
'Test publishing of MQTT messages when state changes.'
| def test_state_changes_are_published_to_mqtt(self):
| assert setup_component(self.hass, alarm_control_panel.DOMAIN, {alarm_control_panel.DOMAIN: {'platform': 'manual_mqtt', 'name': 'test', 'pending_time': 1, 'trigger_time': 1, 'state_topic': 'alarm/state', 'command_topic': 'alarm/command'}})
self.hass.block_till_done()
self.assertEqual(('alarm/state', STATE_ALARM_DISARMED, 0, True), self.mock_publish.mock_calls[(-2)][1])
alarm_control_panel.alarm_arm_home(self.hass)
self.hass.block_till_done()
self.assertEqual(('alarm/state', STATE_ALARM_PENDING, 0, True), self.mock_publish.mock_calls[(-2)][1])
future = (dt_util.utcnow() + timedelta(seconds=1))
with patch('homeassistant.components.alarm_control_panel.manual_mqtt.dt_util.utcnow', return_value=future):
fire_time_changed(self.hass, future)
self.hass.block_till_done()
self.assertEqual(('alarm/state', STATE_ALARM_ARMED_HOME, 0, True), self.mock_publish.mock_calls[(-2)][1])
alarm_control_panel.alarm_arm_away(self.hass)
self.hass.block_till_done()
self.assertEqual(('alarm/state', STATE_ALARM_PENDING, 0, True), self.mock_publish.mock_calls[(-2)][1])
future = (dt_util.utcnow() + timedelta(seconds=1))
with patch('homeassistant.components.alarm_control_panel.manual_mqtt.dt_util.utcnow', return_value=future):
fire_time_changed(self.hass, future)
self.hass.block_till_done()
self.assertEqual(('alarm/state', STATE_ALARM_ARMED_AWAY, 0, True), self.mock_publish.mock_calls[(-2)][1])
alarm_control_panel.alarm_disarm(self.hass)
self.hass.block_till_done()
self.assertEqual(('alarm/state', STATE_ALARM_DISARMED, 0, True), self.mock_publish.mock_calls[(-2)][1])
|
'Setup things to be run when tests are started.'
| def setup_method(self):
| self.hass = get_test_home_assistant()
|
'Stop everything that was started.'
| def teardown_method(self):
| self.hass.stop()
|
'Setup demo platfrom on image_process component.'
| def test_setup_component(self):
| config = {ip.DOMAIN: {'platform': 'demo'}}
with assert_setup_component(1, ip.DOMAIN):
setup_component(self.hass, ip.DOMAIN, config)
|
'Setup demo platfrom on image_process component test service.'
| def test_setup_component_with_service(self):
| config = {ip.DOMAIN: {'platform': 'demo'}}
with assert_setup_component(1, ip.DOMAIN):
setup_component(self.hass, ip.DOMAIN, config)
assert self.hass.services.has_service(ip.DOMAIN, 'scan')
|
'Setup things to be run when tests are started.'
| def setup_method(self):
| self.hass = get_test_home_assistant()
setup_component(self.hass, http.DOMAIN, {http.DOMAIN: {http.CONF_SERVER_PORT: get_test_instance_port()}})
config = {ip.DOMAIN: {'platform': 'test'}, 'camera': {'platform': 'demo'}}
setup_component(self.hass, ip.DOMAIN, config)
state = self.hass.states.get('camera.demo_camera')
self.url = '{0}{1}'.format(self.hass.config.api.base_url, state.attributes.get(ATTR_ENTITY_PICTURE))
|
'Stop everything that was started.'
| def teardown_method(self):
| self.hass.stop()
|
'Grab a image from camera entity.'
| @patch('homeassistant.components.camera.demo.DemoCamera.camera_image', autospec=True, return_value='Test')
def test_get_image_from_camera(self, mock_camera):
| self.hass.start()
ip.scan(self.hass, entity_id='image_processing.test')
self.hass.block_till_done()
state = self.hass.states.get('image_processing.test')
assert mock_camera.called
assert (state.state == '1')
assert (state.attributes['image'] == 'Test')
|
'Try to get image without exists camera.'
| @patch('homeassistant.components.camera.async_get_image', side_effect=HomeAssistantError())
def test_get_image_without_exists_camera(self, mock_image):
| self.hass.states.remove('camera.demo_camera')
ip.scan(self.hass, entity_id='image_processing.test')
self.hass.block_till_done()
state = self.hass.states.get('image_processing.test')
assert mock_image.called
assert (state.state == '0')
|
'Setup things to be run when tests are started.'
| def setup_method(self):
| self.hass = get_test_home_assistant()
config = {ip.DOMAIN: {'platform': 'demo'}, 'camera': {'platform': 'demo'}}
with patch('homeassistant.components.image_processing.demo.DemoImageProcessingAlpr.should_poll', new_callable=PropertyMock(return_value=False)):
setup_component(self.hass, ip.DOMAIN, config)
state = self.hass.states.get('camera.demo_camera')
self.url = '{0}{1}'.format(self.hass.config.api.base_url, state.attributes.get(ATTR_ENTITY_PICTURE))
self.alpr_events = []
@callback
def mock_alpr_event(event):
'Mock event.'
self.alpr_events.append(event)
self.hass.bus.listen('image_processing.found_plate', mock_alpr_event)
|
'Stop everything that was started.'
| def teardown_method(self):
| self.hass.stop()
|
'Setup and scan a picture and test plates from event.'
| def test_alpr_event_single_call(self, aioclient_mock):
| aioclient_mock.get(self.url, content='image')
ip.scan(self.hass, entity_id='image_processing.demo_alpr')
self.hass.block_till_done()
state = self.hass.states.get('image_processing.demo_alpr')
assert (len(self.alpr_events) == 4)
assert (state.state == 'AC3829')
event_data = [event.data for event in self.alpr_events if (event.data.get('plate') == 'AC3829')]
assert (len(event_data) == 1)
assert (event_data[0]['plate'] == 'AC3829')
assert (event_data[0]['confidence'] == 98.3)
assert (event_data[0]['entity_id'] == 'image_processing.demo_alpr')
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.