desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Test track_state_change.'
| def test_track_state_change(self):
| specific_runs = []
wildcard_runs = []
wildercard_runs = []
def specific_run_callback(entity_id, old_state, new_state):
specific_runs.append(1)
track_state_change(self.hass, 'light.Bowl', specific_run_callback, 'on', 'off')
@ha.callback
def wildcard_run_callback(entity_id, old_state, ... |
'Test tracking template.'
| def test_track_template(self):
| specific_runs = []
wildcard_runs = []
wildercard_runs = []
template_condition = Template("{{states.switch.test.state == 'on'}}", self.hass)
template_condition_var = Template("{{states.switch.test.state == 'on' and test == 5}}", self.hass)
self.hass.states.set('switch.test... |
'Test tracking time interval.'
| def test_track_time_interval(self):
| specific_runs = []
utc_now = dt_util.utcnow()
unsub = track_time_interval(self.hass, (lambda x: specific_runs.append(1)), timedelta(seconds=10))
self._send_time_changed((utc_now + timedelta(seconds=5)))
self.hass.block_till_done()
self.assertEqual(0, len(specific_runs))
self._send_time_chang... |
'Test track the sunrise.'
| def test_track_sunrise(self):
| latitude = 32.87336
longitude = 117.22743
self.hass.config.latitude = latitude
self.hass.config.longitude = longitude
setup_component(self.hass, sun.DOMAIN, {sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
astral = Astral()
utc_now = datetime(2014, 5, 24, 12, 0, 0, tzinfo=dt_util.UTC)
utc_today = ... |
'Test track the sunset.'
| def test_track_sunset(self):
| latitude = 32.87336
longitude = 117.22743
self.hass.config.latitude = latitude
self.hass.config.longitude = longitude
setup_component(self.hass, sun.DOMAIN, {sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
astral = Astral()
utc_now = datetime(2014, 5, 24, 12, 0, 0, tzinfo=dt_util.UTC)
utc_today = ... |
'Send a time changed event.'
| def _send_time_changed(self, now):
| self.hass.bus.fire(ha.EVENT_TIME_CHANGED, {ha.ATTR_NOW: now})
|
'Test periodic tasks per minute.'
| def test_periodic_task_minute(self):
| specific_runs = []
unsub = track_utc_time_change(self.hass, (lambda x: specific_runs.append(1)), minute='/5')
self._send_time_changed(datetime(2014, 5, 24, 12, 0, 0))
self.hass.block_till_done()
self.assertEqual(1, len(specific_runs))
self._send_time_changed(datetime(2014, 5, 24, 12, 3, 0))
... |
'Test periodic tasks per hour.'
| def test_periodic_task_hour(self):
| specific_runs = []
unsub = track_utc_time_change(self.hass, (lambda x: specific_runs.append(1)), hour='/2')
self._send_time_changed(datetime(2014, 5, 24, 22, 0, 0))
self.hass.block_till_done()
self.assertEqual(1, len(specific_runs))
self._send_time_changed(datetime(2014, 5, 24, 23, 0, 0))
se... |
'Test periodic tasks per day.'
| def test_periodic_task_day(self):
| specific_runs = []
unsub = track_utc_time_change(self.hass, (lambda x: specific_runs.append(1)), day='/2')
self._send_time_changed(datetime(2014, 5, 2, 0, 0, 0))
self.hass.block_till_done()
self.assertEqual(1, len(specific_runs))
self._send_time_changed(datetime(2014, 5, 3, 12, 0, 0))
self.h... |
'Test periodic tasks per year.'
| def test_periodic_task_year(self):
| specific_runs = []
unsub = track_utc_time_change(self.hass, (lambda x: specific_runs.append(1)), year='/2')
self._send_time_changed(datetime(2014, 5, 2, 0, 0, 0))
self.hass.block_till_done()
self.assertEqual(1, len(specific_runs))
self._send_time_changed(datetime(2015, 5, 2, 0, 0, 0))
self.h... |
'Test periodic tasks with wrong input.'
| def test_periodic_task_wrong_input(self):
| specific_runs = []
track_utc_time_change(self.hass, (lambda x: specific_runs.append(1)), year='/two')
self._send_time_changed(datetime(2014, 5, 2, 0, 0, 0))
self.hass.block_till_done()
self.assertEqual(0, len(specific_runs))
|
'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 the firing of events.'
| def test_firing_event(self):
| event = 'test_event'
calls = []
@callback
def record_event(event):
'Add recorded event to set.'
calls.append(event)
self.hass.bus.listen(event, record_event)
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA({'event': event, 'event_data': {'hello': 'world'}}))
... |
'Test the calling of a service.'
| def test_calling_service(self):
| calls = []
@callback
def record_call(service):
'Add recorded event to set.'
calls.append(service)
self.hass.services.register('test', 'script', record_call)
script.call_from_config(self.hass, {'service': 'test.script', 'data': {'hello': 'world'}})
self.hass.block_till... |
'Test the calling of a service.'
| def test_calling_service_template(self):
| calls = []
@callback
def record_call(service):
'Add recorded event to set.'
calls.append(service)
self.hass.services.register('test', 'script', record_call)
script.call_from_config(self.hass, {'service_template': '\n ... |
'Test the delay.'
| def test_delay(self):
| event = 'test_event'
events = []
@callback
def record_event(event):
'Add recorded event to set.'
events.append(event)
self.hass.bus.listen(event, record_event)
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([{'event': event}, {'delay': {'seconds': 5}}, {'event... |
'Test the delay as a template.'
| def test_delay_template(self):
| event = 'test_evnt'
events = []
@callback
def record_event(event):
'Add recorded event to set.'
events.append(event)
self.hass.bus.listen(event, record_event)
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([{'event': event}, {'delay': '00:00:{{ 5 }}'}, {... |
'Test the cancelling while the delay is present.'
| def test_cancel_while_delay(self):
| event = 'test_event'
events = []
@callback
def record_event(event):
'Add recorded event to set.'
events.append(event)
self.hass.bus.listen(event, record_event)
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([{'delay': {'seconds': 5}}, {'event': event}]))
s... |
'Test the wait template.'
| def test_wait_template(self):
| event = 'test_event'
events = []
@callback
def record_event(event):
'Add recorded event to set.'
events.append(event)
self.hass.bus.listen(event, record_event)
self.hass.states.set('switch.test', 'on')
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([{'even... |
'Test the wait template cancel action.'
| def test_wait_template_cancel(self):
| event = 'test_event'
events = []
@callback
def record_event(event):
'Add recorded event to set.'
events.append(event)
self.hass.bus.listen(event, record_event)
self.hass.states.set('switch.test', 'on')
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([{'even... |
'Test the wait template with correct condition.'
| def test_wait_template_not_schedule(self):
| event = 'test_event'
events = []
@callback
def record_event(event):
'Add recorded event to set.'
events.append(event)
self.hass.bus.listen(event, record_event)
self.hass.states.set('switch.test', 'on')
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([{'even... |
'Test the wait template.'
| def test_wait_template_timeout(self):
| event = 'test_event'
events = []
@callback
def record_event(event):
'Add recorded event to set.'
events.append(event)
self.hass.bus.listen(event, record_event)
self.hass.states.set('switch.test', 'on')
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([{'even... |
'Test if we can pass variables to script.'
| def test_passing_variables_to_script(self):
| calls = []
@callback
def record_call(service):
'Add recorded event to set.'
calls.append(service)
self.hass.services.register('test', 'script', record_call)
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([{'service': 'test.script', 'data_template': {'hello': '{{ ... |
'Test if we can use conditions in a script.'
| def test_condition(self):
| event = 'test_event'
events = []
@callback
def record_event(event):
'Add recorded event to set.'
events.append(event)
self.hass.bus.listen(event, record_event)
self.hass.states.set('test.entity', 'hello')
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([{'e... |
'Test that the conditions do not get created multiple times.'
| @mock.patch('homeassistant.helpers.script.condition.async_from_config')
def test_condition_created_once(self, async_from_config):
| event = 'test_event'
events = []
@callback
def record_event(event):
'Add recorded event to set.'
events.append(event)
self.hass.bus.listen(event, record_event)
self.hass.states.set('test.entity', 'hello')
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([{'e... |
'Test that multiple conditions get cached.'
| def test_all_conditions_cached(self):
| event = 'test_event'
events = []
@callback
def record_event(event):
'Add recorded event to set.'
events.append(event)
self.hass.bus.listen(event, record_event)
self.hass.states.set('test.entity', 'hello')
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([{'e... |
'Test the last_triggered.'
| def test_last_triggered(self):
| event = 'test_event'
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([{'event': event}, {'delay': {'seconds': 5}}, {'event': event}]))
assert (script_obj.last_triggered is None)
time = dt_util.utcnow()
with mock.patch('homeassistant.helpers.script.date_util.utcnow', return_value=time):
... |
'Setup the tests.'
| def setUp(self):
| self.hass = get_test_home_assistant()
self.hass.config.units = UnitSystem('custom', TEMP_CELSIUS, LENGTH_METERS, VOLUME_LITERS, MASS_GRAMS)
|
'Stop down stuff we started.'
| def tearDown(self):
| self.hass.stop()
|
'Test referring states by entity id.'
| def test_referring_states_by_entity_id(self):
| self.hass.states.set('test.object', 'happy')
self.assertEqual('happy', template.Template('{{ states.test.object.state }}', self.hass).render())
|
'Test iterating all states.'
| def test_iterating_all_states(self):
| self.hass.states.set('test.object', 'happy')
self.hass.states.set('sensor.temperature', 10)
self.assertEqual('10happy', template.Template('{% for state in states %}{{ state.state }}{% endfor %}', self.hass).render())
|
'Test iterating domain states.'
| def test_iterating_domain_states(self):
| self.hass.states.set('test.object', 'happy')
self.hass.states.set('sensor.back_door', 'open')
self.hass.states.set('sensor.temperature', 10)
self.assertEqual('open10', template.Template('\n{% for state in states.sensor %}{{ state.state }}{% endfor %}\n ... |
'Test float.'
| def test_float(self):
| self.hass.states.set('sensor.temperature', '12')
self.assertEqual('12.0', template.Template('{{ float(states.sensor.temperature.state) }}', self.hass).render())
self.assertEqual('True', template.Template('{{ float(states.sensor.temperature.state) > 11 }}', self.hass).render())
|
'Test rounding value.'
| def test_rounding_value(self):
| self.hass.states.set('sensor.temperature', 12.78)
self.assertEqual('12.8', template.Template('{{ states.sensor.temperature.state | round(1) }}', self.hass).render())
self.assertEqual('128', template.Template('{{ states.sensor.temperature.state | multiply(10) | round }}', self.h... |
'Test rounding value get original value on error.'
| def test_rounding_value_get_original_value_on_error(self):
| self.assertEqual('None', template.Template('{{ None | round }}', self.hass).render())
self.assertEqual('no_number', template.Template('{{ "no_number" | round }}', self.hass).render())
|
'Test multiply.'
| def test_multiply(self):
| tests = {None: 'None', 10: '100', '"abcd"': 'abcd'}
for (inp, out) in tests.items():
self.assertEqual(out, template.Template(('{{ %s | multiply(10) | round }}' % inp), self.hass).render())
|
'Test the parse timestamp method.'
| def test_strptime(self):
| tests = [('2016-10-19 15:22:05.588122 UTC', '%Y-%m-%d %H:%M:%S.%f %Z', None), ('2016-10-19 15:22:05.588122+0100', '%Y-%m-%d %H:%M:%S.%f%z', None), ('2016-10-19 15:22:05.588122', '%Y-%m-%d %H:%M:%S.%f', None), ('2016-10-19', '%Y-%m-%d', None), ('2016', '%Y', None), ('15:22:05', '%H:%M:%S', No... |
'Test the timestamps to custom filter.'
| def test_timestamp_custom(self):
| now = dt_util.utcnow()
tests = [(None, None, None, 'None'), (1469119144, None, True, '2016-07-21 16:39:04'), (1469119144, '%Y', True, '2016'), (1469119144, 'invalid', True, 'invalid'), (dt_util.as_timestamp(now), None, False, now.strftime('%Y-%m-%d %H:%M:%S'))]
for (inp, fmt, local, out) in tests:
... |
'Test the timestamps to local filter.'
| def test_timestamp_local(self):
| tests = {None: 'None', 1469119144: '2016-07-21 16:39:04'}
for (inp, out) in tests.items():
self.assertEqual(out, template.Template(('{{ %s | timestamp_local }}' % inp), self.hass).render())
|
'Test the min filter.'
| def test_min(self):
| self.assertEqual('1', template.Template('{{ [1, 2, 3] | min }}', self.hass).render())
|
'Test the max filter.'
| def test_max(self):
| self.assertEqual('3', template.Template('{{ [1, 2, 3] | max }}', self.hass).render())
|
'Test the timestamps to local filter.'
| def test_timestamp_utc(self):
| now = dt_util.utcnow()
tests = {None: 'None', 1469119144: '2016-07-21 16:39:04', dt_util.as_timestamp(now): now.strftime('%Y-%m-%d %H:%M:%S')}
for (inp, out) in tests.items():
self.assertEqual(out, template.Template(('{{ %s | timestamp_utc }}' % inp), self.hass).render())
|
'Test the as_timestamp function.'
| def test_as_timestamp(self):
| self.assertEqual('None', template.Template('{{ as_timestamp("invalid") }}', self.hass).render())
self.hass.mock = None
self.assertEqual('None', template.Template('{{ as_timestamp(states.mock) }}', self.hass).render())
tpl = '{{ as_timestamp(strptime("2024-02-03T09:10:24+0000", "%Y-%m-%... |
'Ensure the random filter runs every time, not just once.'
| @patch.object(random, 'choice')
def test_random_every_time(self, test_choice):
| tpl = template.Template('{{ [1,2] | random }}', self.hass)
test_choice.return_value = 'foo'
self.assertEqual('foo', tpl.render())
test_choice.return_value = 'bar'
self.assertEqual('bar', tpl.render())
|
'Test passing variables as keywords.'
| def test_passing_vars_as_keywords(self):
| self.assertEqual('127', template.Template('{{ hello }}', self.hass).render(hello=127))
|
'Test passing variables as variables.'
| def test_passing_vars_as_vars(self):
| self.assertEqual('127', template.Template('{{ hello }}', self.hass).render({'hello': 127}))
|
'Render with possible JSON value with valid JSON.'
| def test_render_with_possible_json_value_with_valid_json(self):
| tpl = template.Template('{{ value_json.hello }}', self.hass)
self.assertEqual('world', tpl.render_with_possible_json_value('{"hello": "world"}'))
|
'Render with possible JSON value with invalid JSON.'
| def test_render_with_possible_json_value_with_invalid_json(self):
| tpl = template.Template('{{ value_json }}', self.hass)
self.assertEqual('', tpl.render_with_possible_json_value('{ I AM NOT JSON }'))
|
'Render with possible JSON value with template error value.'
| def test_render_with_possible_json_value_with_template_error_value(self):
| tpl = template.Template('{{ non_existing.variable }}', self.hass)
self.assertEqual('-', tpl.render_with_possible_json_value('hello', '-'))
|
'Render with possible JSON value with unknown JSON object.'
| def test_render_with_possible_json_value_with_missing_json_value(self):
| tpl = template.Template('{{ value_json.goodbye }}', self.hass)
self.assertEqual('', tpl.render_with_possible_json_value('{"hello": "world"}'))
|
'Render with possible JSON value with known JSON object.'
| def test_render_with_possible_json_value_valid_with_is_defined(self):
| tpl = template.Template('{{ value_json.hello|is_defined }}', self.hass)
self.assertEqual('world', tpl.render_with_possible_json_value('{"hello": "world"}'))
|
'Render with possible JSON value with unknown JSON object.'
| def test_render_with_possible_json_value_undefined_json(self):
| tpl = template.Template('{{ value_json.bye|is_defined }}', self.hass)
self.assertEqual('{"hello": "world"}', tpl.render_with_possible_json_value('{"hello": "world"}'))
|
'Render with possible JSON value with unknown JSON object.'
| def test_render_with_possible_json_value_undefined_json_error_value(self):
| tpl = template.Template('{{ value_json.bye|is_defined }}', self.hass)
self.assertEqual('', tpl.render_with_possible_json_value('{"hello": "world"}', ''))
|
'Test raising an exception on error.'
| def test_raise_exception_on_error(self):
| with self.assertRaises(TemplateError):
template.Template('{{ invalid_syntax').ensure_valid()
|
'Test if state exists works.'
| def test_if_state_exists(self):
| self.hass.states.set('test.object', 'available')
tpl = template.Template('{% if states.test.object %}exists{% else %}not exists{% endif %}', self.hass)
self.assertEqual('exists', tpl.render())
|
'Test is_state method.'
| def test_is_state(self):
| self.hass.states.set('test.object', 'available')
tpl = template.Template('\n{% if is_state("test.object", "available") %}yes{% else %}no{% endif %}\n ', self.hass)
self.assertEqual('yes', tpl.render())
tpl = template.Template('\n{{ ... |
'Test is_state_attr method.'
| def test_is_state_attr(self):
| self.hass.states.set('test.object', 'available', {'mode': 'on'})
tpl = template.Template('\n{% if is_state_attr("test.object", "mode", "on") %}yes{% else %}no{% endif %}\n ', self.hass)
self.assertEqual('yes', tpl.rend... |
'Test using states as a function.'
| def test_states_function(self):
| self.hass.states.set('test.object', 'available')
tpl = template.Template('{{ states("test.object") }}', self.hass)
self.assertEqual('available', tpl.render())
tpl2 = template.Template('{{ states("test.object2") }}', self.hass)
self.assertEqual('unknown', tpl2.render())
|
'Test now method.'
| @patch('homeassistant.helpers.template.TemplateEnvironment.is_safe_callable', return_value=True)
def test_now(self, mock_is_safe):
| now = dt_util.now()
with patch.dict(template.ENV.globals, {'now': (lambda : now)}):
self.assertEqual(now.isoformat(), template.Template('{{ now().isoformat() }}', self.hass).render())
|
'Test utcnow method.'
| @patch('homeassistant.helpers.template.TemplateEnvironment.is_safe_callable', return_value=True)
def test_utcnow(self, mock_is_safe):
| now = dt_util.utcnow()
with patch.dict(template.ENV.globals, {'utcnow': (lambda : now)}):
self.assertEqual(now.isoformat(), template.Template('{{ utcnow().isoformat() }}', self.hass).render())
|
'Test distance function with 1 state.'
| def test_distance_function_with_1_state(self):
| self.hass.states.set('test.object', 'happy', {'latitude': 32.87336, 'longitude': (-117.22943)})
tpl = template.Template('{{ distance(states.test.object) | round }}', self.hass)
self.assertEqual('187', tpl.render())
|
'Test distance function with 2 states.'
| def test_distance_function_with_2_states(self):
| self.hass.states.set('test.object', 'happy', {'latitude': 32.87336, 'longitude': (-117.22943)})
self.hass.states.set('test.object_2', 'happy', {'latitude': self.hass.config.latitude, 'longitude': self.hass.config.longitude})
tpl = template.Template('{{ distance(states.test.object, states.test.object_2... |
'Test distance function with 1 coord.'
| def test_distance_function_with_1_coord(self):
| tpl = template.Template('{{ distance("32.87336", "-117.22943") | round }}', self.hass)
self.assertEqual('187', tpl.render())
|
'Test distance function with 2 coords.'
| def test_distance_function_with_2_coords(self):
| self.assertEqual('187', template.Template(('{{ distance("32.87336", "-117.22943", %s, %s) | round }}' % (self.hass.config.latitude, self.hass.config.longitude)), self.hass).render())
|
'Test distance function with 1 state 1 coord.'
| def test_distance_function_with_1_state_1_coord(self):
| self.hass.states.set('test.object_2', 'happy', {'latitude': self.hass.config.latitude, 'longitude': self.hass.config.longitude})
tpl = template.Template('{{ distance("32.87336", "-117.22943", states.test.object_2) | round }}', self.hass)
self.assertEqual('187', tpl.render())
tpl2 = tem... |
'Test distance function return None if invalid state.'
| def test_distance_function_return_None_if_invalid_state(self):
| self.hass.states.set('test.object_2', 'happy', {'latitude': 10})
tpl = template.Template('{{ distance(states.test.object_2) | round }}', self.hass)
self.assertEqual('None', tpl.render())
|
'Test distance function return None if invalid coord.'
| def test_distance_function_return_None_if_invalid_coord(self):
| self.assertEqual('None', template.Template('{{ distance("123", "abc") }}', self.hass).render())
self.assertEqual('None', template.Template('{{ distance("123") }}', self.hass).render())
self.hass.states.set('test.object_2', 'happy', {'latitude': self.hass.config.latitude, 'longitude': self.has... |
'Test closest function home vs domain.'
| def test_closest_function_home_vs_domain(self):
| self.hass.states.set('test_domain.object', 'happy', {'latitude': (self.hass.config.latitude + 0.1), 'longitude': (self.hass.config.longitude + 0.1)})
self.hass.states.set('not_test_domain.but_closer', 'happy', {'latitude': self.hass.config.latitude, 'longitude': self.hass.config.longitude})
self.assertEqual... |
'Test closest function home vs all states.'
| def test_closest_function_home_vs_all_states(self):
| self.hass.states.set('test_domain.object', 'happy', {'latitude': (self.hass.config.latitude + 0.1), 'longitude': (self.hass.config.longitude + 0.1)})
self.hass.states.set('test_domain_2.and_closer', 'happy', {'latitude': self.hass.config.latitude, 'longitude': self.hass.config.longitude})
self.assertEqual('... |
'Test closest function home vs group entity id.'
| def test_closest_function_home_vs_group_entity_id(self):
| self.hass.states.set('test_domain.object', 'happy', {'latitude': (self.hass.config.latitude + 0.1), 'longitude': (self.hass.config.longitude + 0.1)})
self.hass.states.set('not_in_group.but_closer', 'happy', {'latitude': self.hass.config.latitude, 'longitude': self.hass.config.longitude})
group.Group.create_... |
'Test closest function home vs group state.'
| def test_closest_function_home_vs_group_state(self):
| self.hass.states.set('test_domain.object', 'happy', {'latitude': (self.hass.config.latitude + 0.1), 'longitude': (self.hass.config.longitude + 0.1)})
self.hass.states.set('not_in_group.but_closer', 'happy', {'latitude': self.hass.config.latitude, 'longitude': self.hass.config.longitude})
group.Group.create_... |
'Test closest function to coord.'
| def test_closest_function_to_coord(self):
| self.hass.states.set('test_domain.closest_home', 'happy', {'latitude': (self.hass.config.latitude + 0.1), 'longitude': (self.hass.config.longitude + 0.1)})
self.hass.states.set('test_domain.closest_zone', 'happy', {'latitude': (self.hass.config.latitude + 0.2), 'longitude': (self.hass.config.longitude + 0.2)})
... |
'Test closest function to entity id.'
| def test_closest_function_to_entity_id(self):
| self.hass.states.set('test_domain.closest_home', 'happy', {'latitude': (self.hass.config.latitude + 0.1), 'longitude': (self.hass.config.longitude + 0.1)})
self.hass.states.set('test_domain.closest_zone', 'happy', {'latitude': (self.hass.config.latitude + 0.2), 'longitude': (self.hass.config.longitude + 0.2)})
... |
'Test closest function to state.'
| def test_closest_function_to_state(self):
| self.hass.states.set('test_domain.closest_home', 'happy', {'latitude': (self.hass.config.latitude + 0.1), 'longitude': (self.hass.config.longitude + 0.1)})
self.hass.states.set('test_domain.closest_zone', 'happy', {'latitude': (self.hass.config.latitude + 0.2), 'longitude': (self.hass.config.longitude + 0.2)})
... |
'Test closest function invalid state.'
| def test_closest_function_invalid_state(self):
| self.hass.states.set('test_domain.closest_home', 'happy', {'latitude': (self.hass.config.latitude + 0.1), 'longitude': (self.hass.config.longitude + 0.1)})
for state in ('states.zone.non_existing', '"zone.non_existing"'):
self.assertEqual('None', template.Template(('{{ closest(%s, states) }}' %... |
'Test closest function state with invalid location.'
| def test_closest_function_state_with_invalid_location(self):
| self.hass.states.set('test_domain.closest_home', 'happy', {'latitude': 'invalid latitude', 'longitude': (self.hass.config.longitude + 0.1)})
self.assertEqual('None', template.Template('{{ closest(states.test_domain.closest_home, states) }}', self.hass).render())
|
'Test closest function invalid coordinates.'
| def test_closest_function_invalid_coordinates(self):
| self.hass.states.set('test_domain.closest_home', 'happy', {'latitude': (self.hass.config.latitude + 0.1), 'longitude': (self.hass.config.longitude + 0.1)})
self.assertEqual('None', template.Template('{{ closest("invalid", "coord", states) }}', self.hass).render())
|
'Test closest function without location states.'
| def test_closest_function_no_location_states(self):
| self.assertEqual('None', template.Template('{{ closest(states) }}', self.hass).render())
|
'Test extract entities function with none or exclude stuff.'
| def test_extract_entities_none_exclude_stuff(self):
| self.assertEqual(MATCH_ALL, template.extract_entities(None))
self.assertEqual(MATCH_ALL, template.extract_entities('{{ closest(states.zone.far_away, states.test_domain).entity_id }}'))
self.assertEqual(MATCH_ALL, template.extract_entities('{{ distance("123", states.test_object_2) }}'))
|
'Test extract entities function with none entities stuff.'
| def test_extract_entities_no_match_entities(self):
| self.assertEqual(MATCH_ALL, template.extract_entities("{{ value_json.tst | timestamp_custom('%Y' True) }}"))
self.assertEqual(MATCH_ALL, template.extract_entities('\n{% for state in states.sensor %}\n {{ state.entity_id }}={{ state.state }},\n{% endfor %}\n... |
'Test extract entities function with entities stuff.'
| def test_extract_entities_match_entities(self):
| self.assertListEqual(['device_tracker.phone_1'], template.extract_entities("\n{% if is_state('device_tracker.phone_1', 'home') %}\n Ha, Hercules is home!\n{% else %}\n Hercules is at {{ states('device_tracker.phone_1') }}.\n{% endif %}\n ... |
'Init needed objects.'
| def setUp(self):
| self.hass = get_test_home_assistant()
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test the extraction of domain configuration.'
| def test_extract_domain_configs(self):
| config = {'zone': None, 'zoner': None, 'zone ': None, 'zone Hallo': None, 'zone 100': None}
self.assertEqual(set(['zone', 'zone Hallo', 'zone 100']), set(helpers.extract_domain_configs(config, 'zone')))
|
'Test config per platform method.'
| def test_config_per_platform(self):
| config = OrderedDict([('zone', {'platform': 'hello'}), ('zoner', None), ('zone Hallo', [1, {'platform': 'hello 2'}]), ('zone 100', None)])
assert ([('hello', config['zone']), (None, 1), ('hello 2', config['zone Hallo'][1])] == list(helpers.config_per_platform(config, 'zone')))
|
'Test property to fetch.'
| @property
@deprecated_substitute('old_property')
def new_property(self):
| raise NotImplementedError()
|
'Test property to fetch.'
| @property
def old_property(self):
| return True
|
'Test property to fetch.'
| @property
def new_property(self):
| return True
|
'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 retrieving next sun events.'
| def test_next_events(self):
| utc_now = datetime(2016, 11, 1, 8, 0, 0, tzinfo=dt_util.UTC)
from astral import Astral
astral = Astral()
utc_today = utc_now.date()
latitude = self.hass.config.latitude
longitude = self.hass.config.longitude
mod = (-1)
while True:
next_dawn = astral.dawn_utc((utc_today + timedelt... |
'Test retrieving next sun events.'
| def test_date_events(self):
| utc_now = datetime(2016, 11, 1, 8, 0, 0, tzinfo=dt_util.UTC)
from astral import Astral
astral = Astral()
utc_today = utc_now.date()
latitude = self.hass.config.latitude
longitude = self.hass.config.longitude
dawn = astral.dawn_utc(utc_today, latitude, longitude)
dusk = astral.dusk_utc(ut... |
'Test retrieving next sun events.'
| def test_date_events_default_date(self):
| utc_now = datetime(2016, 11, 1, 8, 0, 0, tzinfo=dt_util.UTC)
from astral import Astral
astral = Astral()
utc_today = utc_now.date()
latitude = self.hass.config.latitude
longitude = self.hass.config.longitude
dawn = astral.dawn_utc(utc_today, latitude, longitude)
dusk = astral.dusk_utc(ut... |
'Test retrieving next sun events.'
| def test_date_events_accepts_datetime(self):
| utc_now = datetime(2016, 11, 1, 8, 0, 0, tzinfo=dt_util.UTC)
from astral import Astral
astral = Astral()
utc_today = utc_now.date()
latitude = self.hass.config.latitude
longitude = self.hass.config.longitude
dawn = astral.dawn_utc(utc_today, latitude, longitude)
dusk = astral.dusk_utc(ut... |
'Test retrieving next sun events.'
| def test_is_up(self):
| utc_now = datetime(2016, 11, 1, 12, 0, 0, tzinfo=dt_util.UTC)
with patch('homeassistant.helpers.condition.dt_util.utcnow', return_value=utc_now):
self.assertFalse(sun.is_up(self.hass))
utc_now = datetime(2016, 11, 1, 18, 0, 0, tzinfo=dt_util.UTC)
with patch('homeassistant.helpers.condition.dt_ut... |
'Test location in Norway where the sun doesn\'t set in summer.'
| def test_norway_in_june(self):
| self.hass.config.latitude = 69.6
self.hass.config.longitude = 18.8
june = datetime(2016, 6, 1, tzinfo=dt_util.UTC)
print sun.get_astral_event_date(self.hass, 'sunrise', datetime(2017, 7, 25))
print sun.get_astral_event_date(self.hass, 'sunset', datetime(2017, 7, 25))
print sun.get_astral_event_d... |
'Setup 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 \'and\' condition.'
| def test_and_condition(self):
| test = condition.from_config({'condition': 'and', 'conditions': [{'condition': 'state', 'entity_id': 'sensor.temperature', 'state': '100'}, {'condition': 'numeric_state', 'entity_id': 'sensor.temperature', 'below': 110}]})
self.hass.states.set('sensor.temperature', 120)
assert (not test(self.hass))
self... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.