Search is not available for this dataset
identifier stringlengths 1 155 | parameters stringlengths 2 6.09k | docstring stringlengths 11 63.4k | docstring_summary stringlengths 0 63.4k | function stringlengths 29 99.8k | function_tokens list | start_point list | end_point list | language stringclasses 1
value | docstring_language stringlengths 2 7 | docstring_language_predictions stringlengths 18 23 | is_langid_reliable stringclasses 2
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
test_render_with_possible_json_value_with_valid_json | (hass) | Render with possible JSON value with valid JSON. | Render with possible JSON value with valid JSON. | def test_render_with_possible_json_value_with_valid_json(hass):
"""Render with possible JSON value with valid JSON."""
tpl = template.Template("{{ value_json.hello }}", hass)
assert tpl.async_render_with_possible_json_value('{"hello": "world"}') == "world" | [
"def",
"test_render_with_possible_json_value_with_valid_json",
"(",
"hass",
")",
":",
"tpl",
"=",
"template",
".",
"Template",
"(",
"\"{{ value_json.hello }}\"",
",",
"hass",
")",
"assert",
"tpl",
".",
"async_render_with_possible_json_value",
"(",
"'{\"hello\": \"world\"}'"... | [
742,
0
] | [
745,
85
] | python | en | ['en', 'en', 'en'] | True |
test_render_with_possible_json_value_with_invalid_json | (hass) | Render with possible JSON value with invalid JSON. | Render with possible JSON value with invalid JSON. | def test_render_with_possible_json_value_with_invalid_json(hass):
"""Render with possible JSON value with invalid JSON."""
tpl = template.Template("{{ value_json }}", hass)
assert tpl.async_render_with_possible_json_value("{ I AM NOT JSON }") == "" | [
"def",
"test_render_with_possible_json_value_with_invalid_json",
"(",
"hass",
")",
":",
"tpl",
"=",
"template",
".",
"Template",
"(",
"\"{{ value_json }}\"",
",",
"hass",
")",
"assert",
"tpl",
".",
"async_render_with_possible_json_value",
"(",
"\"{ I AM NOT JSON }\"",
")"... | [
748,
0
] | [
751,
79
] | python | en | ['en', 'en', 'en'] | True |
test_render_with_possible_json_value_with_template_error_value | (hass) | Render with possible JSON value with template error value. | Render with possible JSON value with template error value. | def test_render_with_possible_json_value_with_template_error_value(hass):
"""Render with possible JSON value with template error value."""
tpl = template.Template("{{ non_existing.variable }}", hass)
assert tpl.async_render_with_possible_json_value("hello", "-") == "-" | [
"def",
"test_render_with_possible_json_value_with_template_error_value",
"(",
"hass",
")",
":",
"tpl",
"=",
"template",
".",
"Template",
"(",
"\"{{ non_existing.variable }}\"",
",",
"hass",
")",
"assert",
"tpl",
".",
"async_render_with_possible_json_value",
"(",
"\"hello\""... | [
754,
0
] | [
757,
73
] | python | en | ['en', 'en', 'en'] | True |
test_render_with_possible_json_value_with_missing_json_value | (hass) | Render with possible JSON value with unknown JSON object. | Render with possible JSON value with unknown JSON object. | def test_render_with_possible_json_value_with_missing_json_value(hass):
"""Render with possible JSON value with unknown JSON object."""
tpl = template.Template("{{ value_json.goodbye }}", hass)
assert tpl.async_render_with_possible_json_value('{"hello": "world"}') == "" | [
"def",
"test_render_with_possible_json_value_with_missing_json_value",
"(",
"hass",
")",
":",
"tpl",
"=",
"template",
".",
"Template",
"(",
"\"{{ value_json.goodbye }}\"",
",",
"hass",
")",
"assert",
"tpl",
".",
"async_render_with_possible_json_value",
"(",
"'{\"hello\": \"... | [
760,
0
] | [
763,
80
] | python | en | ['en', 'en', 'en'] | True |
test_render_with_possible_json_value_valid_with_is_defined | (hass) | Render with possible JSON value with known JSON object. | Render with possible JSON value with known JSON object. | def test_render_with_possible_json_value_valid_with_is_defined(hass):
"""Render with possible JSON value with known JSON object."""
tpl = template.Template("{{ value_json.hello|is_defined }}", hass)
assert tpl.async_render_with_possible_json_value('{"hello": "world"}') == "world" | [
"def",
"test_render_with_possible_json_value_valid_with_is_defined",
"(",
"hass",
")",
":",
"tpl",
"=",
"template",
".",
"Template",
"(",
"\"{{ value_json.hello|is_defined }}\"",
",",
"hass",
")",
"assert",
"tpl",
".",
"async_render_with_possible_json_value",
"(",
"'{\"hell... | [
766,
0
] | [
769,
85
] | python | en | ['en', 'en', 'en'] | True |
test_render_with_possible_json_value_undefined_json | (hass) | Render with possible JSON value with unknown JSON object. | Render with possible JSON value with unknown JSON object. | def test_render_with_possible_json_value_undefined_json(hass):
"""Render with possible JSON value with unknown JSON object."""
tpl = template.Template("{{ value_json.bye|is_defined }}", hass)
assert (
tpl.async_render_with_possible_json_value('{"hello": "world"}')
== '{"hello": "world"}'
... | [
"def",
"test_render_with_possible_json_value_undefined_json",
"(",
"hass",
")",
":",
"tpl",
"=",
"template",
".",
"Template",
"(",
"\"{{ value_json.bye|is_defined }}\"",
",",
"hass",
")",
"assert",
"(",
"tpl",
".",
"async_render_with_possible_json_value",
"(",
"'{\"hello\... | [
772,
0
] | [
778,
5
] | python | en | ['en', 'en', 'en'] | True |
test_render_with_possible_json_value_undefined_json_error_value | (hass) | Render with possible JSON value with unknown JSON object. | Render with possible JSON value with unknown JSON object. | def test_render_with_possible_json_value_undefined_json_error_value(hass):
"""Render with possible JSON value with unknown JSON object."""
tpl = template.Template("{{ value_json.bye|is_defined }}", hass)
assert tpl.async_render_with_possible_json_value('{"hello": "world"}', "") == "" | [
"def",
"test_render_with_possible_json_value_undefined_json_error_value",
"(",
"hass",
")",
":",
"tpl",
"=",
"template",
".",
"Template",
"(",
"\"{{ value_json.bye|is_defined }}\"",
",",
"hass",
")",
"assert",
"tpl",
".",
"async_render_with_possible_json_value",
"(",
"'{\"h... | [
781,
0
] | [
784,
84
] | python | en | ['en', 'en', 'en'] | True |
test_render_with_possible_json_value_non_string_value | (hass) | Render with possible JSON value with non-string value. | Render with possible JSON value with non-string value. | def test_render_with_possible_json_value_non_string_value(hass):
"""Render with possible JSON value with non-string value."""
tpl = template.Template(
"""
{{ strptime(value~'+0000', '%Y-%m-%d %H:%M:%S%z') }}
""",
hass,
)
value = datetime(2019, 1, 18, 12, 13, 14)
expected = st... | [
"def",
"test_render_with_possible_json_value_non_string_value",
"(",
"hass",
")",
":",
"tpl",
"=",
"template",
".",
"Template",
"(",
"\"\"\"\n{{ strptime(value~'+0000', '%Y-%m-%d %H:%M:%S%z') }}\n \"\"\"",
",",
"hass",
",",
")",
"value",
"=",
"datetime",
"(",
"2019",... | [
787,
0
] | [
797,
71
] | python | en | ['en', 'en', 'en'] | True |
test_if_state_exists | (hass) | Test if state exists works. | Test if state exists works. | def test_if_state_exists(hass):
"""Test if state exists works."""
hass.states.async_set("test.object", "available")
tpl = template.Template(
"{% if states.test.object %}exists{% else %}not exists{% endif %}", hass
)
assert tpl.async_render() == "exists" | [
"def",
"test_if_state_exists",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.object\"",
",",
"\"available\"",
")",
"tpl",
"=",
"template",
".",
"Template",
"(",
"\"{% if states.test.object %}exists{% else %}not exists{% endif %}\"",
",",
... | [
800,
0
] | [
806,
41
] | python | en | ['en', 'en', 'en'] | True |
test_is_state | (hass) | Test is_state method. | Test is_state method. | def test_is_state(hass):
"""Test is_state method."""
hass.states.async_set("test.object", "available")
tpl = template.Template(
"""
{% if is_state("test.object", "available") %}yes{% else %}no{% endif %}
""",
hass,
)
assert tpl.async_render() == "yes"
tpl = template.Temp... | [
"def",
"test_is_state",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.object\"",
",",
"\"available\"",
")",
"tpl",
"=",
"template",
".",
"Template",
"(",
"\"\"\"\n{% if is_state(\"test.object\", \"available\") %}yes{% else %}no{% endif %}\n ... | [
809,
0
] | [
826,
38
] | python | en | ['en', 'en', 'en'] | True |
test_is_state_attr | (hass) | Test is_state_attr method. | Test is_state_attr method. | def test_is_state_attr(hass):
"""Test is_state_attr method."""
hass.states.async_set("test.object", "available", {"mode": "on"})
tpl = template.Template(
"""
{% if is_state_attr("test.object", "mode", "on") %}yes{% else %}no{% endif %}
""",
hass,
)
assert tpl.async_render... | [
"def",
"test_is_state_attr",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.object\"",
",",
"\"available\"",
",",
"{",
"\"mode\"",
":",
"\"on\"",
"}",
")",
"tpl",
"=",
"template",
".",
"Template",
"(",
"\"\"\"\n{% if is_state_attr... | [
829,
0
] | [
846,
38
] | python | en | ['en', 'en', 'en'] | True |
test_state_attr | (hass) | Test state_attr method. | Test state_attr method. | def test_state_attr(hass):
"""Test state_attr method."""
hass.states.async_set("test.object", "available", {"mode": "on"})
tpl = template.Template(
"""
{% if state_attr("test.object", "mode") == "on" %}yes{% else %}no{% endif %}
""",
hass,
)
assert tpl.async_render() == "... | [
"def",
"test_state_attr",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.object\"",
",",
"\"available\"",
",",
"{",
"\"mode\"",
":",
"\"on\"",
"}",
")",
"tpl",
"=",
"template",
".",
"Template",
"(",
"\"\"\"\n{% if state_attr(\"tes... | [
849,
0
] | [
866,
37
] | python | en | ['en', 'de', 'en'] | True |
test_states_function | (hass) | Test using states as a function. | Test using states as a function. | def test_states_function(hass):
"""Test using states as a function."""
hass.states.async_set("test.object", "available")
tpl = template.Template('{{ states("test.object") }}', hass)
assert tpl.async_render() == "available"
tpl2 = template.Template('{{ states("test.object2") }}', hass)
assert tp... | [
"def",
"test_states_function",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.object\"",
",",
"\"available\"",
")",
"tpl",
"=",
"template",
".",
"Template",
"(",
"'{{ states(\"test.object\") }}'",
",",
"hass",
")",
"assert",
"tpl",
... | [
869,
0
] | [
876,
43
] | python | en | ['en', 'en', 'en'] | True |
test_now | (mock_is_safe, hass) | Test now method. | Test now method. | def test_now(mock_is_safe, hass):
"""Test now method."""
now = dt_util.now()
with patch("homeassistant.util.dt.now", return_value=now):
info = template.Template("{{ now().isoformat() }}", hass).async_render_to_info()
assert now.isoformat() == info.result()
assert info.has_time is True | [
"def",
"test_now",
"(",
"mock_is_safe",
",",
"hass",
")",
":",
"now",
"=",
"dt_util",
".",
"now",
"(",
")",
"with",
"patch",
"(",
"\"homeassistant.util.dt.now\"",
",",
"return_value",
"=",
"now",
")",
":",
"info",
"=",
"template",
".",
"Template",
"(",
"... | [
883,
0
] | [
890,
32
] | python | en | ['en', 'sr', 'en'] | True |
test_utcnow | (mock_is_safe, hass) | Test now method. | Test now method. | def test_utcnow(mock_is_safe, hass):
"""Test now method."""
utcnow = dt_util.utcnow()
with patch("homeassistant.util.dt.utcnow", return_value=utcnow):
info = template.Template(
"{{ utcnow().isoformat() }}", hass
).async_render_to_info()
assert utcnow.isoformat() == info.r... | [
"def",
"test_utcnow",
"(",
"mock_is_safe",
",",
"hass",
")",
":",
"utcnow",
"=",
"dt_util",
".",
"utcnow",
"(",
")",
"with",
"patch",
"(",
"\"homeassistant.util.dt.utcnow\"",
",",
"return_value",
"=",
"utcnow",
")",
":",
"info",
"=",
"template",
".",
"Templa... | [
897,
0
] | [
906,
32
] | python | en | ['en', 'sr', 'en'] | True |
test_relative_time | (mock_is_safe, hass) | Test relative_time method. | Test relative_time method. | def test_relative_time(mock_is_safe, hass):
"""Test relative_time method."""
now = datetime.strptime("2000-01-01 10:00:00 +00:00", "%Y-%m-%d %H:%M:%S %z")
with patch("homeassistant.util.dt.now", return_value=now):
result = template.Template(
'{{relative_time(strptime("2000-01-01 09:00:00... | [
"def",
"test_relative_time",
"(",
"mock_is_safe",
",",
"hass",
")",
":",
"now",
"=",
"datetime",
".",
"strptime",
"(",
"\"2000-01-01 10:00:00 +00:00\"",
",",
"\"%Y-%m-%d %H:%M:%S %z\"",
")",
"with",
"patch",
"(",
"\"homeassistant.util.dt.now\"",
",",
"return_value",
"... | [
913,
0
] | [
948,
33
] | python | en | ['en', 'en', 'en'] | True |
test_timedelta | (mock_is_safe, hass) | Test relative_time method. | Test relative_time method. | def test_timedelta(mock_is_safe, hass):
"""Test relative_time method."""
now = datetime.strptime("2000-01-01 10:00:00 +00:00", "%Y-%m-%d %H:%M:%S %z")
with patch("homeassistant.util.dt.now", return_value=now):
result = template.Template(
"{{timedelta(seconds=120)}}",
hass,
... | [
"def",
"test_timedelta",
"(",
"mock_is_safe",
",",
"hass",
")",
":",
"now",
"=",
"datetime",
".",
"strptime",
"(",
"\"2000-01-01 10:00:00 +00:00\"",
",",
"\"%Y-%m-%d %H:%M:%S %z\"",
")",
"with",
"patch",
"(",
"\"homeassistant.util.dt.now\"",
",",
"return_value",
"=",
... | [
955,
0
] | [
998,
34
] | python | en | ['en', 'en', 'en'] | True |
test_regex_match | (hass) | Test regex_match method. | Test regex_match method. | def test_regex_match(hass):
"""Test regex_match method."""
tpl = template.Template(
r"""
{{ '123-456-7890' | regex_match('(\\d{3})-(\\d{3})-(\\d{4})') }}
""",
hass,
)
assert tpl.async_render() is True
tpl = template.Template(
"""
{{ 'Home Assistant test' | regex_... | [
"def",
"test_regex_match",
"(",
"hass",
")",
":",
"tpl",
"=",
"template",
".",
"Template",
"(",
"r\"\"\"\n{{ '123-456-7890' | regex_match('(\\\\d{3})-(\\\\d{3})-(\\\\d{4})') }}\n \"\"\"",
",",
"hass",
",",
")",
"assert",
"tpl",
".",
"async_render",
"(",
")",
... | [
1001,
0
] | [
1033,
37
] | python | de | ['de', 'de', 'en'] | True |
test_match_test | (hass) | Test match test. | Test match test. | def test_match_test(hass):
"""Test match test."""
tpl = template.Template(
r"""
{{ '123-456-7890' is match('(\\d{3})-(\\d{3})-(\\d{4})') }}
""",
hass,
)
assert tpl.async_render() is True | [
"def",
"test_match_test",
"(",
"hass",
")",
":",
"tpl",
"=",
"template",
".",
"Template",
"(",
"r\"\"\"\n{{ '123-456-7890' is match('(\\\\d{3})-(\\\\d{3})-(\\\\d{4})') }}\n \"\"\"",
",",
"hass",
",",
")",
"assert",
"tpl",
".",
"async_render",
"(",
")",
"is",
... | [
1036,
0
] | [
1044,
37
] | python | en | ['en', 'lb', 'en'] | True |
test_regex_search | (hass) | Test regex_search method. | Test regex_search method. | def test_regex_search(hass):
"""Test regex_search method."""
tpl = template.Template(
r"""
{{ '123-456-7890' | regex_search('(\\d{3})-(\\d{3})-(\\d{4})') }}
""",
hass,
)
assert tpl.async_render() is True
tpl = template.Template(
"""
{{ 'Home Assistant test' | reg... | [
"def",
"test_regex_search",
"(",
"hass",
")",
":",
"tpl",
"=",
"template",
".",
"Template",
"(",
"r\"\"\"\n{{ '123-456-7890' | regex_search('(\\\\d{3})-(\\\\d{3})-(\\\\d{4})') }}\n \"\"\"",
",",
"hass",
",",
")",
"assert",
"tpl",
".",
"async_render",
"(",
")",
... | [
1047,
0
] | [
1079,
37
] | python | cy | ['de', 'cy', 'en'] | False |
test_search_test | (hass) | Test search test. | Test search test. | def test_search_test(hass):
"""Test search test."""
tpl = template.Template(
r"""
{{ '123-456-7890' is search('(\\d{3})-(\\d{3})-(\\d{4})') }}
""",
hass,
)
assert tpl.async_render() is True | [
"def",
"test_search_test",
"(",
"hass",
")",
":",
"tpl",
"=",
"template",
".",
"Template",
"(",
"r\"\"\"\n{{ '123-456-7890' is search('(\\\\d{3})-(\\\\d{3})-(\\\\d{4})') }}\n \"\"\"",
",",
"hass",
",",
")",
"assert",
"tpl",
".",
"async_render",
"(",
")",
"is"... | [
1082,
0
] | [
1090,
37
] | python | en | ['en', 'en', 'en'] | True |
test_regex_replace | (hass) | Test regex_replace method. | Test regex_replace method. | def test_regex_replace(hass):
"""Test regex_replace method."""
tpl = template.Template(
r"""
{{ 'Hello World' | regex_replace('(Hello\\s)',) }}
""",
hass,
)
assert tpl.async_render() == "World"
tpl = template.Template(
"""
{{ ['Home hinderant test'] | regex_repla... | [
"def",
"test_regex_replace",
"(",
"hass",
")",
":",
"tpl",
"=",
"template",
".",
"Template",
"(",
"r\"\"\"\n{{ 'Hello World' | regex_replace('(Hello\\\\s)',) }}\n \"\"\"",
",",
"hass",
",",
")",
"assert",
"tpl",
".",
"async_render",
"(",
")",
"==",
"\"World... | [
1093,
0
] | [
1109,
56
] | python | en | ['nl', 'la', 'en'] | False |
test_regex_findall | (hass) | Test regex_findall method. | Test regex_findall method. | def test_regex_findall(hass):
"""Test regex_findall method."""
tpl = template.Template(
"""
{{ 'Flight from JFK to LHR' | regex_findall('([A-Z]{3})') }}
""",
hass,
)
assert tpl.async_render() == ["JFK", "LHR"] | [
"def",
"test_regex_findall",
"(",
"hass",
")",
":",
"tpl",
"=",
"template",
".",
"Template",
"(",
"\"\"\"\n{{ 'Flight from JFK to LHR' | regex_findall('([A-Z]{3})') }}\n \"\"\"",
",",
"hass",
",",
")",
"assert",
"tpl",
".",
"async_render",
"(",
")",
"==",
"... | [
1112,
0
] | [
1120,
47
] | python | de | ['sv', 'de', 'en'] | False |
test_regex_findall_index | (hass) | Test regex_findall_index method. | Test regex_findall_index method. | def test_regex_findall_index(hass):
"""Test regex_findall_index method."""
tpl = template.Template(
"""
{{ 'Flight from JFK to LHR' | regex_findall_index('([A-Z]{3})', 0) }}
""",
hass,
)
assert tpl.async_render() == "JFK"
tpl = template.Template(
"""
{{ 'Flight f... | [
"def",
"test_regex_findall_index",
"(",
"hass",
")",
":",
"tpl",
"=",
"template",
".",
"Template",
"(",
"\"\"\"\n{{ 'Flight from JFK to LHR' | regex_findall_index('([A-Z]{3})', 0) }}\n \"\"\"",
",",
"hass",
",",
")",
"assert",
"tpl",
".",
"async_render",
"(",
"... | [
1123,
0
] | [
1147,
38
] | python | de | ['nl', 'de', 'en'] | False |
test_bitwise_and | (hass) | Test bitwise_and method. | Test bitwise_and method. | def test_bitwise_and(hass):
"""Test bitwise_and method."""
tpl = template.Template(
"""
{{ 8 | bitwise_and(8) }}
""",
hass,
)
assert tpl.async_render() == 8 & 8
tpl = template.Template(
"""
{{ 10 | bitwise_and(2) }}
""",
hass,
)
assert ... | [
"def",
"test_bitwise_and",
"(",
"hass",
")",
":",
"tpl",
"=",
"template",
".",
"Template",
"(",
"\"\"\"\n{{ 8 | bitwise_and(8) }}\n \"\"\"",
",",
"hass",
",",
")",
"assert",
"tpl",
".",
"async_render",
"(",
")",
"==",
"8",
"&",
"8",
"tpl",
"=",
"t... | [
1150,
0
] | [
1172,
38
] | python | en | ['en', 'en', 'en'] | True |
test_bitwise_or | (hass) | Test bitwise_or method. | Test bitwise_or method. | def test_bitwise_or(hass):
"""Test bitwise_or method."""
tpl = template.Template(
"""
{{ 8 | bitwise_or(8) }}
""",
hass,
)
assert tpl.async_render() == 8 | 8
tpl = template.Template(
"""
{{ 10 | bitwise_or(2) }}
""",
hass,
)
assert tpl.... | [
"def",
"test_bitwise_or",
"(",
"hass",
")",
":",
"tpl",
"=",
"template",
".",
"Template",
"(",
"\"\"\"\n{{ 8 | bitwise_or(8) }}\n \"\"\"",
",",
"hass",
",",
")",
"assert",
"tpl",
".",
"async_render",
"(",
")",
"==",
"8",
"|",
"8",
"tpl",
"=",
"tem... | [
1175,
0
] | [
1197,
38
] | python | en | ['en', 'en', 'en'] | True |
test_distance_function_with_1_state | (hass) | Test distance function with 1 state. | Test distance function with 1 state. | def test_distance_function_with_1_state(hass):
"""Test distance function with 1 state."""
_set_up_units(hass)
hass.states.async_set(
"test.object", "happy", {"latitude": 32.87336, "longitude": -117.22943}
)
tpl = template.Template("{{ distance(states.test.object) | round }}", hass)
asser... | [
"def",
"test_distance_function_with_1_state",
"(",
"hass",
")",
":",
"_set_up_units",
"(",
"hass",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.object\"",
",",
"\"happy\"",
",",
"{",
"\"latitude\"",
":",
"32.87336",
",",
"\"longitude\"",
":",
"-",
... | [
1200,
0
] | [
1207,
36
] | python | en | ['en', 'en', 'en'] | True |
test_distance_function_with_2_states | (hass) | Test distance function with 2 states. | Test distance function with 2 states. | def test_distance_function_with_2_states(hass):
"""Test distance function with 2 states."""
_set_up_units(hass)
hass.states.async_set(
"test.object", "happy", {"latitude": 32.87336, "longitude": -117.22943}
)
hass.states.async_set(
"test.object_2",
"happy",
{"latitude... | [
"def",
"test_distance_function_with_2_states",
"(",
"hass",
")",
":",
"_set_up_units",
"(",
"hass",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.object\"",
",",
"\"happy\"",
",",
"{",
"\"latitude\"",
":",
"32.87336",
",",
"\"longitude\"",
":",
"-",... | [
1210,
0
] | [
1224,
36
] | python | en | ['en', 'en', 'en'] | True |
test_distance_function_with_1_coord | (hass) | Test distance function with 1 coord. | Test distance function with 1 coord. | def test_distance_function_with_1_coord(hass):
"""Test distance function with 1 coord."""
_set_up_units(hass)
tpl = template.Template('{{ distance("32.87336", "-117.22943") | round }}', hass)
assert tpl.async_render() == 187 | [
"def",
"test_distance_function_with_1_coord",
"(",
"hass",
")",
":",
"_set_up_units",
"(",
"hass",
")",
"tpl",
"=",
"template",
".",
"Template",
"(",
"'{{ distance(\"32.87336\", \"-117.22943\") | round }}'",
",",
"hass",
")",
"assert",
"tpl",
".",
"async_render",
"(",... | [
1227,
0
] | [
1231,
36
] | python | en | ['en', 'en', 'en'] | True |
test_distance_function_with_2_coords | (hass) | Test distance function with 2 coords. | Test distance function with 2 coords. | def test_distance_function_with_2_coords(hass):
"""Test distance function with 2 coords."""
_set_up_units(hass)
assert (
template.Template(
'{{ distance("32.87336", "-117.22943", %s, %s) | round }}'
% (hass.config.latitude, hass.config.longitude),
hass,
).... | [
"def",
"test_distance_function_with_2_coords",
"(",
"hass",
")",
":",
"_set_up_units",
"(",
"hass",
")",
"assert",
"(",
"template",
".",
"Template",
"(",
"'{{ distance(\"32.87336\", \"-117.22943\", %s, %s) | round }}'",
"%",
"(",
"hass",
".",
"config",
".",
"latitude",
... | [
1234,
0
] | [
1244,
5
] | python | en | ['en', 'en', 'en'] | True |
test_distance_function_with_1_state_1_coord | (hass) | Test distance function with 1 state 1 coord. | Test distance function with 1 state 1 coord. | def test_distance_function_with_1_state_1_coord(hass):
"""Test distance function with 1 state 1 coord."""
_set_up_units(hass)
hass.states.async_set(
"test.object_2",
"happy",
{"latitude": hass.config.latitude, "longitude": hass.config.longitude},
)
tpl = template.Template(
... | [
"def",
"test_distance_function_with_1_state_1_coord",
"(",
"hass",
")",
":",
"_set_up_units",
"(",
"hass",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.object_2\"",
",",
"\"happy\"",
",",
"{",
"\"latitude\"",
":",
"hass",
".",
"config",
".",
"latit... | [
1247,
0
] | [
1265,
37
] | python | en | ['en', 'en', 'en'] | True |
test_distance_function_return_none_if_invalid_state | (hass) | Test distance function return None if invalid state. | Test distance function return None if invalid state. | def test_distance_function_return_none_if_invalid_state(hass):
"""Test distance function return None if invalid state."""
hass.states.async_set("test.object_2", "happy", {"latitude": 10})
tpl = template.Template("{{ distance(states.test.object_2) | round }}", hass)
assert tpl.async_render() is None | [
"def",
"test_distance_function_return_none_if_invalid_state",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.object_2\"",
",",
"\"happy\"",
",",
"{",
"\"latitude\"",
":",
"10",
"}",
")",
"tpl",
"=",
"template",
".",
"Template",
"(",... | [
1268,
0
] | [
1272,
37
] | python | en | ['fr', 'en', 'en'] | True |
test_distance_function_return_none_if_invalid_coord | (hass) | Test distance function return None if invalid coord. | Test distance function return None if invalid coord. | def test_distance_function_return_none_if_invalid_coord(hass):
"""Test distance function return None if invalid coord."""
assert (
template.Template('{{ distance("123", "abc") }}', hass).async_render() is None
)
assert template.Template('{{ distance("123") }}', hass).async_render() is None
... | [
"def",
"test_distance_function_return_none_if_invalid_coord",
"(",
"hass",
")",
":",
"assert",
"(",
"template",
".",
"Template",
"(",
"'{{ distance(\"123\", \"abc\") }}'",
",",
"hass",
")",
".",
"async_render",
"(",
")",
"is",
"None",
")",
"assert",
"template",
".",... | [
1275,
0
] | [
1289,
37
] | python | en | ['fr', 'en', 'en'] | True |
test_distance_function_with_2_entity_ids | (hass) | Test distance function with 2 entity ids. | Test distance function with 2 entity ids. | def test_distance_function_with_2_entity_ids(hass):
"""Test distance function with 2 entity ids."""
_set_up_units(hass)
hass.states.async_set(
"test.object", "happy", {"latitude": 32.87336, "longitude": -117.22943}
)
hass.states.async_set(
"test.object_2",
"happy",
{"... | [
"def",
"test_distance_function_with_2_entity_ids",
"(",
"hass",
")",
":",
"_set_up_units",
"(",
"hass",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.object\"",
",",
"\"happy\"",
",",
"{",
"\"latitude\"",
":",
"32.87336",
",",
"\"longitude\"",
":",
... | [
1292,
0
] | [
1306,
36
] | python | en | ['en', 'en', 'en'] | True |
test_distance_function_with_1_entity_1_coord | (hass) | Test distance function with 1 entity_id and 1 coord. | Test distance function with 1 entity_id and 1 coord. | def test_distance_function_with_1_entity_1_coord(hass):
"""Test distance function with 1 entity_id and 1 coord."""
_set_up_units(hass)
hass.states.async_set(
"test.object",
"happy",
{"latitude": hass.config.latitude, "longitude": hass.config.longitude},
)
tpl = template.Templ... | [
"def",
"test_distance_function_with_1_entity_1_coord",
"(",
"hass",
")",
":",
"_set_up_units",
"(",
"hass",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.object\"",
",",
"\"happy\"",
",",
"{",
"\"latitude\"",
":",
"hass",
".",
"config",
".",
"latitu... | [
1309,
0
] | [
1320,
36
] | python | en | ['en', 'en', 'en'] | True |
test_closest_function_home_vs_domain | (hass) | Test closest function home vs domain. | Test closest function home vs domain. | def test_closest_function_home_vs_domain(hass):
"""Test closest function home vs domain."""
hass.states.async_set(
"test_domain.object",
"happy",
{
"latitude": hass.config.latitude + 0.1,
"longitude": hass.config.longitude + 0.1,
},
)
hass.states.... | [
"def",
"test_closest_function_home_vs_domain",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test_domain.object\"",
",",
"\"happy\"",
",",
"{",
"\"latitude\"",
":",
"hass",
".",
"config",
".",
"latitude",
"+",
"0.1",
",",
"\"longitude\"... | [
1323,
0
] | [
1352,
5
] | python | en | ['fr', 'en', 'en'] | True |
test_closest_function_home_vs_all_states | (hass) | Test closest function home vs all states. | Test closest function home vs all states. | def test_closest_function_home_vs_all_states(hass):
"""Test closest function home vs all states."""
hass.states.async_set(
"test_domain.object",
"happy",
{
"latitude": hass.config.latitude + 0.1,
"longitude": hass.config.longitude + 0.1,
},
)
hass... | [
"def",
"test_closest_function_home_vs_all_states",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test_domain.object\"",
",",
"\"happy\"",
",",
"{",
"\"latitude\"",
":",
"hass",
".",
"config",
".",
"latitude",
"+",
"0.1",
",",
"\"longitu... | [
1355,
0
] | [
1380,
5
] | python | en | ['en', 'en', 'en'] | True |
test_closest_function_home_vs_group_entity_id | (hass) | Test closest function home vs group entity id. | Test closest function home vs group entity id. | async def test_closest_function_home_vs_group_entity_id(hass):
"""Test closest function home vs group entity id."""
hass.states.async_set(
"test_domain.object",
"happy",
{
"latitude": hass.config.latitude + 0.1,
"longitude": hass.config.longitude + 0.1,
},... | [
"async",
"def",
"test_closest_function_home_vs_group_entity_id",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test_domain.object\"",
",",
"\"happy\"",
",",
"{",
"\"latitude\"",
":",
"hass",
".",
"config",
".",
"latitude",
"+",
"0.1",
"... | [
1383,
0
] | [
1408,
34
] | python | en | ['en', 'en', 'en'] | True |
test_closest_function_home_vs_group_state | (hass) | Test closest function home vs group state. | Test closest function home vs group state. | async def test_closest_function_home_vs_group_state(hass):
"""Test closest function home vs group state."""
hass.states.async_set(
"test_domain.object",
"happy",
{
"latitude": hass.config.latitude + 0.1,
"longitude": hass.config.longitude + 0.1,
},
)
... | [
"async",
"def",
"test_closest_function_home_vs_group_state",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test_domain.object\"",
",",
"\"happy\"",
",",
"{",
"\"latitude\"",
":",
"hass",
".",
"config",
".",
"latitude",
"+",
"0.1",
",",
... | [
1411,
0
] | [
1442,
34
] | python | en | ['en', 'en', 'en'] | True |
test_expand | (hass) | Test expand function. | Test expand function. | async def test_expand(hass):
"""Test expand function."""
info = render_to_info(hass, "{{ expand('test.object') }}")
assert_result_info(info, [], ["test.object"])
assert info.rate_limit is None
info = render_to_info(hass, "{{ expand(56) }}")
assert_result_info(info, [])
assert info.rate_limi... | [
"async",
"def",
"test_expand",
"(",
"hass",
")",
":",
"info",
"=",
"render_to_info",
"(",
"hass",
",",
"\"{{ expand('test.object') }}\"",
")",
"assert_result_info",
"(",
"info",
",",
"[",
"]",
",",
"[",
"\"test.object\"",
"]",
")",
"assert",
"info",
".",
"ra... | [
1445,
0
] | [
1527,
34
] | python | en | ['en', 'en', 'en'] | True |
test_device_entities | (hass) | Test device_entities function. | Test device_entities function. | async def test_device_entities(hass):
"""Test device_entities function."""
config_entry = MockConfigEntry(domain="light")
device_registry = mock_device_registry(hass)
entity_registry = mock_registry(hass)
# Test non existing device ids
info = render_to_info(hass, "{{ device_entities('abc123') }... | [
"async",
"def",
"test_device_entities",
"(",
"hass",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"light\"",
")",
"device_registry",
"=",
"mock_device_registry",
"(",
"hass",
")",
"entity_registry",
"=",
"mock_registry",
"(",
"hass",
")"... | [
1530,
0
] | [
1600,
34
] | python | en | ['fr', 'en', 'en'] | True |
test_device_id | (hass) | Test device_id function. | Test device_id function. | async def test_device_id(hass):
"""Test device_id function."""
config_entry = MockConfigEntry(domain="light")
device_registry = mock_device_registry(hass)
entity_registry = mock_registry(hass)
device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
... | [
"async",
"def",
"test_device_id",
"(",
"hass",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"light\"",
")",
"device_registry",
"=",
"mock_device_registry",
"(",
"hass",
")",
"entity_registry",
"=",
"mock_registry",
"(",
"hass",
")",
"d... | [
1603,
0
] | [
1643,
34
] | python | en | ['da', 'en', 'en'] | True |
test_device_attr | (hass) | Test device_attr and is_device_attr functions. | Test device_attr and is_device_attr functions. | async def test_device_attr(hass):
"""Test device_attr and is_device_attr functions."""
config_entry = MockConfigEntry(domain="light")
device_registry = mock_device_registry(hass)
entity_registry = mock_registry(hass)
# Test non existing device ids (device_attr)
info = render_to_info(hass, "{{ d... | [
"async",
"def",
"test_device_attr",
"(",
"hass",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"light\"",
")",
"device_registry",
"=",
"mock_device_registry",
"(",
"hass",
")",
"entity_registry",
"=",
"mock_registry",
"(",
"hass",
")",
... | [
1646,
0
] | [
1748,
34
] | python | en | ['en', 'en', 'en'] | True |
test_area_id | (hass) | Test area_id function. | Test area_id function. | async def test_area_id(hass):
"""Test area_id function."""
config_entry = MockConfigEntry(domain="light")
device_registry = mock_device_registry(hass)
entity_registry = mock_registry(hass)
area_registry = mock_area_registry(hass)
# Test non existing entity id
info = render_to_info(hass, "{{... | [
"async",
"def",
"test_area_id",
"(",
"hass",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"light\"",
")",
"device_registry",
"=",
"mock_device_registry",
"(",
"hass",
")",
"entity_registry",
"=",
"mock_registry",
"(",
"hass",
")",
"are... | [
1751,
0
] | [
1852,
34
] | python | en | ['en', 'en', 'en'] | True |
test_area_name | (hass) | Test area_name function. | Test area_name function. | async def test_area_name(hass):
"""Test area_name function."""
config_entry = MockConfigEntry(domain="light")
device_registry = mock_device_registry(hass)
entity_registry = mock_registry(hass)
area_registry = mock_area_registry(hass)
# Test non existing entity id
info = render_to_info(hass,... | [
"async",
"def",
"test_area_name",
"(",
"hass",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"light\"",
")",
"device_registry",
"=",
"mock_device_registry",
"(",
"hass",
")",
"entity_registry",
"=",
"mock_registry",
"(",
"hass",
")",
"a... | [
1855,
0
] | [
1931,
34
] | python | en | ['en', 'en', 'en'] | True |
test_closest_function_to_coord | (hass) | Test closest function to coord. | Test closest function to coord. | def test_closest_function_to_coord(hass):
"""Test closest function to coord."""
hass.states.async_set(
"test_domain.closest_home",
"happy",
{
"latitude": hass.config.latitude + 0.1,
"longitude": hass.config.longitude + 0.1,
},
)
hass.states.async_... | [
"def",
"test_closest_function_to_coord",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test_domain.closest_home\"",
",",
"\"happy\"",
",",
"{",
"\"latitude\"",
":",
"hass",
".",
"config",
".",
"latitude",
"+",
"0.1",
",",
"\"longitude\"... | [
1934,
0
] | [
1977,
59
] | python | en | ['en', 'en', 'en'] | True |
test_async_render_to_info_with_branching | (hass) | Test async_render_to_info function by domain. | Test async_render_to_info function by domain. | def test_async_render_to_info_with_branching(hass):
"""Test async_render_to_info function by domain."""
hass.states.async_set("light.a", "off")
hass.states.async_set("light.b", "on")
hass.states.async_set("light.c", "off")
info = render_to_info(
hass,
"""
{% if states.light.a == "on... | [
"def",
"test_async_render_to_info_with_branching",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"light.a\"",
",",
"\"off\"",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"light.b\"",
",",
"\"on\"",
")",
"hass",
".",
"states",
... | [
1980,
0
] | [
2009,
34
] | python | en | ['en', 'en', 'en'] | True |
test_async_render_to_info_with_complex_branching | (hass) | Test async_render_to_info function by domain. | Test async_render_to_info function by domain. | def test_async_render_to_info_with_complex_branching(hass):
"""Test async_render_to_info function by domain."""
hass.states.async_set("light.a", "off")
hass.states.async_set("light.b", "on")
hass.states.async_set("light.c", "off")
hass.states.async_set("vacuum.a", "off")
hass.states.async_set("d... | [
"def",
"test_async_render_to_info_with_complex_branching",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"light.a\"",
",",
"\"off\"",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"light.b\"",
",",
"\"on\"",
")",
"hass",
".",
"s... | [
2012,
0
] | [
2046,
63
] | python | en | ['en', 'en', 'en'] | True |
test_async_render_to_info_with_wildcard_matching_entity_id | (hass) | Test tracking template with a wildcard. | Test tracking template with a wildcard. | async def test_async_render_to_info_with_wildcard_matching_entity_id(hass):
"""Test tracking template with a wildcard."""
template_complex_str = r"""
{% for state in states.cover %}
{% if state.entity_id | regex_match('.*\.office_') %}
{{ state.entity_id }}={{ state.state }}
{% endif %}
{% endfor %}
"... | [
"async",
"def",
"test_async_render_to_info_with_wildcard_matching_entity_id",
"(",
"hass",
")",
":",
"template_complex_str",
"=",
"r\"\"\"\n\n{% for state in states.cover %}\n {% if state.entity_id | regex_match('.*\\.office_') %}\n {{ state.entity_id }}={{ state.state }}\n {% endif %}\n{% en... | [
2049,
0
] | [
2068,
63
] | python | en | ['en', 'en', 'en'] | True |
test_async_render_to_info_with_wildcard_matching_state | (hass) | Test tracking template with a wildcard. | Test tracking template with a wildcard. | async def test_async_render_to_info_with_wildcard_matching_state(hass):
"""Test tracking template with a wildcard."""
template_complex_str = """
{% for state in states %}
{% if state.state | regex_match('ope.*') %}
{{ state.entity_id }}={{ state.state }}
{% endif %}
{% endfor %}
"""
hass.states.as... | [
"async",
"def",
"test_async_render_to_info_with_wildcard_matching_state",
"(",
"hass",
")",
":",
"template_complex_str",
"=",
"\"\"\"\n\n{% for state in states %}\n {% if state.state | regex_match('ope.*') %}\n {{ state.entity_id }}={{ state.state }}\n {% endif %}\n{% endfor %}\n\n\"\"\"",
... | [
2071,
0
] | [
2119,
63
] | python | en | ['en', 'en', 'en'] | True |
test_nested_async_render_to_info_case | (hass) | Test a deeply nested state with async_render_to_info. | Test a deeply nested state with async_render_to_info. | def test_nested_async_render_to_info_case(hass):
"""Test a deeply nested state with async_render_to_info."""
hass.states.async_set("input_select.picker", "vacuum.a")
hass.states.async_set("vacuum.a", "off")
info = render_to_info(
hass, "{{ states[states['input_select.picker'].state].state }}",... | [
"def",
"test_nested_async_render_to_info_case",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"input_select.picker\"",
",",
"\"vacuum.a\"",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"vacuum.a\"",
",",
"\"off\"",
")",
"info",
"... | [
2122,
0
] | [
2132,
34
] | python | en | ['en', 'en', 'en'] | True |
test_result_as_boolean | (hass) | Test converting a template result to a boolean. | Test converting a template result to a boolean. | def test_result_as_boolean(hass):
"""Test converting a template result to a boolean."""
assert template.result_as_boolean(True) is True
assert template.result_as_boolean(" 1 ") is True
assert template.result_as_boolean(" true ") is True
assert template.result_as_boolean(" TrUE ") is True
assert... | [
"def",
"test_result_as_boolean",
"(",
"hass",
")",
":",
"assert",
"template",
".",
"result_as_boolean",
"(",
"True",
")",
"is",
"True",
"assert",
"template",
".",
"result_as_boolean",
"(",
"\" 1 \"",
")",
"is",
"True",
"assert",
"template",
".",
"result_as_boole... | [
2135,
0
] | [
2162,
52
] | python | en | ['en', 'en', 'en'] | True |
test_closest_function_to_entity_id | (hass) | Test closest function to entity id. | Test closest function to entity id. | def test_closest_function_to_entity_id(hass):
"""Test closest function to entity id."""
hass.states.async_set(
"test_domain.closest_home",
"happy",
{
"latitude": hass.config.latitude + 0.1,
"longitude": hass.config.longitude + 0.1,
},
)
hass.state... | [
"def",
"test_closest_function_to_entity_id",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test_domain.closest_home\"",
",",
"\"happy\"",
",",
"{",
"\"latitude\"",
":",
"hass",
".",
"config",
".",
"latitude",
"+",
"0.1",
",",
"\"longitu... | [
2165,
0
] | [
2219,
5
] | python | en | ['en', 'en', 'en'] | True |
test_closest_function_to_state | (hass) | Test closest function to state. | Test closest function to state. | def test_closest_function_to_state(hass):
"""Test closest function to state."""
hass.states.async_set(
"test_domain.closest_home",
"happy",
{
"latitude": hass.config.latitude + 0.1,
"longitude": hass.config.longitude + 0.1,
},
)
hass.states.async_... | [
"def",
"test_closest_function_to_state",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test_domain.closest_home\"",
",",
"\"happy\"",
",",
"{",
"\"latitude\"",
":",
"hass",
".",
"config",
".",
"latitude",
"+",
"0.1",
",",
"\"longitude\"... | [
2222,
0
] | [
2256,
5
] | python | en | ['en', 'en', 'en'] | True |
test_closest_function_invalid_state | (hass) | Test closest function invalid state. | Test closest function invalid state. | def test_closest_function_invalid_state(hass):
"""Test closest function invalid state."""
hass.states.async_set(
"test_domain.closest_home",
"happy",
{
"latitude": hass.config.latitude + 0.1,
"longitude": hass.config.longitude + 0.1,
},
)
for stat... | [
"def",
"test_closest_function_invalid_state",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test_domain.closest_home\"",
",",
"\"happy\"",
",",
"{",
"\"latitude\"",
":",
"hass",
".",
"config",
".",
"latitude",
"+",
"0.1",
",",
"\"longit... | [
2259,
0
] | [
2274,
9
] | python | en | ['en', 'en', 'en'] | True |
test_closest_function_state_with_invalid_location | (hass) | Test closest function state with invalid location. | Test closest function state with invalid location. | def test_closest_function_state_with_invalid_location(hass):
"""Test closest function state with invalid location."""
hass.states.async_set(
"test_domain.closest_home",
"happy",
{"latitude": "invalid latitude", "longitude": hass.config.longitude + 0.1},
)
assert (
templa... | [
"def",
"test_closest_function_state_with_invalid_location",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test_domain.closest_home\"",
",",
"\"happy\"",
",",
"{",
"\"latitude\"",
":",
"\"invalid latitude\"",
",",
"\"longitude\"",
":",
"hass",
... | [
2277,
0
] | [
2290,
5
] | python | en | ['en', 'en', 'en'] | True |
test_closest_function_invalid_coordinates | (hass) | Test closest function invalid coordinates. | Test closest function invalid coordinates. | def test_closest_function_invalid_coordinates(hass):
"""Test closest function invalid coordinates."""
hass.states.async_set(
"test_domain.closest_home",
"happy",
{
"latitude": hass.config.latitude + 0.1,
"longitude": hass.config.longitude + 0.1,
},
)
... | [
"def",
"test_closest_function_invalid_coordinates",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test_domain.closest_home\"",
",",
"\"happy\"",
",",
"{",
"\"latitude\"",
":",
"hass",
".",
"config",
".",
"latitude",
"+",
"0.1",
",",
"\"... | [
2293,
0
] | [
2315,
5
] | python | en | ['en', 'en', 'en'] | True |
test_closest_function_no_location_states | (hass) | Test closest function without location states. | Test closest function without location states. | def test_closest_function_no_location_states(hass):
"""Test closest function without location states."""
assert (
template.Template("{{ closest(states).entity_id }}", hass).async_render() == ""
) | [
"def",
"test_closest_function_no_location_states",
"(",
"hass",
")",
":",
"assert",
"(",
"template",
".",
"Template",
"(",
"\"{{ closest(states).entity_id }}\"",
",",
"hass",
")",
".",
"async_render",
"(",
")",
"==",
"\"\"",
")"
] | [
2318,
0
] | [
2322,
5
] | python | en | ['en', 'en', 'en'] | True |
test_generate_filter_iterators | (hass) | Test extract entities function with none entities stuff. | Test extract entities function with none entities stuff. | def test_generate_filter_iterators(hass):
"""Test extract entities function with none entities stuff."""
info = render_to_info(
hass,
"""
{% for state in states %}
{{ state.entity_id }}
{% endfor %}
""",
)
assert_result_info(info, "", all_states=True)
... | [
"def",
"test_generate_filter_iterators",
"(",
"hass",
")",
":",
"info",
"=",
"render_to_info",
"(",
"hass",
",",
"\"\"\"\n {% for state in states %}\n {{ state.entity_id }}\n {% endfor %}\n \"\"\"",
",",
")",
"assert_result_info",
"(",
"info",
",",
"... | [
2325,
0
] | [
2379,
73
] | python | en | ['en', 'en', 'en'] | True |
test_generate_select | (hass) | Test extract entities function with none entities stuff. | Test extract entities function with none entities stuff. | def test_generate_select(hass):
"""Test extract entities function with none entities stuff."""
template_str = """
{{ states.sensor|selectattr("state","equalto","off")
|join(",", attribute="entity_id") }}
"""
tmp = template.Template(template_str, hass)
info = tmp.async_render_to_info()
asser... | [
"def",
"test_generate_select",
"(",
"hass",
")",
":",
"template_str",
"=",
"\"\"\"\n{{ states.sensor|selectattr(\"state\",\"equalto\",\"off\")\n|join(\",\", attribute=\"entity_id\") }}\n \"\"\"",
"tmp",
"=",
"template",
".",
"Template",
"(",
"template_str",
",",
"hass",
")... | [
2382,
0
] | [
2404,
47
] | python | en | ['en', 'en', 'en'] | True |
test_async_render_to_info_in_conditional | (hass) | Test extract entities function with none entities stuff. | Test extract entities function with none entities stuff. | async def test_async_render_to_info_in_conditional(hass):
"""Test extract entities function with none entities stuff."""
template_str = """
{{ states("sensor.xyz") == "dog" }}
"""
tmp = template.Template(template_str, hass)
info = tmp.async_render_to_info()
assert_result_info(info, False, [... | [
"async",
"def",
"test_async_render_to_info_in_conditional",
"(",
"hass",
")",
":",
"template_str",
"=",
"\"\"\"\n{{ states(\"sensor.xyz\") == \"dog\" }}\n \"\"\"",
"tmp",
"=",
"template",
".",
"Template",
"(",
"template_str",
",",
"hass",
")",
"info",
"=",
"tmp",
... | [
2407,
0
] | [
2440,
70
] | python | en | ['en', 'en', 'en'] | True |
test_jinja_namespace | (hass) | Test Jinja's namespace command can be used. | Test Jinja's namespace command can be used. | def test_jinja_namespace(hass):
"""Test Jinja's namespace command can be used."""
test_template = template.Template(
(
"{% set ns = namespace(a_key='') %}"
"{% set ns.a_key = states.sensor.dummy.state %}"
"{{ ns.a_key }}"
),
hass,
)
hass.state... | [
"def",
"test_jinja_namespace",
"(",
"hass",
")",
":",
"test_template",
"=",
"template",
".",
"Template",
"(",
"(",
"\"{% set ns = namespace(a_key='') %}\"",
"\"{% set ns.a_key = states.sensor.dummy.state %}\"",
"\"{{ ns.a_key }}\"",
")",
",",
"hass",
",",
")",
"hass",
"."... | [
2443,
0
] | [
2458,
58
] | python | en | ['en', 'en', 'en'] | True |
test_state_with_unit | (hass) | Test the state_with_unit property helper. | Test the state_with_unit property helper. | def test_state_with_unit(hass):
"""Test the state_with_unit property helper."""
hass.states.async_set("sensor.test", "23", {ATTR_UNIT_OF_MEASUREMENT: "beers"})
hass.states.async_set("sensor.test2", "wow")
tpl = template.Template("{{ states.sensor.test.state_with_unit }}", hass)
assert tpl.async_re... | [
"def",
"test_state_with_unit",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"sensor.test\"",
",",
"\"23\"",
",",
"{",
"ATTR_UNIT_OF_MEASUREMENT",
":",
"\"beers\"",
"}",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"sensor.test... | [
2461,
0
] | [
2482,
35
] | python | en | ['en', 'en', 'en'] | True |
test_length_of_states | (hass) | Test fetching the length of states. | Test fetching the length of states. | def test_length_of_states(hass):
"""Test fetching the length of states."""
hass.states.async_set("sensor.test", "23")
hass.states.async_set("sensor.test2", "wow")
hass.states.async_set("climate.test2", "cooling")
tpl = template.Template("{{ states | length }}", hass)
assert tpl.async_render() =... | [
"def",
"test_length_of_states",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"sensor.test\"",
",",
"\"23\"",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"sensor.test2\"",
",",
"\"wow\"",
")",
"hass",
".",
"states",
".",
"... | [
2485,
0
] | [
2495,
34
] | python | en | ['en', 'en', 'en'] | True |
test_render_complex_handling_non_template_values | (hass) | Test that we can render non-template fields. | Test that we can render non-template fields. | def test_render_complex_handling_non_template_values(hass):
"""Test that we can render non-template fields."""
assert template.render_complex(
{True: 1, False: template.Template("{{ hello }}", hass)}, {"hello": 2}
) == {True: 1, False: 2} | [
"def",
"test_render_complex_handling_non_template_values",
"(",
"hass",
")",
":",
"assert",
"template",
".",
"render_complex",
"(",
"{",
"True",
":",
"1",
",",
"False",
":",
"template",
".",
"Template",
"(",
"\"{{ hello }}\"",
",",
"hass",
")",
"}",
",",
"{",
... | [
2498,
0
] | [
2502,
28
] | python | en | ['en', 'en', 'en'] | True |
test_urlencode | (hass) | Test the urlencode method. | Test the urlencode method. | def test_urlencode(hass):
"""Test the urlencode method."""
tpl = template.Template(
("{% set dict = {'foo': 'x&y', 'bar': 42} %}" "{{ dict | urlencode }}"),
hass,
)
assert tpl.async_render() == "foo=x%26y&bar=42"
tpl = template.Template(
("{% set string = 'the quick brown fox... | [
"def",
"test_urlencode",
"(",
"hass",
")",
":",
"tpl",
"=",
"template",
".",
"Template",
"(",
"(",
"\"{% set dict = {'foo': 'x&y', 'bar': 42} %}\"",
"\"{{ dict | urlencode }}\"",
")",
",",
"hass",
",",
")",
"assert",
"tpl",
".",
"async_render",
"(",
")",
"==",
"... | [
2505,
0
] | [
2516,
73
] | python | en | ['en', 'et', 'en'] | True |
test_cache_garbage_collection | () | Test caching a template. | Test caching a template. | async def test_cache_garbage_collection():
"""Test caching a template."""
template_string = (
"{% set dict = {'foo': 'x&y', 'bar': 42} %} {{ dict | urlencode }}"
)
tpl = template.Template(
(template_string),
)
tpl.ensure_valid()
assert template._NO_HASS_ENV.template_cache.get... | [
"async",
"def",
"test_cache_garbage_collection",
"(",
")",
":",
"template_string",
"=",
"(",
"\"{% set dict = {'foo': 'x&y', 'bar': 42} %} {{ dict | urlencode }}\"",
")",
"tpl",
"=",
"template",
".",
"Template",
"(",
"(",
"template_string",
")",
",",
")",
"tpl",
".",
... | [
2519,
0
] | [
2547,
5
] | python | en | ['en', 'en', 'en'] | True |
test_is_template_string | () | Test is template string. | Test is template string. | def test_is_template_string():
"""Test is template string."""
assert template.is_template_string("{{ x }}") is True
assert template.is_template_string("{% if x == 2 %}1{% else %}0{%end if %}") is True
assert template.is_template_string("{# a comment #} Hey") is True
assert template.is_template_strin... | [
"def",
"test_is_template_string",
"(",
")",
":",
"assert",
"template",
".",
"is_template_string",
"(",
"\"{{ x }}\"",
")",
"is",
"True",
"assert",
"template",
".",
"is_template_string",
"(",
"\"{% if x == 2 %}1{% else %}0{%end if %}\"",
")",
"is",
"True",
"assert",
"t... | [
2550,
0
] | [
2556,
60
] | python | en | ['en', 'en', 'en'] | True |
test_protected_blocked | (hass) | Test accessing __getattr__ produces a template error. | Test accessing __getattr__ produces a template error. | async def test_protected_blocked(hass):
"""Test accessing __getattr__ produces a template error."""
tmp = template.Template('{{ states.__getattr__("any") }}', hass)
with pytest.raises(TemplateError):
tmp.async_render()
tmp = template.Template('{{ states.sensor.__getattr__("any") }}', hass)
... | [
"async",
"def",
"test_protected_blocked",
"(",
"hass",
")",
":",
"tmp",
"=",
"template",
".",
"Template",
"(",
"'{{ states.__getattr__(\"any\") }}'",
",",
"hass",
")",
"with",
"pytest",
".",
"raises",
"(",
"TemplateError",
")",
":",
"tmp",
".",
"async_render",
... | [
2559,
0
] | [
2571,
26
] | python | en | ['en', 'en', 'en'] | True |
test_demo_template | (hass) | Test the demo template works as expected. | Test the demo template works as expected. | async def test_demo_template(hass):
"""Test the demo template works as expected."""
hass.states.async_set("sun.sun", "above", {"elevation": 50, "next_rising": "later"})
for i in range(2):
hass.states.async_set(f"sensor.sensor{i}", "on")
demo_template_str = """
{## Imitate available variables: #... | [
"async",
"def",
"test_demo_template",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"sun.sun\"",
",",
"\"above\"",
",",
"{",
"\"elevation\"",
":",
"50",
",",
"\"next_rising\"",
":",
"\"later\"",
"}",
")",
"for",
"i",
"in",
"range",... | [
2574,
0
] | [
2610,
26
] | python | en | ['en', 'en', 'en'] | True |
test_slice_states | (hass) | Test iterating states with a slice. | Test iterating states with a slice. | async def test_slice_states(hass):
"""Test iterating states with a slice."""
hass.states.async_set("sensor.test", "23")
tpl = template.Template(
"{% for states in states | slice(1) -%}{% set state = states | first %}{{ state.entity_id }}{%- endfor %}",
hass,
)
assert tpl.async_rende... | [
"async",
"def",
"test_slice_states",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"sensor.test\"",
",",
"\"23\"",
")",
"tpl",
"=",
"template",
".",
"Template",
"(",
"\"{% for states in states | slice(1) -%}{% set state = states | first %}{{ sta... | [
2613,
0
] | [
2621,
46
] | python | en | ['en', 'en', 'en'] | True |
test_lifecycle | (hass) | Test that we limit template render info for lifecycle events. | Test that we limit template render info for lifecycle events. | async def test_lifecycle(hass):
"""Test that we limit template render info for lifecycle events."""
hass.states.async_set("sun.sun", "above", {"elevation": 50, "next_rising": "later"})
for i in range(2):
hass.states.async_set(f"sensor.sensor{i}", "on")
hass.states.async_set("sensor.removed", "of... | [
"async",
"def",
"test_lifecycle",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"sun.sun\"",
",",
"\"above\"",
",",
"{",
"\"elevation\"",
":",
"50",
",",
"\"next_rising\"",
":",
"\"later\"",
"}",
")",
"for",
"i",
"in",
"range",
"... | [
2624,
0
] | [
2657,
58
] | python | en | ['en', 'en', 'en'] | True |
test_template_timeout | (hass) | Test to see if a template will timeout. | Test to see if a template will timeout. | async def test_template_timeout(hass):
"""Test to see if a template will timeout."""
for i in range(2):
hass.states.async_set(f"sensor.sensor{i}", "on")
tmp = template.Template("{{ states | count }}", hass)
assert await tmp.async_render_will_timeout(3) is False
tmp3 = template.Template("st... | [
"async",
"def",
"test_template_timeout",
"(",
"hass",
")",
":",
"for",
"i",
"in",
"range",
"(",
"2",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"f\"sensor.sensor{i}\"",
",",
"\"on\"",
")",
"tmp",
"=",
"template",
".",
"Template",
"(",
"\"{{ ... | [
2660,
0
] | [
2682,
65
] | python | en | ['en', 'en', 'en'] | True |
test_template_timeout_raise | (hass) | Test we can raise from. | Test we can raise from. | async def test_template_timeout_raise(hass):
"""Test we can raise from."""
tmp2 = template.Template("{{ error_invalid + 1 }}", hass)
with pytest.raises(TemplateError):
assert await tmp2.async_render_will_timeout(3) is False | [
"async",
"def",
"test_template_timeout_raise",
"(",
"hass",
")",
":",
"tmp2",
"=",
"template",
".",
"Template",
"(",
"\"{{ error_invalid + 1 }}\"",
",",
"hass",
")",
"with",
"pytest",
".",
"raises",
"(",
"TemplateError",
")",
":",
"assert",
"await",
"tmp2",
".... | [
2685,
0
] | [
2689,
63
] | python | en | ['en', 'en', 'en'] | True |
test_lights | (hass) | Test we can sort lights. | Test we can sort lights. | async def test_lights(hass):
"""Test we can sort lights."""
tmpl = """
{% set lights_on = states.light|selectattr('state','eq','on')|map(attribute='name')|list %}
{% if lights_on|length == 0 %}
No lights on. Sleep well..
{% elif lights_on|length == 1 %}
The... | [
"async",
"def",
"test_lights",
"(",
"hass",
")",
":",
"tmpl",
"=",
"\"\"\"\n {% set lights_on = states.light|selectattr('state','eq','on')|map(attribute='name')|list %}\n {% if lights_on|length == 0 %}\n No lights on. Sleep well..\n {% elif lights_on|length ==... | [
2692,
0
] | [
2719,
44
] | python | en | ['en', 'da', 'en'] | True |
test_template_errors | (hass) | Test template rendering wraps exceptions with TemplateError. | Test template rendering wraps exceptions with TemplateError. | async def test_template_errors(hass):
"""Test template rendering wraps exceptions with TemplateError."""
with pytest.raises(TemplateError):
template.Template("{{ now() | rando }}", hass).async_render()
with pytest.raises(TemplateError):
template.Template("{{ utcnow() | rando }}", hass).asy... | [
"async",
"def",
"test_template_errors",
"(",
"hass",
")",
":",
"with",
"pytest",
".",
"raises",
"(",
"TemplateError",
")",
":",
"template",
".",
"Template",
"(",
"\"{{ now() | rando }}\"",
",",
"hass",
")",
".",
"async_render",
"(",
")",
"with",
"pytest",
".... | [
2722,
0
] | [
2735,
73
] | python | en | ['en', 'en', 'en'] | True |
test_state_attributes | (hass) | Test state attributes. | Test state attributes. | async def test_state_attributes(hass):
"""Test state attributes."""
hass.states.async_set("sensor.test", "23")
tpl = template.Template(
"{{ states.sensor.test.last_changed }}",
hass,
)
assert tpl.async_render() == str(hass.states.get("sensor.test").last_changed)
tpl = template.... | [
"async",
"def",
"test_state_attributes",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"sensor.test\"",
",",
"\"23\"",
")",
"tpl",
"=",
"template",
".",
"Template",
"(",
"\"{{ states.sensor.test.last_changed }}\"",
",",
"hass",
",",
")",... | [
2738,
0
] | [
2783,
26
] | python | en | ['en', 'en', 'en'] | True |
test_unavailable_states | (hass) | Test watching unavailable states. | Test watching unavailable states. | async def test_unavailable_states(hass):
"""Test watching unavailable states."""
for i in range(10):
hass.states.async_set(f"light.sensor{i}", "on")
hass.states.async_set("light.unavailable", "unavailable")
hass.states.async_set("light.unknown", "unknown")
hass.states.async_set("light.none... | [
"async",
"def",
"test_unavailable_states",
"(",
"hass",
")",
":",
"for",
"i",
"in",
"range",
"(",
"10",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"f\"light.sensor{i}\"",
",",
"\"on\"",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"l... | [
2786,
0
] | [
2806,
79
] | python | en | ['en', 'en', 'en'] | True |
test_legacy_templates | (hass) | Test if old template behavior works when legacy templates are enabled. | Test if old template behavior works when legacy templates are enabled. | async def test_legacy_templates(hass):
"""Test if old template behavior works when legacy templates are enabled."""
hass.states.async_set("sensor.temperature", "12")
assert (
template.Template("{{ states.sensor.temperature.state }}", hass).async_render()
== 12
)
await async_process... | [
"async",
"def",
"test_legacy_templates",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"sensor.temperature\"",
",",
"\"12\"",
")",
"assert",
"(",
"template",
".",
"Template",
"(",
"\"{{ states.sensor.temperature.state }}\"",
",",
"hass",
"... | [
2809,
0
] | [
2822,
5
] | python | en | ['en', 'en', 'en'] | True |
test_no_result_parsing | (hass) | Test if templates results are not parsed. | Test if templates results are not parsed. | async def test_no_result_parsing(hass):
"""Test if templates results are not parsed."""
hass.states.async_set("sensor.temperature", "12")
assert (
template.Template("{{ states.sensor.temperature.state }}", hass).async_render(
parse_result=False
)
== "12"
)
asser... | [
"async",
"def",
"test_no_result_parsing",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"sensor.temperature\"",
",",
"\"12\"",
")",
"assert",
"(",
"template",
".",
"Template",
"(",
"\"{{ states.sensor.temperature.state }}\"",
",",
"hass",
... | [
2825,
0
] | [
2844,
5
] | python | en | ['en', 'en', 'en'] | True |
test_is_static_still_ast_evals | (hass) | Test is_static still converts to native type. | Test is_static still converts to native type. | async def test_is_static_still_ast_evals(hass):
"""Test is_static still converts to native type."""
tpl = template.Template("[1, 2]", hass)
assert tpl.is_static
assert tpl.async_render() == [1, 2] | [
"async",
"def",
"test_is_static_still_ast_evals",
"(",
"hass",
")",
":",
"tpl",
"=",
"template",
".",
"Template",
"(",
"\"[1, 2]\"",
",",
"hass",
")",
"assert",
"tpl",
".",
"is_static",
"assert",
"tpl",
".",
"async_render",
"(",
")",
"==",
"[",
"1",
",",
... | [
2847,
0
] | [
2851,
39
] | python | en | ['en', 'en', 'en'] | True |
test_result_wrappers | (hass) | Test result wrappers. | Test result wrappers. | async def test_result_wrappers(hass):
"""Test result wrappers."""
for text, native, orig_type, schema in (
("[1, 2]", [1, 2], list, vol.Schema([int])),
("{1, 2}", {1, 2}, set, vol.Schema({int})),
("(1, 2)", (1, 2), tuple, vol.ExactSequence([int, int])),
('{"hello": True}', {"hell... | [
"async",
"def",
"test_result_wrappers",
"(",
"hass",
")",
":",
"for",
"text",
",",
"native",
",",
"orig_type",
",",
"schema",
"in",
"(",
"(",
"\"[1, 2]\"",
",",
"[",
"1",
",",
"2",
"]",
",",
"list",
",",
"vol",
".",
"Schema",
"(",
"[",
"int",
"]",
... | [
2854,
0
] | [
2874,
9
] | python | en | ['en', 'en', 'en'] | True |
test_parse_result | (hass) | Test parse result. | Test parse result. | async def test_parse_result(hass):
"""Test parse result."""
for tpl, result in (
('{{ "{{}}" }}', "{{}}"),
("not-something", "not-something"),
("2a", "2a"),
("123E5", "123E5"),
("1j", "1j"),
("1e+100", "1e+100"),
("0xface", "0xface"),
("123", 123),... | [
"async",
"def",
"test_parse_result",
"(",
"hass",
")",
":",
"for",
"tpl",
",",
"result",
"in",
"(",
"(",
"'{{ \"{{}}\" }}'",
",",
"\"{{}}\"",
")",
",",
"(",
"\"not-something\"",
",",
"\"not-something\"",
")",
",",
"(",
"\"2a\"",
",",
"\"2a\"",
")",
",",
... | [
2877,
0
] | [
2901,
68
] | python | de | ['fr', 'de', 'en'] | False |
test_undefined_variable | (hass, caplog) | Test a warning is logged on undefined variables. | Test a warning is logged on undefined variables. | async def test_undefined_variable(hass, caplog):
"""Test a warning is logged on undefined variables."""
tpl = template.Template("{{ no_such_variable }}", hass)
assert tpl.async_render() == ""
assert (
"Template variable warning: 'no_such_variable' is undefined when rendering '{{ no_such_variable... | [
"async",
"def",
"test_undefined_variable",
"(",
"hass",
",",
"caplog",
")",
":",
"tpl",
"=",
"template",
".",
"Template",
"(",
"\"{{ no_such_variable }}\"",
",",
"hass",
")",
"assert",
"tpl",
".",
"async_render",
"(",
")",
"==",
"\"\"",
"assert",
"(",
"\"Tem... | [
2904,
0
] | [
2911,
5
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, entry, async_add_entities) | Set up Velbus cover based on config_entry. | Set up Velbus cover based on config_entry. | async def async_setup_entry(hass, entry, async_add_entities):
"""Set up Velbus cover based on config_entry."""
cntrl = hass.data[DOMAIN][entry.entry_id]["cntrl"]
modules_data = hass.data[DOMAIN][entry.entry_id]["cover"]
entities = []
for address, channel in modules_data:
module = cntrl.get_m... | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"entry",
",",
"async_add_entities",
")",
":",
"cntrl",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"[",
"\"cntrl\"",
"]",
"modules_data",
"=",
"hass",
".",
"data... | [
20,
0
] | [
28,
32
] | python | en | ['en', 'en', 'en'] | True |
VelbusCover.supported_features | (self) | Flag supported features. | Flag supported features. | def supported_features(self):
"""Flag supported features."""
if self._module.support_position():
return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP | SUPPORT_SET_POSITION
return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP | [
"def",
"supported_features",
"(",
"self",
")",
":",
"if",
"self",
".",
"_module",
".",
"support_position",
"(",
")",
":",
"return",
"SUPPORT_OPEN",
"|",
"SUPPORT_CLOSE",
"|",
"SUPPORT_STOP",
"|",
"SUPPORT_SET_POSITION",
"return",
"SUPPORT_OPEN",
"|",
"SUPPORT_CLOS... | [
35,
4
] | [
39,
58
] | python | en | ['da', 'en', 'en'] | True |
VelbusCover.is_closed | (self) | Return if the cover is closed. | Return if the cover is closed. | def is_closed(self):
"""Return if the cover is closed."""
if self._module.get_position(self._channel) == 100:
return True
return False | [
"def",
"is_closed",
"(",
"self",
")",
":",
"if",
"self",
".",
"_module",
".",
"get_position",
"(",
"self",
".",
"_channel",
")",
"==",
"100",
":",
"return",
"True",
"return",
"False"
] | [
42,
4
] | [
46,
20
] | python | en | ['en', 'en', 'en'] | True |
VelbusCover.current_cover_position | (self) | Return current position of cover.
None is unknown, 0 is closed, 100 is fully open
Velbus: 100 = closed, 0 = open
| Return current position of cover. | def current_cover_position(self):
"""Return current position of cover.
None is unknown, 0 is closed, 100 is fully open
Velbus: 100 = closed, 0 = open
"""
pos = self._module.get_position(self._channel)
return 100 - pos | [
"def",
"current_cover_position",
"(",
"self",
")",
":",
"pos",
"=",
"self",
".",
"_module",
".",
"get_position",
"(",
"self",
".",
"_channel",
")",
"return",
"100",
"-",
"pos"
] | [
49,
4
] | [
56,
24
] | python | en | ['en', 'en', 'en'] | True |
VelbusCover.open_cover | (self, **kwargs) | Open the cover. | Open the cover. | def open_cover(self, **kwargs):
"""Open the cover."""
try:
self._module.open(self._channel)
except VelbusException as err:
_LOGGER.error("A Velbus error occurred: %s", err) | [
"def",
"open_cover",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"self",
".",
"_module",
".",
"open",
"(",
"self",
".",
"_channel",
")",
"except",
"VelbusException",
"as",
"err",
":",
"_LOGGER",
".",
"error",
"(",
"\"A Velbus error occurr... | [
58,
4
] | [
63,
61
] | python | en | ['en', 'en', 'en'] | True |
VelbusCover.close_cover | (self, **kwargs) | Close the cover. | Close the cover. | def close_cover(self, **kwargs):
"""Close the cover."""
try:
self._module.close(self._channel)
except VelbusException as err:
_LOGGER.error("A Velbus error occurred: %s", err) | [
"def",
"close_cover",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"self",
".",
"_module",
".",
"close",
"(",
"self",
".",
"_channel",
")",
"except",
"VelbusException",
"as",
"err",
":",
"_LOGGER",
".",
"error",
"(",
"\"A Velbus error occu... | [
65,
4
] | [
70,
61
] | python | en | ['en', 'en', 'en'] | True |
VelbusCover.stop_cover | (self, **kwargs) | Stop the cover. | Stop the cover. | def stop_cover(self, **kwargs):
"""Stop the cover."""
try:
self._module.stop(self._channel)
except VelbusException as err:
_LOGGER.error("A Velbus error occurred: %s", err) | [
"def",
"stop_cover",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"self",
".",
"_module",
".",
"stop",
"(",
"self",
".",
"_channel",
")",
"except",
"VelbusException",
"as",
"err",
":",
"_LOGGER",
".",
"error",
"(",
"\"A Velbus error occurr... | [
72,
4
] | [
77,
61
] | python | en | ['en', 'en', 'en'] | True |
VelbusCover.set_cover_position | (self, **kwargs) | Move the cover to a specific position. | Move the cover to a specific position. | def set_cover_position(self, **kwargs):
"""Move the cover to a specific position."""
try:
self._module.set(self._channel, (100 - kwargs[ATTR_POSITION]))
except VelbusException as err:
_LOGGER.error("A Velbus error occurred: %s", err) | [
"def",
"set_cover_position",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"self",
".",
"_module",
".",
"set",
"(",
"self",
".",
"_channel",
",",
"(",
"100",
"-",
"kwargs",
"[",
"ATTR_POSITION",
"]",
")",
")",
"except",
"VelbusException",... | [
79,
4
] | [
84,
61
] | python | en | ['en', 'en', 'en'] | True |
test_switch_simple | (hass: HomeAssistant, knx: KNXTestKit) | Test simple KNX switch. | Test simple KNX switch. | async def test_switch_simple(hass: HomeAssistant, knx: KNXTestKit):
"""Test simple KNX switch."""
await knx.setup_integration(
{
SwitchSchema.PLATFORM_NAME: {
CONF_NAME: "test",
KNX_ADDRESS: "1/2/3",
}
}
)
assert len(hass.states.asy... | [
"async",
"def",
"test_switch_simple",
"(",
"hass",
":",
"HomeAssistant",
",",
"knx",
":",
"KNXTestKit",
")",
":",
"await",
"knx",
".",
"setup_integration",
"(",
"{",
"SwitchSchema",
".",
"PLATFORM_NAME",
":",
"{",
"CONF_NAME",
":",
"\"test\"",
",",
"KNX_ADDRES... | [
15,
0
] | [
51,
38
] | python | en | ['en', 'pl', 'en'] | True |
test_switch_state | (hass: HomeAssistant, knx: KNXTestKit) | Test KNX switch with state_address. | Test KNX switch with state_address. | async def test_switch_state(hass: HomeAssistant, knx: KNXTestKit):
"""Test KNX switch with state_address."""
_ADDRESS = "1/1/1"
_STATE_ADDRESS = "2/2/2"
await knx.setup_integration(
{
SwitchSchema.PLATFORM_NAME: {
CONF_NAME: "test",
KNX_ADDRESS: _ADDR... | [
"async",
"def",
"test_switch_state",
"(",
"hass",
":",
"HomeAssistant",
",",
"knx",
":",
"KNXTestKit",
")",
":",
"_ADDRESS",
"=",
"\"1/1/1\"",
"_STATE_ADDRESS",
"=",
"\"2/2/2\"",
"await",
"knx",
".",
"setup_integration",
"(",
"{",
"SwitchSchema",
".",
"PLATFORM_... | [
54,
0
] | [
110,
38
] | python | en | ['en', 'pl', 'en'] | True |
test_switch_restore_and_respond | (hass, knx) | Test restoring KNX switch state and respond to read. | Test restoring KNX switch state and respond to read. | async def test_switch_restore_and_respond(hass, knx):
"""Test restoring KNX switch state and respond to read."""
_ADDRESS = "1/1/1"
fake_state = State("switch.test", "on")
with patch(
"homeassistant.helpers.restore_state.RestoreEntity.async_get_last_state",
return_value=fake_state,
... | [
"async",
"def",
"test_switch_restore_and_respond",
"(",
"hass",
",",
"knx",
")",
":",
"_ADDRESS",
"=",
"\"1/1/1\"",
"fake_state",
"=",
"State",
"(",
"\"switch.test\"",
",",
"\"on\"",
")",
"with",
"patch",
"(",
"\"homeassistant.helpers.restore_state.RestoreEntity.async_g... | [
113,
0
] | [
151,
46
] | python | en | ['en', 'en', 'en'] | True |
TestIntegerEnumOneValue.testIntegerEnumOneValue | (self) | Test IntegerEnumOneValue | Test IntegerEnumOneValue | def testIntegerEnumOneValue(self):
"""Test IntegerEnumOneValue"""
model = IntegerEnumOneValue()
assert model.value == 0, "With only one option, the value is assigned automatically"
model = IntegerEnumOneValue(0)
assert model.value == 0, "We can also pass in the value as a positi... | [
"def",
"testIntegerEnumOneValue",
"(",
"self",
")",
":",
"model",
"=",
"IntegerEnumOneValue",
"(",
")",
"assert",
"model",
".",
"value",
"==",
"0",
",",
"\"With only one option, the value is assigned automatically\"",
"model",
"=",
"IntegerEnumOneValue",
"(",
"0",
")"... | [
28,
4
] | [
37,
84
] | python | de | ['de', 'et', 'ur'] | False |
mock_config_entry | () | Return a Ruckus Unleashed mock config entry. | Return a Ruckus Unleashed mock config entry. | def mock_config_entry() -> MockConfigEntry:
"""Return a Ruckus Unleashed mock config entry."""
return MockConfigEntry(
domain=DOMAIN,
title=DEFAULT_TITLE,
unique_id=DEFAULT_UNIQUE_ID,
data=CONFIG,
options=None,
) | [
"def",
"mock_config_entry",
"(",
")",
"->",
"MockConfigEntry",
":",
"return",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"title",
"=",
"DEFAULT_TITLE",
",",
"unique_id",
"=",
"DEFAULT_UNIQUE_ID",
",",
"data",
"=",
"CONFIG",
",",
"options",
"=",
"Non... | [
56,
0
] | [
64,
5
] | python | en | ['en', 'da', 'en'] | True |
init_integration | (hass) | Set up the Ruckus Unleashed integration in Home Assistant. | Set up the Ruckus Unleashed integration in Home Assistant. | async def init_integration(hass) -> MockConfigEntry:
"""Set up the Ruckus Unleashed integration in Home Assistant."""
entry = mock_config_entry()
with patch(
"homeassistant.components.ruckus_unleashed.Ruckus.connect",
return_value=None,
), patch(
"homeassistant.components.ruckus_... | [
"async",
"def",
"init_integration",
"(",
"hass",
")",
"->",
"MockConfigEntry",
":",
"entry",
"=",
"mock_config_entry",
"(",
")",
"with",
"patch",
"(",
"\"homeassistant.components.ruckus_unleashed.Ruckus.connect\"",
",",
"return_value",
"=",
"None",
",",
")",
",",
"p... | [
67,
0
] | [
92,
16
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass: HomeAssistant, entry: ConfigEntry) | Set up Kostal Plenticore Solar Inverter from a config entry. | Set up Kostal Plenticore Solar Inverter from a config entry. | async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Kostal Plenticore Solar Inverter from a config entry."""
hass.data.setdefault(DOMAIN, {})
plenticore = Plenticore(hass, entry)
if not await plenticore.async_setup():
return False
hass.data[DOMAIN][entr... | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"entry",
":",
"ConfigEntry",
")",
"->",
"bool",
":",
"hass",
".",
"data",
".",
"setdefault",
"(",
"DOMAIN",
",",
"{",
"}",
")",
"plenticore",
"=",
"Plenticore",
"(",
"hass",
","... | [
16,
0
] | [
29,
15
] | python | en | ['en', 'en', 'en'] | True |
async_unload_entry | (hass: HomeAssistant, entry: ConfigEntry) | Unload a config entry. | Unload a config entry. | async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
if unload_ok:
# remove API object
plenticore = hass.data[DOMAIN].pop(entry.entry_id)
try:
... | [
"async",
"def",
"async_unload_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"entry",
":",
"ConfigEntry",
")",
"->",
"bool",
":",
"unload_ok",
"=",
"await",
"hass",
".",
"config_entries",
".",
"async_unload_platforms",
"(",
"entry",
",",
"PLATFORMS",
")",
"if... | [
32,
0
] | [
43,
20
] | python | en | ['en', 'es', 'en'] | True |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.