desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Setup and scan a picture and test plates from event.'
def test_alpr_event_double_call(self, aioclient_mock):
aioclient_mock.get(self.url, content='image') ip.scan(self.hass, entity_id='image_processing.demo_alpr') 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) asser...
'Setup and scan a picture and test plates from event.'
@patch('homeassistant.components.image_processing.demo.DemoImageProcessingAlpr.confidence', new_callable=PropertyMock(return_value=95)) def test_alpr_event_single_call_confidence(self, confidence_mock, 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) == 2) assert (state.state == 'AC3829') event_data = [event.data for ev...
'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.DemoImageProcessingFace.should_poll', new_callable=PropertyMock(return_value=False)): setup_component(self.hass, ip.DOMAIN, conf...
'Stop everything that was started.'
def teardown_method(self):
self.hass.stop()
'Setup and scan a picture and test faces from event.'
def test_face_event_call(self, aioclient_mock):
aioclient_mock.get(self.url, content='image') ip.scan(self.hass, entity_id='image_processing.demo_face') self.hass.block_till_done() state = self.hass.states.get('image_processing.demo_face') assert (len(self.face_events) == 2) assert (state.state == 'Hans') assert (state.attributes['total_f...
'Setup and scan a picture and test faces from event.'
@patch('homeassistant.components.image_processing.demo.DemoImageProcessingFace.confidence', new_callable=PropertyMock(return_value=None)) def test_face_event_call_no_confidence(self, mock_confi, aioclient_mock):
aioclient_mock.get(self.url, content='image') ip.scan(self.hass, entity_id='image_processing.demo_face') self.hass.block_till_done() state = self.hass.states.get('image_processing.demo_face') assert (len(self.face_events) == 3) assert (state.state == '4') assert (state.attributes['total_face...
'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 platform with one entity.'
def test_setup_platform(self):
config = {ip.DOMAIN: {'platform': 'openalpr_cloud', 'source': {'entity_id': 'camera.demo_camera'}, 'region': 'eu', 'api_key': 'sk_abcxyz123456'}, 'camera': {'platform': 'demo'}} with assert_setup_component(1, ip.DOMAIN): setup_component(self.hass, ip.DOMAIN, config) assert self.hass.states.get('imag...
'Setup platform with one entity and set name.'
def test_setup_platform_name(self):
config = {ip.DOMAIN: {'platform': 'openalpr_cloud', 'source': {'entity_id': 'camera.demo_camera', 'name': 'test local'}, 'region': 'eu', 'api_key': 'sk_abcxyz123456'}, 'camera': {'platform': 'demo'}} with assert_setup_component(1, ip.DOMAIN): setup_component(self.hass, ip.DOMAIN, config) assert s...
'Setup platform with one entity without api_key.'
def test_setup_platform_without_api_key(self):
config = {ip.DOMAIN: {'platform': 'openalpr_cloud', 'source': {'entity_id': 'camera.demo_camera'}, 'region': 'eu'}, 'camera': {'platform': 'demo'}} with assert_setup_component(0, ip.DOMAIN): setup_component(self.hass, ip.DOMAIN, config)
'Setup platform with one entity without region.'
def test_setup_platform_without_region(self):
config = {ip.DOMAIN: {'platform': 'openalpr_cloud', 'source': {'entity_id': 'camera.demo_camera'}, 'api_key': 'sk_abcxyz123456'}, 'camera': {'platform': 'demo'}} with assert_setup_component(0, ip.DOMAIN): setup_component(self.hass, ip.DOMAIN, config)
'Setup things to be run when tests are started.'
def setup_method(self):
self.hass = get_test_home_assistant() config = {ip.DOMAIN: {'platform': 'openalpr_cloud', 'source': {'entity_id': 'camera.demo_camera', 'name': 'test local'}, 'region': 'eu', 'api_key': 'sk_abcxyz123456'}, 'camera': {'platform': 'demo'}} with patch('homeassistant.components.image_processing.openalpr_clou...
'Stop everything that was started.'
def teardown_method(self):
self.hass.stop()
'Setup and scan a picture and test plates from event.'
def test_openalpr_process_image(self, aioclient_mock):
aioclient_mock.get(self.url, content='image') aioclient_mock.post(OPENALPR_API_URL, params=self.params, text=load_fixture('alpr_cloud.json'), status=200) ip.scan(self.hass, entity_id='image_processing.test_local') self.hass.block_till_done() state = self.hass.states.get('image_processing.test_local'...
'Setup and scan a picture and test api error.'
def test_openalpr_process_image_api_error(self, aioclient_mock):
aioclient_mock.get(self.url, content='image') aioclient_mock.post(OPENALPR_API_URL, params=self.params, text="{'error': 'error message'}", status=400) ip.scan(self.hass, entity_id='image_processing.test_local') self.hass.block_till_done() assert (len(aioclient_mock.mock_calls) == 2) assert...
'Setup and scan a picture and test api error.'
def test_openalpr_process_image_api_timeout(self, aioclient_mock):
aioclient_mock.get(self.url, content='image') aioclient_mock.post(OPENALPR_API_URL, params=self.params, exc=asyncio.TimeoutError()) ip.scan(self.hass, entity_id='image_processing.test_local') self.hass.block_till_done() assert (len(aioclient_mock.mock_calls) == 2) assert (len(self.alpr_events) =...
'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 platform with one entity.'
@patch('homeassistant.components.microsoft_face.MicrosoftFace.update_store', return_value=mock_coro()) def test_setup_platform(self, store_mock):
config = {ip.DOMAIN: {'platform': 'microsoft_face_detect', 'source': {'entity_id': 'camera.demo_camera'}, 'attributes': ['age', 'gender']}, 'camera': {'platform': 'demo'}, mf.DOMAIN: {'api_key': '12345678abcdef6'}} with assert_setup_component(1, ip.DOMAIN): setup_component(self.hass, ip.DOMAIN, config) ...
'Setup platform with one entity and set name.'
@patch('homeassistant.components.microsoft_face.MicrosoftFace.update_store', return_value=mock_coro()) def test_setup_platform_name(self, store_mock):
config = {ip.DOMAIN: {'platform': 'microsoft_face_detect', 'source': {'entity_id': 'camera.demo_camera', 'name': 'test local'}}, 'camera': {'platform': 'demo'}, mf.DOMAIN: {'api_key': '12345678abcdef6'}} with assert_setup_component(1, ip.DOMAIN): setup_component(self.hass, ip.DOMAIN, config) asse...
'Setup things to be run when tests are started.'
def setup_method(self):
self.hass = get_test_home_assistant() self.config = {ip.DOMAIN: {'platform': 'microsoft_face_detect', 'source': {'entity_id': 'camera.demo_camera', 'name': 'test local'}, 'attributes': ['age', 'gender']}, 'camera': {'platform': 'demo'}, mf.DOMAIN: {'api_key': '12345678abcdef6'}} self.endpoint_url = 'http...
'Stop everything that was started.'
def teardown_method(self):
self.hass.stop()
'Setup and scan a picture and test plates from event.'
@patch('homeassistant.components.image_processing.microsoft_face_detect.MicrosoftFaceDetectEntity.should_poll', new_callable=PropertyMock(return_value=False)) def test_ms_detect_process_image(self, poll_mock, aioclient_mock):
aioclient_mock.get(self.endpoint_url.format('persongroups'), text=load_fixture('microsoft_face_persongroups.json')) aioclient_mock.get(self.endpoint_url.format('persongroups/test_group1/persons'), text=load_fixture('microsoft_face_persons.json')) aioclient_mock.get(self.endpoint_url.format('persongroups/tes...
'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 platform with one entity.'
def test_setup_platform(self):
config = {ip.DOMAIN: {'platform': 'openalpr_local', 'source': {'entity_id': 'camera.demo_camera'}, 'region': 'eu'}, 'camera': {'platform': 'demo'}} with assert_setup_component(1, ip.DOMAIN): setup_component(self.hass, ip.DOMAIN, config) assert self.hass.states.get('image_processing.openalpr_demo_cam...
'Setup platform with one entity and set name.'
def test_setup_platform_name(self):
config = {ip.DOMAIN: {'platform': 'openalpr_local', 'source': {'entity_id': 'camera.demo_camera', 'name': 'test local'}, 'region': 'eu'}, 'camera': {'platform': 'demo'}} with assert_setup_component(1, ip.DOMAIN): setup_component(self.hass, ip.DOMAIN, config) assert self.hass.states.get('image_pro...
'Setup platform with one entity without region.'
def test_setup_platform_without_region(self):
config = {ip.DOMAIN: {'platform': 'openalpr_local', 'source': {'entity_id': 'camera.demo_camera'}}, 'camera': {'platform': 'demo'}} with assert_setup_component(0, ip.DOMAIN): setup_component(self.hass, ip.DOMAIN, config)
'Setup things to be run when tests are started.'
def setup_method(self):
self.hass = get_test_home_assistant() config = {ip.DOMAIN: {'platform': 'openalpr_local', 'source': {'entity_id': 'camera.demo_camera', 'name': 'test local'}, 'region': 'eu'}, 'camera': {'platform': 'demo'}} with patch('homeassistant.components.image_processing.openalpr_local.OpenAlprLocalEntity.should_p...
'Stop everything that was started.'
def teardown_method(self):
self.hass.stop()
'Setup and scan a picture and test plates from event.'
@patch('asyncio.create_subprocess_exec', return_value=mock_async_subprocess()) def test_openalpr_process_image(self, popen_mock, aioclient_mock):
aioclient_mock.get(self.url, content='image') ip.scan(self.hass, entity_id='image_processing.test_local') self.hass.block_till_done() state = self.hass.states.get('image_processing.test_local') assert popen_mock.called assert (len(self.alpr_events) == 5) assert (state.attributes.get('vehicle...
'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 platform with one entity.'
@patch('homeassistant.components.microsoft_face.MicrosoftFace.update_store', return_value=mock_coro()) def test_setup_platform(self, store_mock):
config = {ip.DOMAIN: {'platform': 'microsoft_face_identify', 'source': {'entity_id': 'camera.demo_camera'}, 'group': 'Test Group1'}, 'camera': {'platform': 'demo'}, mf.DOMAIN: {'api_key': '12345678abcdef6'}} with assert_setup_component(1, ip.DOMAIN): setup_component(self.hass, ip.DOMAIN, config) ...
'Setup platform with one entity and set name.'
@patch('homeassistant.components.microsoft_face.MicrosoftFace.update_store', return_value=mock_coro()) def test_setup_platform_name(self, store_mock):
config = {ip.DOMAIN: {'platform': 'microsoft_face_identify', 'source': {'entity_id': 'camera.demo_camera', 'name': 'test local'}, 'group': 'Test Group1'}, 'camera': {'platform': 'demo'}, mf.DOMAIN: {'api_key': '12345678abcdef6'}} with assert_setup_component(1, ip.DOMAIN): setup_component(self.hass...
'Setup things to be run when tests are started.'
def setup_method(self):
self.hass = get_test_home_assistant() self.config = {ip.DOMAIN: {'platform': 'microsoft_face_identify', 'source': {'entity_id': 'camera.demo_camera', 'name': 'test local'}, 'group': 'Test Group1'}, 'camera': {'platform': 'demo'}, mf.DOMAIN: {'api_key': '12345678abcdef6'}} self.endpoint_url = 'https://...
'Stop everything that was started.'
def teardown_method(self):
self.hass.stop()
'Setup and scan a picture and test plates from event.'
@patch('homeassistant.components.image_processing.microsoft_face_identify.MicrosoftFaceIdentifyEntity.should_poll', new_callable=PropertyMock(return_value=False)) def test_ms_identify_process_image(self, poll_mock, aioclient_mock):
aioclient_mock.get(self.endpoint_url.format('persongroups'), text=load_fixture('microsoft_face_persongroups.json')) aioclient_mock.get(self.endpoint_url.format('persongroups/test_group1/persons'), text=load_fixture('microsoft_face_persons.json')) aioclient_mock.get(self.endpoint_url.format('persongroups/tes...
'Setup things to be run when tests are started.'
def setup_method(self, method):
self.hass = get_test_home_assistant() self.values = [17, 20, 15.2, 5, 3.8, 9.2, 6.7, 14, 6] self.count = len(self.values) self.min = min(self.values) self.max = max(self.values) self.total = sum(self.values) self.mean = round((sum(self.values) / len(self.values)), 2) self.median = round(...
'Stop everything that was started.'
def teardown_method(self, method):
self.hass.stop()
'Test if source is a sensor.'
def test_binary_sensor_source(self):
values = [1, 0, 1, 0, 1, 0, 1] assert setup_component(self.hass, 'sensor', {'sensor': {'platform': 'statistics', 'name': 'test', 'entity_id': 'binary_sensor.test_monitored'}}) for value in values: self.hass.states.set('binary_sensor.test_monitored', value) self.hass.block_till_done() sta...
'Test if source is a sensor.'
def test_sensor_source(self):
assert setup_component(self.hass, 'sensor', {'sensor': {'platform': 'statistics', 'name': 'test', 'entity_id': 'sensor.test_monitored'}}) for value in self.values: self.hass.states.set('sensor.test_monitored', value, {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}) self.hass.block_till_done() state...
'Test rotation.'
def test_sampling_size(self):
assert setup_component(self.hass, 'sensor', {'sensor': {'platform': 'statistics', 'name': 'test', 'entity_id': 'sensor.test_monitored', 'sampling_size': 5}}) for value in self.values: self.hass.states.set('sensor.test_monitored', value, {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}) self.hass.block_t...
'Set up 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 the history statistics sensor setup.'
def test_setup(self):
self.init_recorder() config = {'history': {}, 'sensor': {'platform': 'history_stats', 'entity_id': 'binary_sensor.test_id', 'state': 'on', 'start': '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}', 'duration': '02:00', 'name': 'Test'}} self.assertTrue(setup_component(self.hass, 'senso...
'Test the conversion from templates to period.'
def test_period_parsing(self):
today = Template('{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}', self.hass) duration = timedelta(hours=2, minutes=1) sensor1 = HistoryStatsSensor(self.hass, 'test', 'on', today, None, duration, 'time', 'test') sensor2 = HistoryStatsSensor(self.hass, 'test', 'on', None, today, du...
'Test the history statistics sensor measure.'
def test_measure(self):
t0 = (dt_util.utcnow() - timedelta(minutes=40)) t1 = (t0 + timedelta(minutes=20)) t2 = (dt_util.utcnow() - timedelta(minutes=10)) fake_states = {'binary_sensor.test_id': [ha.State('binary_sensor.test_id', 'on', last_changed=t0), ha.State('binary_sensor.test_id', 'off', last_changed=t1), ha.State('binary...
'Test when start or end value is not a timestamp or a date.'
def test_wrong_date(self):
good = Template('{{ now() }}', self.hass) bad = Template('{{ TEST }}', self.hass) sensor1 = HistoryStatsSensor(self.hass, 'test', 'on', good, bad, None, 'time', 'Test') sensor2 = HistoryStatsSensor(self.hass, 'test', 'on', bad, good, None, 'time', 'Test') before_update1 = sensor1._period...
'Test when duration value is not a timedelta.'
def test_wrong_duration(self):
self.init_recorder() config = {'history': {}, 'sensor': {'platform': 'history_stats', 'entity_id': 'binary_sensor.test_id', 'name': 'Test', 'state': 'on', 'start': '{{ now() }}', 'duration': 'TEST'}} setup_component(self.hass, 'sensor', config) self.assertEqual(self.hass.states.get('sensor.test'),...
'Test Exception when the template cannot be parsed.'
def test_bad_template(self):
bad = Template('{{ x - 12 }}', self.hass) duration = '01:00' sensor1 = HistoryStatsSensor(self.hass, 'test', 'on', bad, None, duration, 'time', 'Test') sensor2 = HistoryStatsSensor(self.hass, 'test', 'on', None, bad, duration, 'time', 'Test') before_update1 = sensor1._period before_u...
'Test config when not enough arguments provided.'
def test_not_enough_arguments(self):
self.init_recorder() config = {'history': {}, 'sensor': {'platform': 'history_stats', 'entity_id': 'binary_sensor.test_id', 'name': 'Test', 'state': 'on', 'start': '{{ now() }}'}} setup_component(self.hass, 'sensor', config) self.assertEqual(self.hass.states.get('sensor.test'), None) self.asse...
'Test config when too many arguments provided.'
def test_too_many_arguments(self):
self.init_recorder() config = {'history': {}, 'sensor': {'platform': 'history_stats', 'entity_id': 'binary_sensor.test_id', 'name': 'Test', 'state': 'on', 'start': '{{ as_timestamp(now()) - 3600 }}', 'end': '{{ now() }}', 'duration': '01:00'}} setup_component(self.hass, 'sensor', config) ...
'Initialize the recorder.'
def init_recorder(self):
init_recorder_component(self.hass) self.hass.start()
'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, None, add_devices) add_devices.assert_called_with([])
'Test setup component with devices.'
def test_setup_component(self):
def _add_device(devices): assert (len(devices) == 5) assert (devices[0].name == 'Device_name filter life') assert (devices[1].name == 'Device_name dust') assert (devices[2].name == 'Device_name humidity') assert (devices[3].name == 'Device_name temperature') ...
'Test filter life sensor with no value.'
def test_dyson_filter_life_sensor(self):
sensor = dyson.DysonFilterLifeSensor(self.hass, _get_device_without_state()) sensor.entity_id = 'sensor.dyson_1' self.assertFalse(sensor.should_poll) self.assertIsNone(sensor.state) self.assertEqual(sensor.unit_of_measurement, 'hours') self.assertEqual(sensor.name, 'Device_name filter life...
'Test filter sensor with values.'
def test_dyson_filter_life_sensor_with_values(self):
sensor = dyson.DysonFilterLifeSensor(self.hass, _get_with_state()) sensor.entity_id = 'sensor.dyson_1' self.assertFalse(sensor.should_poll) self.assertEqual(sensor.state, 100) self.assertEqual(sensor.unit_of_measurement, 'hours') self.assertEqual(sensor.name, 'Device_name filter life') ...
'Test dust sensor with no value.'
def test_dyson_dust_sensor(self):
sensor = dyson.DysonDustSensor(self.hass, _get_device_without_state()) sensor.entity_id = 'sensor.dyson_1' self.assertFalse(sensor.should_poll) self.assertIsNone(sensor.state) self.assertEqual(sensor.unit_of_measurement, 'level') self.assertEqual(sensor.name, 'Device_name dust') self.asse...
'Test dust sensor with values.'
def test_dyson_dust_sensor_with_values(self):
sensor = dyson.DysonDustSensor(self.hass, _get_with_state()) sensor.entity_id = 'sensor.dyson_1' self.assertFalse(sensor.should_poll) self.assertEqual(sensor.state, 5) self.assertEqual(sensor.unit_of_measurement, 'level') self.assertEqual(sensor.name, 'Device_name dust') self.assertEqual(...
'Test humidity sensor with no value.'
def test_dyson_humidity_sensor(self):
sensor = dyson.DysonHumiditySensor(self.hass, _get_device_without_state()) sensor.entity_id = 'sensor.dyson_1' self.assertFalse(sensor.should_poll) self.assertIsNone(sensor.state) self.assertEqual(sensor.unit_of_measurement, '%') self.assertEqual(sensor.name, 'Device_name humidity') self....
'Test humidity sensor with values.'
def test_dyson_humidity_sensor_with_values(self):
sensor = dyson.DysonHumiditySensor(self.hass, _get_with_state()) sensor.entity_id = 'sensor.dyson_1' self.assertFalse(sensor.should_poll) self.assertEqual(sensor.state, 45) self.assertEqual(sensor.unit_of_measurement, '%') self.assertEqual(sensor.name, 'Device_name humidity') self.assertE...
'Test humidity sensor while device is in standby monitoring.'
def test_dyson_humidity_standby_monitoring(self):
sensor = dyson.DysonHumiditySensor(self.hass, _get_with_standby_monitoring()) sensor.entity_id = 'sensor.dyson_1' self.assertFalse(sensor.should_poll) self.assertEqual(sensor.state, STATE_OFF) self.assertEqual(sensor.unit_of_measurement, '%') self.assertEqual(sensor.name, 'Device_name humidit...
'Test temperature sensor with no value.'
def test_dyson_temperature_sensor(self):
sensor = dyson.DysonTemperatureSensor(self.hass, _get_device_without_state(), TEMP_CELSIUS) sensor.entity_id = 'sensor.dyson_1' self.assertFalse(sensor.should_poll) self.assertIsNone(sensor.state) self.assertEqual(sensor.unit_of_measurement, '\xc2\xb0C') self.assertEqual(sensor.name, 'Device_nam...
'Test temperature sensor with values.'
def test_dyson_temperature_sensor_with_values(self):
sensor = dyson.DysonTemperatureSensor(self.hass, _get_with_state(), TEMP_CELSIUS) sensor.entity_id = 'sensor.dyson_1' self.assertFalse(sensor.should_poll) self.assertEqual(sensor.state, 21.9) self.assertEqual(sensor.unit_of_measurement, '\xc2\xb0C') self.assertEqual(sensor.name, 'Device_name ...
'Test temperature sensor while device is in standby monitoring.'
def test_dyson_temperature_standby_monitoring(self):
sensor = dyson.DysonTemperatureSensor(self.hass, _get_with_standby_monitoring(), TEMP_CELSIUS) sensor.entity_id = 'sensor.dyson_1' self.assertFalse(sensor.should_poll) self.assertEqual(sensor.state, STATE_OFF) self.assertEqual(sensor.unit_of_measurement, '\xc2\xb0C') self.assertEqual(sensor.name...
'Test air quality sensor with no value.'
def test_dyson_air_quality_sensor(self):
sensor = dyson.DysonAirQualitySensor(self.hass, _get_device_without_state()) sensor.entity_id = 'sensor.dyson_1' self.assertFalse(sensor.should_poll) self.assertIsNone(sensor.state) self.assertEqual(sensor.unit_of_measurement, 'level') self.assertEqual(sensor.name, 'Device_name air quality...
'Test air quality sensor with values.'
def test_dyson_air_quality_sensor_with_values(self):
sensor = dyson.DysonAirQualitySensor(self.hass, _get_with_state()) sensor.entity_id = 'sensor.dyson_1' self.assertFalse(sensor.should_poll) self.assertEqual(sensor.state, 2) self.assertEqual(sensor.unit_of_measurement, 'level') self.assertEqual(sensor.name, 'Device_name air quality') s...
'Setup things to be run when tests are started.'
def setUp(self):
self.hass = get_test_home_assistant() self.hass.states.set('test.indoortemp', '20', {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}) self.hass.states.set('test.outdoortemp', '10', {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}) self.hass.states.set('test.indoorhumidity', '50', {ATTR_UNIT_OF_MEASUREMENT: '%'})
'Stop down everything that was started.'
def tearDown(self):
self.hass.stop()
'Test the mold indicator sensor setup.'
def test_setup(self):
self.assertTrue(setup_component(self.hass, sensor.DOMAIN, {'sensor': {'platform': 'mold_indicator', 'indoor_temp_sensor': 'test.indoortemp', 'outdoor_temp_sensor': 'test.outdoortemp', 'indoor_humidity_sensor': 'test.indoorhumidity', 'calibration_factor': 2.0}})) moldind = self.hass.states.get('sensor.mold_indic...
'Test invalid sensor values.'
def test_invalidhum(self):
self.hass.states.set('test.indoortemp', '10', {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}) self.hass.states.set('test.outdoortemp', '10', {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}) self.hass.states.set('test.indoorhumidity', '0', {ATTR_UNIT_OF_MEASUREMENT: '%'}) self.assertTrue(setup_component(self.hass, se...
'Test the mold indicator internal calculations.'
def test_calculation(self):
self.assertTrue(setup_component(self.hass, sensor.DOMAIN, {'sensor': {'platform': 'mold_indicator', 'indoor_temp_sensor': 'test.indoortemp', 'outdoor_temp_sensor': 'test.outdoortemp', 'indoor_humidity_sensor': 'test.indoorhumidity', 'calibration_factor': 2.0}})) moldind = self.hass.states.get('sensor.mold_indic...
'Test the sensor_changed function.'
def test_sensor_changed(self):
self.assertTrue(setup_component(self.hass, sensor.DOMAIN, {'sensor': {'platform': 'mold_indicator', 'indoor_temp_sensor': 'test.indoortemp', 'outdoor_temp_sensor': 'test.outdoortemp', 'indoor_humidity_sensor': 'test.indoorhumidity', 'calibration_factor': 2.0}})) self.hass.states.set('test.indoortemp', '30', {AT...
'Mock add devices.'
def add_devices(self, devices):
for device in devices: self.DEVICES.append(device)
'Initialize values for this testcase class.'
def setUp(self):
self.hass = get_test_home_assistant() mock_kira = MagicMock() self.hass.data[kira.DOMAIN] = {kira.CONF_SENSOR: {}} self.hass.data[kira.DOMAIN][kira.CONF_SENSOR]['kira'] = mock_kira
'Stop everything that was started.'
def tearDown(self):
self.hass.stop()
'Ensure Kira sensor properly updates its attributes from callback.'
def test_kira_sensor_callback(self):
kira.setup_platform(self.hass, TEST_CONFIG, self.add_devices, DISCOVERY_INFO) assert (len(self.DEVICES) == 1) sensor = self.DEVICES[0] assert (sensor.name == 'kira') sensor.hass = self.hass codeName = 'FAKE_CODE' deviceName = 'FAKE_DEVICE' codeTuple = (codeName, deviceName) sensor._u...
'Mock add entities.'
def add_entities(self, new_entities, update_before_add=False):
if update_before_add: for entity in new_entities: entity.update() for entity in new_entities: self.entities.append(entity)
'Initialize values for this testcase class.'
def setUp(self):
self.hass = get_test_home_assistant() self.config = {CONF_API_KEY: 'foo', SCAN_INTERVAL: timedelta(seconds=120), CONF_TRAVEL_TIMES: [{CONF_ID: 96, CONF_NAME: 'I90 EB'}]} self.entities = []
'Stop everything that was started.'
def tearDown(self):
self.hass.stop()
'Test the platform setup with configuration.'
def test_setup_with_config(self):
self.assertTrue(setup_component(self.hass, 'sensor', {'wsdot': self.config}))
'Test for operational WSDOT sensor with proper attributes.'
@requests_mock.Mocker() def test_setup(self, mock_req):
uri = re.compile((WashingtonStateTravelTimeSensor.RESOURCE + '*')) mock_req.get(uri, text=load_fixture('wsdot.json')) wsdot.setup_platform(self.hass, self.config, self.add_entities) self.assertEqual(len(self.entities), 1) sensor = self.entities[0] self.assertEqual(sensor.name, 'I90 EB') s...
'Set up things to be run when tests are started.'
def setup_method(self, method):
self.hass = get_test_home_assistant()
'Stop everything that was started.'
def teardown_method(self, method):
self.hass.stop()
'Test the Moon sensor.'
@patch('homeassistant.components.sensor.moon.dt_util.utcnow', return_value=DAY1) def test_moon_day1(self, mock_request):
config = {'sensor': {'platform': 'moon', 'name': 'moon_day1'}} assert setup_component(self.hass, 'sensor', config) state = self.hass.states.get('sensor.moon_day1') self.assertEqual(state.state, 'Waxing crescent')
'Test the Moon sensor.'
@patch('homeassistant.components.sensor.moon.dt_util.utcnow', return_value=DAY2) def test_moon_day2(self, mock_request):
config = {'sensor': {'platform': 'moon', 'name': 'moon_day2'}} assert setup_component(self.hass, 'sensor', config) state = self.hass.states.get('sensor.moon_day2') self.assertEqual(state.state, 'Waning gibbous')
'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 with minimum configuration.'
@requests_mock.Mocker() def test_setup_minimum(self, mock_req):
resource = '{}{}{}'.format('http://', google_wifi.DEFAULT_HOST, google_wifi.ENDPOINT) mock_req.get(resource, status_code=200) self.assertTrue(setup_component(self.hass, 'sensor', {'sensor': {'platform': 'google_wifi', 'monitored_conditions': ['uptime']}})) assert_setup_component(1, 'sensor')
'Test setup with full configuration.'
@requests_mock.Mocker() def test_setup_get(self, mock_req):
resource = '{}{}{}'.format('http://', 'localhost', google_wifi.ENDPOINT) mock_req.get(resource, status_code=200) self.assertTrue(setup_component(self.hass, 'sensor', {'sensor': {'platform': 'google_wifi', 'host': 'localhost', 'name': 'Test Wifi', 'monitored_conditions': ['current_version', 'new_version',...
'Setup things to be run when tests are started.'
def setUp(self):
self.hass = get_test_home_assistant() with requests_mock.Mocker() as mock_req: self.setup_api(MOCK_DATA, mock_req)
'Stop everything that was started.'
def tearDown(self):
self.hass.stop()
'Setup API with fake data.'
def setup_api(self, data, mock_req):
resource = '{}{}{}'.format('http://', 'localhost', google_wifi.ENDPOINT) now = datetime(1970, month=1, day=1) with patch('homeassistant.util.dt.now', return_value=now): mock_req.get(resource, text=data, status_code=200) conditions = google_wifi.MONITORED_CONDITIONS.keys() self.api = ...
'Fake delay to prevent update throttle.'
def fake_delay(self, ha_delay):
hass_now = dt_util.utcnow() shifted_time = (hass_now + timedelta(seconds=ha_delay)) self.hass.bus.fire(ha.EVENT_TIME_CHANGED, {ha.ATTR_NOW: shifted_time})
'Test the name.'
def test_name(self):
for name in self.sensor_dict: sensor = self.sensor_dict[name]['sensor'] test_name = self.sensor_dict[name]['name'] self.assertEqual(test_name, sensor.name)
'Test the unit of measurement.'
def test_unit_of_measurement(self):
for name in self.sensor_dict: sensor = self.sensor_dict[name]['sensor'] self.assertEqual(self.sensor_dict[name]['units'], sensor.unit_of_measurement)