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_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 %} """ hass.states.async_set("cover.office_drapes", "closed") hass.states.async_set("cover.office_window", "closed") hass.states.async_set("cover.office_skylight", "open") info = render_to_info(hass, template_complex_str) assert info.domains == {"cover"} assert info.entities == set() assert info.all_states is False assert info.rate_limit == template.DOMAIN_STATES_RATE_LIMIT
[ "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{% endfor %}\n\n\"\"\"", "hass", ".", "states", ".", "async_set", "(", "\"cover.office_drapes\"", ",", "\"closed\"", ")", "hass", ".", "states", ".", "async_set", "(", "\"cover.office_window\"", ",", "\"closed\"", ")", "hass", ".", "states", ".", "async_set", "(", "\"cover.office_skylight\"", ",", "\"open\"", ")", "info", "=", "render_to_info", "(", "hass", ",", "template_complex_str", ")", "assert", "info", ".", "domains", "==", "{", "\"cover\"", "}", "assert", "info", ".", "entities", "==", "set", "(", ")", "assert", "info", ".", "all_states", "is", "False", "assert", "info", ".", "rate_limit", "==", "template", ".", "DOMAIN_STATES_RATE_LIMIT" ]
[ 1588, 0 ]
[ 1607, 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.async_set("cover.office_drapes", "closed") hass.states.async_set("cover.office_window", "closed") hass.states.async_set("cover.office_skylight", "open") hass.states.async_set("cover.x_skylight", "open") hass.states.async_set("binary_sensor.door", "open") await hass.async_block_till_done() info = render_to_info(hass, template_complex_str) assert not info.domains assert info.entities == set() assert info.all_states is True assert info.rate_limit == template.ALL_STATES_RATE_LIMIT hass.states.async_set("binary_sensor.door", "closed") info = render_to_info(hass, template_complex_str) assert not info.domains assert info.entities == set() assert info.all_states is True assert info.rate_limit == template.ALL_STATES_RATE_LIMIT template_cover_str = """ {% for state in states.cover %} {% if state.state | regex_match('ope.*') %} {{ state.entity_id }}={{ state.state }} {% endif %} {% endfor %} """ hass.states.async_set("cover.x_skylight", "closed") info = render_to_info(hass, template_cover_str) assert info.domains == {"cover"} assert info.entities == set() assert info.all_states is False assert info.rate_limit == template.DOMAIN_STATES_RATE_LIMIT
[ "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\"\"\"", "hass", ".", "states", ".", "async_set", "(", "\"cover.office_drapes\"", ",", "\"closed\"", ")", "hass", ".", "states", ".", "async_set", "(", "\"cover.office_window\"", ",", "\"closed\"", ")", "hass", ".", "states", ".", "async_set", "(", "\"cover.office_skylight\"", ",", "\"open\"", ")", "hass", ".", "states", ".", "async_set", "(", "\"cover.x_skylight\"", ",", "\"open\"", ")", "hass", ".", "states", ".", "async_set", "(", "\"binary_sensor.door\"", ",", "\"open\"", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "info", "=", "render_to_info", "(", "hass", ",", "template_complex_str", ")", "assert", "not", "info", ".", "domains", "assert", "info", ".", "entities", "==", "set", "(", ")", "assert", "info", ".", "all_states", "is", "True", "assert", "info", ".", "rate_limit", "==", "template", ".", "ALL_STATES_RATE_LIMIT", "hass", ".", "states", ".", "async_set", "(", "\"binary_sensor.door\"", ",", "\"closed\"", ")", "info", "=", "render_to_info", "(", "hass", ",", "template_complex_str", ")", "assert", "not", "info", ".", "domains", "assert", "info", ".", "entities", "==", "set", "(", ")", "assert", "info", ".", "all_states", "is", "True", "assert", "info", ".", "rate_limit", "==", "template", ".", "ALL_STATES_RATE_LIMIT", "template_cover_str", "=", "\"\"\"\n\n{% for state in states.cover %}\n {% if state.state | regex_match('ope.*') %}\n {{ state.entity_id }}={{ state.state }}\n {% endif %}\n{% endfor %}\n\n\"\"\"", "hass", ".", "states", ".", "async_set", "(", "\"cover.x_skylight\"", ",", "\"closed\"", ")", "info", "=", "render_to_info", "(", "hass", ",", "template_cover_str", ")", "assert", "info", ".", "domains", "==", "{", "\"cover\"", "}", "assert", "info", ".", "entities", "==", "set", "(", ")", "assert", "info", ".", "all_states", "is", "False", "assert", "info", ".", "rate_limit", "==", "template", ".", "DOMAIN_STATES_RATE_LIMIT" ]
[ 1610, 0 ]
[ 1658, 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 }}", {} ) assert_result_info(info, "off", {"input_select.picker", "vacuum.a"}) assert info.rate_limit is None
[ "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", "=", "render_to_info", "(", "hass", ",", "\"{{ states[states['input_select.picker'].state].state }}\"", ",", "{", "}", ")", "assert_result_info", "(", "info", ",", "\"off\"", ",", "{", "\"input_select.picker\"", ",", "\"vacuum.a\"", "}", ")", "assert", "info", ".", "rate_limit", "is", "None" ]
[ 1661, 0 ]
[ 1671, 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 template.result_as_boolean(" YeS ") is True assert template.result_as_boolean(" On ") is True assert template.result_as_boolean(" Enable ") is True assert template.result_as_boolean(1) is True assert template.result_as_boolean(-1) is True assert template.result_as_boolean(500) is True assert template.result_as_boolean(0.5) is True assert template.result_as_boolean(0.389) is True assert template.result_as_boolean(35) is True assert template.result_as_boolean(False) is False assert template.result_as_boolean(" 0 ") is False assert template.result_as_boolean(" false ") is False assert template.result_as_boolean(" FaLsE ") is False assert template.result_as_boolean(" no ") is False assert template.result_as_boolean(" off ") is False assert template.result_as_boolean(" disable ") is False assert template.result_as_boolean(0) is False assert template.result_as_boolean(0.0) is False assert template.result_as_boolean("0.00") is False assert template.result_as_boolean(None) is False
[ "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_boolean", "(", "\" true \"", ")", "is", "True", "assert", "template", ".", "result_as_boolean", "(", "\" TrUE \"", ")", "is", "True", "assert", "template", ".", "result_as_boolean", "(", "\" YeS \"", ")", "is", "True", "assert", "template", ".", "result_as_boolean", "(", "\" On \"", ")", "is", "True", "assert", "template", ".", "result_as_boolean", "(", "\" Enable \"", ")", "is", "True", "assert", "template", ".", "result_as_boolean", "(", "1", ")", "is", "True", "assert", "template", ".", "result_as_boolean", "(", "-", "1", ")", "is", "True", "assert", "template", ".", "result_as_boolean", "(", "500", ")", "is", "True", "assert", "template", ".", "result_as_boolean", "(", "0.5", ")", "is", "True", "assert", "template", ".", "result_as_boolean", "(", "0.389", ")", "is", "True", "assert", "template", ".", "result_as_boolean", "(", "35", ")", "is", "True", "assert", "template", ".", "result_as_boolean", "(", "False", ")", "is", "False", "assert", "template", ".", "result_as_boolean", "(", "\" 0 \"", ")", "is", "False", "assert", "template", ".", "result_as_boolean", "(", "\" false \"", ")", "is", "False", "assert", "template", ".", "result_as_boolean", "(", "\" FaLsE \"", ")", "is", "False", "assert", "template", ".", "result_as_boolean", "(", "\" no \"", ")", "is", "False", "assert", "template", ".", "result_as_boolean", "(", "\" off \"", ")", "is", "False", "assert", "template", ".", "result_as_boolean", "(", "\" disable \"", ")", "is", "False", "assert", "template", ".", "result_as_boolean", "(", "0", ")", "is", "False", "assert", "template", ".", "result_as_boolean", "(", "0.0", ")", "is", "False", "assert", "template", ".", "result_as_boolean", "(", "\"0.00\"", ")", "is", "False", "assert", "template", ".", "result_as_boolean", "(", "None", ")", "is", "False" ]
[ 1674, 0 ]
[ 1701, 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.states.async_set( "test_domain.closest_zone", "happy", { "latitude": hass.config.latitude + 0.2, "longitude": hass.config.longitude + 0.2, }, ) hass.states.async_set( "zone.far_away", "zoning", { "latitude": hass.config.latitude + 0.3, "longitude": hass.config.longitude + 0.3, }, ) info = render_to_info( hass, "{{ closest(zone, states.test_domain).entity_id }}", {"zone": "zone.far_away"}, ) assert_result_info( info, "test_domain.closest_zone", ["test_domain.closest_home", "test_domain.closest_zone", "zone.far_away"], ["test_domain"], ) info = render_to_info( hass, "{{ ([states.test_domain, 'test_domain.closest_zone'] " "| closest(zone)).entity_id }}", {"zone": "zone.far_away"}, ) assert_result_info( info, "test_domain.closest_zone", ["test_domain.closest_home", "test_domain.closest_zone", "zone.far_away"], ["test_domain"], )
[ "def", "test_closest_function_to_entity_id", "(", "hass", ")", ":", "hass", ".", "states", ".", "async_set", "(", "\"test_domain.closest_home\"", ",", "\"happy\"", ",", "{", "\"latitude\"", ":", "hass", ".", "config", ".", "latitude", "+", "0.1", ",", "\"longitude\"", ":", "hass", ".", "config", ".", "longitude", "+", "0.1", ",", "}", ",", ")", "hass", ".", "states", ".", "async_set", "(", "\"test_domain.closest_zone\"", ",", "\"happy\"", ",", "{", "\"latitude\"", ":", "hass", ".", "config", ".", "latitude", "+", "0.2", ",", "\"longitude\"", ":", "hass", ".", "config", ".", "longitude", "+", "0.2", ",", "}", ",", ")", "hass", ".", "states", ".", "async_set", "(", "\"zone.far_away\"", ",", "\"zoning\"", ",", "{", "\"latitude\"", ":", "hass", ".", "config", ".", "latitude", "+", "0.3", ",", "\"longitude\"", ":", "hass", ".", "config", ".", "longitude", "+", "0.3", ",", "}", ",", ")", "info", "=", "render_to_info", "(", "hass", ",", "\"{{ closest(zone, states.test_domain).entity_id }}\"", ",", "{", "\"zone\"", ":", "\"zone.far_away\"", "}", ",", ")", "assert_result_info", "(", "info", ",", "\"test_domain.closest_zone\"", ",", "[", "\"test_domain.closest_home\"", ",", "\"test_domain.closest_zone\"", ",", "\"zone.far_away\"", "]", ",", "[", "\"test_domain\"", "]", ",", ")", "info", "=", "render_to_info", "(", "hass", ",", "\"{{ ([states.test_domain, 'test_domain.closest_zone'] \"", "\"| closest(zone)).entity_id }}\"", ",", "{", "\"zone\"", ":", "\"zone.far_away\"", "}", ",", ")", "assert_result_info", "(", "info", ",", "\"test_domain.closest_zone\"", ",", "[", "\"test_domain.closest_home\"", ",", "\"test_domain.closest_zone\"", ",", "\"zone.far_away\"", "]", ",", "[", "\"test_domain\"", "]", ",", ")" ]
[ 1704, 0 ]
[ 1758, 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_set( "test_domain.closest_zone", "happy", { "latitude": hass.config.latitude + 0.2, "longitude": hass.config.longitude + 0.2, }, ) hass.states.async_set( "zone.far_away", "zoning", { "latitude": hass.config.latitude + 0.3, "longitude": hass.config.longitude + 0.3, }, ) assert ( template.Template( "{{ closest(states.zone.far_away, states.test_domain).entity_id }}", hass ).async_render() == "test_domain.closest_zone" )
[ "def", "test_closest_function_to_state", "(", "hass", ")", ":", "hass", ".", "states", ".", "async_set", "(", "\"test_domain.closest_home\"", ",", "\"happy\"", ",", "{", "\"latitude\"", ":", "hass", ".", "config", ".", "latitude", "+", "0.1", ",", "\"longitude\"", ":", "hass", ".", "config", ".", "longitude", "+", "0.1", ",", "}", ",", ")", "hass", ".", "states", ".", "async_set", "(", "\"test_domain.closest_zone\"", ",", "\"happy\"", ",", "{", "\"latitude\"", ":", "hass", ".", "config", ".", "latitude", "+", "0.2", ",", "\"longitude\"", ":", "hass", ".", "config", ".", "longitude", "+", "0.2", ",", "}", ",", ")", "hass", ".", "states", ".", "async_set", "(", "\"zone.far_away\"", ",", "\"zoning\"", ",", "{", "\"latitude\"", ":", "hass", ".", "config", ".", "latitude", "+", "0.3", ",", "\"longitude\"", ":", "hass", ".", "config", ".", "longitude", "+", "0.3", ",", "}", ",", ")", "assert", "(", "template", ".", "Template", "(", "\"{{ closest(states.zone.far_away, states.test_domain).entity_id }}\"", ",", "hass", ")", ".", "async_render", "(", ")", "==", "\"test_domain.closest_zone\"", ")" ]
[ 1761, 0 ]
[ 1795, 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 state in ("states.zone.non_existing", '"zone.non_existing"'): assert ( template.Template("{{ closest(%s, states) }}" % state, hass).async_render() is None )
[ "def", "test_closest_function_invalid_state", "(", "hass", ")", ":", "hass", ".", "states", ".", "async_set", "(", "\"test_domain.closest_home\"", ",", "\"happy\"", ",", "{", "\"latitude\"", ":", "hass", ".", "config", ".", "latitude", "+", "0.1", ",", "\"longitude\"", ":", "hass", ".", "config", ".", "longitude", "+", "0.1", ",", "}", ",", ")", "for", "state", "in", "(", "\"states.zone.non_existing\"", ",", "'\"zone.non_existing\"'", ")", ":", "assert", "(", "template", ".", "Template", "(", "\"{{ closest(%s, states) }}\"", "%", "state", ",", "hass", ")", ".", "async_render", "(", ")", "is", "None", ")" ]
[ 1798, 0 ]
[ 1813, 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 ( template.Template( "{{ closest(states.test_domain.closest_home, states) }}", hass ).async_render() is None )
[ "def", "test_closest_function_state_with_invalid_location", "(", "hass", ")", ":", "hass", ".", "states", ".", "async_set", "(", "\"test_domain.closest_home\"", ",", "\"happy\"", ",", "{", "\"latitude\"", ":", "\"invalid latitude\"", ",", "\"longitude\"", ":", "hass", ".", "config", ".", "longitude", "+", "0.1", "}", ",", ")", "assert", "(", "template", ".", "Template", "(", "\"{{ closest(states.test_domain.closest_home, states) }}\"", ",", "hass", ")", ".", "async_render", "(", ")", "is", "None", ")" ]
[ 1816, 0 ]
[ 1829, 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, }, ) assert ( template.Template( '{{ closest("invalid", "coord", states) }}', hass ).async_render() is None ) assert ( template.Template( '{{ states | closest("invalid", "coord") }}', hass ).async_render() is None )
[ "def", "test_closest_function_invalid_coordinates", "(", "hass", ")", ":", "hass", ".", "states", ".", "async_set", "(", "\"test_domain.closest_home\"", ",", "\"happy\"", ",", "{", "\"latitude\"", ":", "hass", ".", "config", ".", "latitude", "+", "0.1", ",", "\"longitude\"", ":", "hass", ".", "config", ".", "longitude", "+", "0.1", ",", "}", ",", ")", "assert", "(", "template", ".", "Template", "(", "'{{ closest(\"invalid\", \"coord\", states) }}'", ",", "hass", ")", ".", "async_render", "(", ")", "is", "None", ")", "assert", "(", "template", ".", "Template", "(", "'{{ states | closest(\"invalid\", \"coord\") }}'", ",", "hass", ")", ".", "async_render", "(", ")", "is", "None", ")" ]
[ 1832, 0 ]
[ 1854, 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", "(", ")", "==", "\"\"", ")" ]
[ 1857, 0 ]
[ 1861, 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) info = render_to_info( hass, """ {% for state in states.sensor %} {{ state.entity_id }} {% endfor %} """, ) assert_result_info(info, "", domains=["sensor"]) hass.states.async_set("sensor.test_sensor", "off", {"attr": "value"}) # Don't need the entity because the state is not accessed info = render_to_info( hass, """ {% for state in states.sensor %} {{ state.entity_id }} {% endfor %} """, ) assert_result_info(info, "sensor.test_sensor", domains=["sensor"]) # But we do here because the state gets accessed info = render_to_info( hass, """ {% for state in states.sensor %} {{ state.entity_id }}={{ state.state }}, {% endfor %} """, ) assert_result_info(info, "sensor.test_sensor=off,", [], ["sensor"]) info = render_to_info( hass, """ {% for state in states.sensor %} {{ state.entity_id }}={{ state.attributes.attr }}, {% endfor %} """, ) assert_result_info(info, "sensor.test_sensor=value,", [], ["sensor"])
[ "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", ",", "\"\"", ",", "all_states", "=", "True", ")", "info", "=", "render_to_info", "(", "hass", ",", "\"\"\"\n {% for state in states.sensor %}\n {{ state.entity_id }}\n {% endfor %}\n \"\"\"", ",", ")", "assert_result_info", "(", "info", ",", "\"\"", ",", "domains", "=", "[", "\"sensor\"", "]", ")", "hass", ".", "states", ".", "async_set", "(", "\"sensor.test_sensor\"", ",", "\"off\"", ",", "{", "\"attr\"", ":", "\"value\"", "}", ")", "# Don't need the entity because the state is not accessed", "info", "=", "render_to_info", "(", "hass", ",", "\"\"\"\n {% for state in states.sensor %}\n {{ state.entity_id }}\n {% endfor %}\n \"\"\"", ",", ")", "assert_result_info", "(", "info", ",", "\"sensor.test_sensor\"", ",", "domains", "=", "[", "\"sensor\"", "]", ")", "# But we do here because the state gets accessed", "info", "=", "render_to_info", "(", "hass", ",", "\"\"\"\n {% for state in states.sensor %}\n {{ state.entity_id }}={{ state.state }},\n {% endfor %}\n \"\"\"", ",", ")", "assert_result_info", "(", "info", ",", "\"sensor.test_sensor=off,\"", ",", "[", "]", ",", "[", "\"sensor\"", "]", ")", "info", "=", "render_to_info", "(", "hass", ",", "\"\"\"\n {% for state in states.sensor %}\n {{ state.entity_id }}={{ state.attributes.attr }},\n {% endfor %}\n \"\"\"", ",", ")", "assert_result_info", "(", "info", ",", "\"sensor.test_sensor=value,\"", ",", "[", "]", ",", "[", "\"sensor\"", "]", ")" ]
[ 1864, 0 ]
[ 1918, 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() assert_result_info(info, "", [], []) assert info.domains_lifecycle == {"sensor"} hass.states.async_set("sensor.test_sensor", "off", {"attr": "value"}) hass.states.async_set("sensor.test_sensor_on", "on") info = tmp.async_render_to_info() assert_result_info( info, "sensor.test_sensor", [], ["sensor"], ) assert info.domains_lifecycle == {"sensor"}
[ "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", ")", "info", "=", "tmp", ".", "async_render_to_info", "(", ")", "assert_result_info", "(", "info", ",", "\"\"", ",", "[", "]", ",", "[", "]", ")", "assert", "info", ".", "domains_lifecycle", "==", "{", "\"sensor\"", "}", "hass", ".", "states", ".", "async_set", "(", "\"sensor.test_sensor\"", ",", "\"off\"", ",", "{", "\"attr\"", ":", "\"value\"", "}", ")", "hass", ".", "states", ".", "async_set", "(", "\"sensor.test_sensor_on\"", ",", "\"on\"", ")", "info", "=", "tmp", ".", "async_render_to_info", "(", ")", "assert_result_info", "(", "info", ",", "\"sensor.test_sensor\"", ",", "[", "]", ",", "[", "\"sensor\"", "]", ",", ")", "assert", "info", ".", "domains_lifecycle", "==", "{", "\"sensor\"", "}" ]
[ 1921, 0 ]
[ 1943, 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, ["sensor.xyz"], []) hass.states.async_set("sensor.xyz", "dog") hass.states.async_set("sensor.cow", "True") await hass.async_block_till_done() template_str = """ {% if states("sensor.xyz") == "dog" %} {{ states("sensor.cow") }} {% else %} {{ states("sensor.pig") }} {% endif %} """ tmp = template.Template(template_str, hass) info = tmp.async_render_to_info() assert_result_info(info, True, ["sensor.xyz", "sensor.cow"], []) hass.states.async_set("sensor.xyz", "sheep") hass.states.async_set("sensor.pig", "oink") await hass.async_block_till_done() tmp = template.Template(template_str, hass) info = tmp.async_render_to_info() assert_result_info(info, "oink", ["sensor.xyz", "sensor.pig"], [])
[ "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", ".", "async_render_to_info", "(", ")", "assert_result_info", "(", "info", ",", "False", ",", "[", "\"sensor.xyz\"", "]", ",", "[", "]", ")", "hass", ".", "states", ".", "async_set", "(", "\"sensor.xyz\"", ",", "\"dog\"", ")", "hass", ".", "states", ".", "async_set", "(", "\"sensor.cow\"", ",", "\"True\"", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "template_str", "=", "\"\"\"\n{% if states(\"sensor.xyz\") == \"dog\" %}\n {{ states(\"sensor.cow\") }}\n{% else %}\n {{ states(\"sensor.pig\") }}\n{% endif %}\n \"\"\"", "tmp", "=", "template", ".", "Template", "(", "template_str", ",", "hass", ")", "info", "=", "tmp", ".", "async_render_to_info", "(", ")", "assert_result_info", "(", "info", ",", "True", ",", "[", "\"sensor.xyz\"", ",", "\"sensor.cow\"", "]", ",", "[", "]", ")", "hass", ".", "states", ".", "async_set", "(", "\"sensor.xyz\"", ",", "\"sheep\"", ")", "hass", ".", "states", ".", "async_set", "(", "\"sensor.pig\"", ",", "\"oink\"", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "tmp", "=", "template", ".", "Template", "(", "template_str", ",", "hass", ")", "info", "=", "tmp", ".", "async_render_to_info", "(", ")", "assert_result_info", "(", "info", ",", "\"oink\"", ",", "[", "\"sensor.xyz\"", ",", "\"sensor.pig\"", "]", ",", "[", "]", ")" ]
[ 1946, 0 ]
[ 1979, 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.states.async_set("sensor.dummy", "a value") assert test_template.async_render() == "a value" hass.states.async_set("sensor.dummy", "another value") assert test_template.async_render() == "another value"
[ "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", ".", "states", ".", "async_set", "(", "\"sensor.dummy\"", ",", "\"a value\"", ")", "assert", "test_template", ".", "async_render", "(", ")", "==", "\"a value\"", "hass", ".", "states", ".", "async_set", "(", "\"sensor.dummy\"", ",", "\"another value\"", ")", "assert", "test_template", ".", "async_render", "(", ")", "==", "\"another value\"" ]
[ 1982, 0 ]
[ 1997, 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_render() == "23 beers" tpl = template.Template("{{ states.sensor.test2.state_with_unit }}", hass) assert tpl.async_render() == "wow" tpl = template.Template( "{% for state in states %}{{ state.state_with_unit }} {% endfor %}", hass ) assert tpl.async_render() == "23 beers wow" tpl = template.Template("{{ states.sensor.non_existing.state_with_unit }}", hass) assert tpl.async_render() == ""
[ "def", "test_state_with_unit", "(", "hass", ")", ":", "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_render", "(", ")", "==", "\"23 beers\"", "tpl", "=", "template", ".", "Template", "(", "\"{{ states.sensor.test2.state_with_unit }}\"", ",", "hass", ")", "assert", "tpl", ".", "async_render", "(", ")", "==", "\"wow\"", "tpl", "=", "template", ".", "Template", "(", "\"{% for state in states %}{{ state.state_with_unit }} {% endfor %}\"", ",", "hass", ")", "assert", "tpl", ".", "async_render", "(", ")", "==", "\"23 beers wow\"", "tpl", "=", "template", ".", "Template", "(", "\"{{ states.sensor.non_existing.state_with_unit }}\"", ",", "hass", ")", "assert", "tpl", ".", "async_render", "(", ")", "==", "\"\"" ]
[ 2000, 0 ]
[ 2021, 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() == 3 tpl = template.Template("{{ states.sensor | length }}", hass) assert tpl.async_render() == 2
[ "def", "test_length_of_states", "(", "hass", ")", ":", "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", "(", ")", "==", "3", "tpl", "=", "template", ".", "Template", "(", "\"{{ states.sensor | length }}\"", ",", "hass", ")", "assert", "tpl", ".", "async_render", "(", ")", "==", "2" ]
[ 2024, 0 ]
[ 2034, 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", ")", "}", ",", "{", "\"hello\"", ":", "2", "}", ")", "==", "{", "True", ":", "1", ",", "False", ":", "2", "}" ]
[ 2037, 0 ]
[ 2041, 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 = true' %}" "{{ string | urlencode }}"), hass, ) assert tpl.async_render() == "the%20quick%20brown%20fox%20%3D%20true"
[ "def", "test_urlencode", "(", "hass", ")", ":", "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 = true' %}\"", "\"{{ string | urlencode }}\"", ")", ",", "hass", ",", ")", "assert", "tpl", ".", "async_render", "(", ")", "==", "\"the%20quick%20brown%20fox%20%3D%20true\"" ]
[ 2044, 0 ]
[ 2055, 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( template_string ) # pylint: disable=protected-access tpl2 = template.Template( (template_string), ) tpl2.ensure_valid() assert template._NO_HASS_ENV.template_cache.get( template_string ) # pylint: disable=protected-access del tpl assert template._NO_HASS_ENV.template_cache.get( template_string ) # pylint: disable=protected-access del tpl2 assert not template._NO_HASS_ENV.template_cache.get( template_string )
[ "async", "def", "test_cache_garbage_collection", "(", ")", ":", "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", "(", "template_string", ")", "# pylint: disable=protected-access", "tpl2", "=", "template", ".", "Template", "(", "(", "template_string", ")", ",", ")", "tpl2", ".", "ensure_valid", "(", ")", "assert", "template", ".", "_NO_HASS_ENV", ".", "template_cache", ".", "get", "(", "template_string", ")", "# pylint: disable=protected-access", "del", "tpl", "assert", "template", ".", "_NO_HASS_ENV", ".", "template_cache", ".", "get", "(", "template_string", ")", "# pylint: disable=protected-access", "del", "tpl2", "assert", "not", "template", ".", "_NO_HASS_ENV", ".", "template_cache", ".", "get", "(", "template_string", ")" ]
[ 2058, 0 ]
[ 2086, 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_string("1") is False assert template.is_template_string("Some Text") is False
[ "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", "template", ".", "is_template_string", "(", "\"{# a comment #} Hey\"", ")", "is", "True", "assert", "template", ".", "is_template_string", "(", "\"1\"", ")", "is", "False", "assert", "template", ".", "is_template_string", "(", "\"Some Text\"", ")", "is", "False" ]
[ 2089, 0 ]
[ 2095, 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) with pytest.raises(TemplateError): tmp.async_render() tmp = template.Template('{{ states.sensor.any.__getattr__("any") }}', hass) with pytest.raises(TemplateError): tmp.async_render()
[ "async", "def", "test_protected_blocked", "(", "hass", ")", ":", "tmp", "=", "template", ".", "Template", "(", "'{{ states.__getattr__(\"any\") }}'", ",", "hass", ")", "with", "pytest", ".", "raises", "(", "TemplateError", ")", ":", "tmp", ".", "async_render", "(", ")", "tmp", "=", "template", ".", "Template", "(", "'{{ states.sensor.__getattr__(\"any\") }}'", ",", "hass", ")", "with", "pytest", ".", "raises", "(", "TemplateError", ")", ":", "tmp", ".", "async_render", "(", ")", "tmp", "=", "template", ".", "Template", "(", "'{{ states.sensor.any.__getattr__(\"any\") }}'", ",", "hass", ")", "with", "pytest", ".", "raises", "(", "TemplateError", ")", ":", "tmp", ".", "async_render", "(", ")" ]
[ 2098, 0 ]
[ 2110, 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: ##} {% set my_test_json = { "temperature": 25, "unit": "°C" } %} The temperature is {{ my_test_json.temperature }} {{ my_test_json.unit }}. {% if is_state("sun.sun", "above_horizon") -%} The sun rose {{ relative_time(states.sun.sun.last_changed) }} ago. {%- else -%} The sun will rise at {{ as_timestamp(strptime(state_attr("sun.sun", "next_rising"), "")) | timestamp_local }}. {%- endif %} For loop example getting 3 entity values: {% for states in states | slice(3) -%} {% set state = states | first %} {%- if loop.first %}The {% elif loop.last %} and the {% else %}, the {% endif -%} {{ state.name | lower }} is {{state.state_with_unit}} {%- endfor %}. """ tmp = template.Template(demo_template_str, hass) result = tmp.async_render() assert "The temperature is 25" in result assert "is on" in result assert "sensor0" in result assert "sensor1" in result assert "sun" in result
[ "async", "def", "test_demo_template", "(", "hass", ")", ":", "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", "=", "\"\"\"\n{## Imitate available variables: ##}\n{% set my_test_json = {\n \"temperature\": 25,\n \"unit\": \"°C\"\n} %}\n\nThe temperature is {{ my_test_json.temperature }} {{ my_test_json.unit }}.\n\n{% if is_state(\"sun.sun\", \"above_horizon\") -%}\n The sun rose {{ relative_time(states.sun.sun.last_changed) }} ago.\n{%- else -%}\n The sun will rise at {{ as_timestamp(strptime(state_attr(\"sun.sun\", \"next_rising\"), \"\")) | timestamp_local }}.\n{%- endif %}\n\nFor loop example getting 3 entity values:\n\n{% for states in states | slice(3) -%}\n {% set state = states | first %}\n {%- if loop.first %}The {% elif loop.last %} and the {% else %}, the {% endif -%}\n {{ state.name | lower }} is {{state.state_with_unit}}\n{%- endfor %}.\n\"\"\"", "tmp", "=", "template", ".", "Template", "(", "demo_template_str", ",", "hass", ")", "result", "=", "tmp", ".", "async_render", "(", ")", "assert", "\"The temperature is 25\"", "in", "result", "assert", "\"is on\"", "in", "result", "assert", "\"sensor0\"", "in", "result", "assert", "\"sensor1\"", "in", "result", "assert", "\"sun\"", "in", "result" ]
[ 2113, 0 ]
[ 2149, 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_render() == "sensor.test"
[ "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 %}{{ state.entity_id }}{%- endfor %}\"", ",", "hass", ",", ")", "assert", "tpl", ".", "async_render", "(", ")", "==", "\"sensor.test\"" ]
[ 2152, 0 ]
[ 2160, 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", "off") await hass.async_block_till_done() hass.states.async_set("sun.sun", "below", {"elevation": 60, "next_rising": "later"}) for i in range(2): hass.states.async_set(f"sensor.sensor{i}", "off") hass.states.async_set("sensor.new", "off") hass.states.async_remove("sensor.removed") await hass.async_block_till_done() tmp = template.Template("{{ states | count }}", hass) info = tmp.async_render_to_info() assert info.all_states is False assert info.all_states_lifecycle is True assert info.rate_limit is None assert info.has_time is False assert info.entities == set() assert info.domains == set() assert info.domains_lifecycle == set() assert info.filter("sun.sun") is False assert info.filter("sensor.sensor1") is False assert info.filter_lifecycle("sensor.new") is True assert info.filter_lifecycle("sensor.removed") is True
[ "async", "def", "test_lifecycle", "(", "hass", ")", ":", "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\"", ",", "\"off\"", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "hass", ".", "states", ".", "async_set", "(", "\"sun.sun\"", ",", "\"below\"", ",", "{", "\"elevation\"", ":", "60", ",", "\"next_rising\"", ":", "\"later\"", "}", ")", "for", "i", "in", "range", "(", "2", ")", ":", "hass", ".", "states", ".", "async_set", "(", "f\"sensor.sensor{i}\"", ",", "\"off\"", ")", "hass", ".", "states", ".", "async_set", "(", "\"sensor.new\"", ",", "\"off\"", ")", "hass", ".", "states", ".", "async_remove", "(", "\"sensor.removed\"", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "tmp", "=", "template", ".", "Template", "(", "\"{{ states | count }}\"", ",", "hass", ")", "info", "=", "tmp", ".", "async_render_to_info", "(", ")", "assert", "info", ".", "all_states", "is", "False", "assert", "info", ".", "all_states_lifecycle", "is", "True", "assert", "info", ".", "rate_limit", "is", "None", "assert", "info", ".", "has_time", "is", "False", "assert", "info", ".", "entities", "==", "set", "(", ")", "assert", "info", ".", "domains", "==", "set", "(", ")", "assert", "info", ".", "domains_lifecycle", "==", "set", "(", ")", "assert", "info", ".", "filter", "(", "\"sun.sun\"", ")", "is", "False", "assert", "info", ".", "filter", "(", "\"sensor.sensor1\"", ")", "is", "False", "assert", "info", ".", "filter_lifecycle", "(", "\"sensor.new\"", ")", "is", "True", "assert", "info", ".", "filter_lifecycle", "(", "\"sensor.removed\"", ")", "is", "True" ]
[ 2163, 0 ]
[ 2196, 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 tmp2 = template.Template("{{ error_invalid + 1 }}", hass) assert await tmp2.async_render_will_timeout(3) is False tmp3 = template.Template("static", hass) assert await tmp3.async_render_will_timeout(3) is False tmp4 = template.Template("{{ var1 }}", hass) assert await tmp4.async_render_will_timeout(3, {"var1": "ok"}) is False slow_template_str = """ {% for var in range(1000) -%} {% for var in range(1000) -%} {{ var }} {%- endfor %} {%- endfor %} """ tmp5 = template.Template(slow_template_str, hass) assert await tmp5.async_render_will_timeout(0.000001) is True
[ "async", "def", "test_template_timeout", "(", "hass", ")", ":", "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", "tmp2", "=", "template", ".", "Template", "(", "\"{{ error_invalid + 1 }}\"", ",", "hass", ")", "assert", "await", "tmp2", ".", "async_render_will_timeout", "(", "3", ")", "is", "False", "tmp3", "=", "template", ".", "Template", "(", "\"static\"", ",", "hass", ")", "assert", "await", "tmp3", ".", "async_render_will_timeout", "(", "3", ")", "is", "False", "tmp4", "=", "template", ".", "Template", "(", "\"{{ var1 }}\"", ",", "hass", ")", "assert", "await", "tmp4", ".", "async_render_will_timeout", "(", "3", ",", "{", "\"var1\"", ":", "\"ok\"", "}", ")", "is", "False", "slow_template_str", "=", "\"\"\"\n{% for var in range(1000) -%}\n {% for var in range(1000) -%}\n {{ var }}\n {%- endfor %}\n{%- endfor %}\n\"\"\"", "tmp5", "=", "template", ".", "Template", "(", "slow_template_str", ",", "hass", ")", "assert", "await", "tmp5", ".", "async_render_will_timeout", "(", "0.000001", ")", "is", "True" ]
[ 2199, 0 ]
[ 2224, 65 ]
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 {{lights_on[0]}} light is on. {% elif lights_on|length == 2 %} The {{lights_on[0]}} and {{lights_on[1]}} lights are on. {% else %} The {{lights_on[:-1]|join(', ')}}, and {{lights_on[-1]}} lights are on. {% endif %} """ states = [] for i in range(10): states.append(f"light.sensor{i}") hass.states.async_set(f"light.sensor{i}", "on") tmp = template.Template(tmpl, hass) info = tmp.async_render_to_info() assert info.entities == set() assert info.domains == {"light"} assert "lights are on" in info.result() for i in range(10): assert f"sensor{i}" in info.result()
[ "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 == 1 %}\n The {{lights_on[0]}} light is on.\n {% elif lights_on|length == 2 %}\n The {{lights_on[0]}} and {{lights_on[1]}} lights are on.\n {% else %}\n The {{lights_on[:-1]|join(', ')}}, and {{lights_on[-1]}} lights are on.\n {% endif %}\n \"\"\"", "states", "=", "[", "]", "for", "i", "in", "range", "(", "10", ")", ":", "states", ".", "append", "(", "f\"light.sensor{i}\"", ")", "hass", ".", "states", ".", "async_set", "(", "f\"light.sensor{i}\"", ",", "\"on\"", ")", "tmp", "=", "template", ".", "Template", "(", "tmpl", ",", "hass", ")", "info", "=", "tmp", ".", "async_render_to_info", "(", ")", "assert", "info", ".", "entities", "==", "set", "(", ")", "assert", "info", ".", "domains", "==", "{", "\"light\"", "}", "assert", "\"lights are on\"", "in", "info", ".", "result", "(", ")", "for", "i", "in", "range", "(", "10", ")", ":", "assert", "f\"sensor{i}\"", "in", "info", ".", "result", "(", ")" ]
[ 2227, 0 ]
[ 2254, 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).async_render() with pytest.raises(TemplateError): template.Template("{{ now() | random }}", hass).async_render() with pytest.raises(TemplateError): template.Template("{{ utcnow() | random }}", hass).async_render()
[ "async", "def", "test_template_errors", "(", "hass", ")", ":", "with", "pytest", ".", "raises", "(", "TemplateError", ")", ":", "template", ".", "Template", "(", "\"{{ now() | rando }}\"", ",", "hass", ")", ".", "async_render", "(", ")", "with", "pytest", ".", "raises", "(", "TemplateError", ")", ":", "template", ".", "Template", "(", "\"{{ utcnow() | rando }}\"", ",", "hass", ")", ".", "async_render", "(", ")", "with", "pytest", ".", "raises", "(", "TemplateError", ")", ":", "template", ".", "Template", "(", "\"{{ now() | random }}\"", ",", "hass", ")", ".", "async_render", "(", ")", "with", "pytest", ".", "raises", "(", "TemplateError", ")", ":", "template", ".", "Template", "(", "\"{{ utcnow() | random }}\"", ",", "hass", ")", ".", "async_render", "(", ")" ]
[ 2257, 0 ]
[ 2270, 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.Template( "{{ states.sensor.test.object_id }}", hass, ) assert tpl.async_render() == hass.states.get("sensor.test").object_id tpl = template.Template( "{{ states.sensor.test.domain }}", hass, ) assert tpl.async_render() == hass.states.get("sensor.test").domain tpl = template.Template( "{{ states.sensor.test.context.id }}", hass, ) assert tpl.async_render() == hass.states.get("sensor.test").context.id tpl = template.Template( "{{ states.sensor.test.state_with_unit }}", hass, ) assert tpl.async_render() == 23 tpl = template.Template( "{{ states.sensor.test.invalid_prop }}", hass, ) assert tpl.async_render() == "" tpl = template.Template( "{{ states.sensor.test.invalid_prop.xx }}", hass, ) with pytest.raises(TemplateError): tpl.async_render()
[ "async", "def", "test_state_attributes", "(", "hass", ")", ":", "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", ".", "Template", "(", "\"{{ states.sensor.test.object_id }}\"", ",", "hass", ",", ")", "assert", "tpl", ".", "async_render", "(", ")", "==", "hass", ".", "states", ".", "get", "(", "\"sensor.test\"", ")", ".", "object_id", "tpl", "=", "template", ".", "Template", "(", "\"{{ states.sensor.test.domain }}\"", ",", "hass", ",", ")", "assert", "tpl", ".", "async_render", "(", ")", "==", "hass", ".", "states", ".", "get", "(", "\"sensor.test\"", ")", ".", "domain", "tpl", "=", "template", ".", "Template", "(", "\"{{ states.sensor.test.context.id }}\"", ",", "hass", ",", ")", "assert", "tpl", ".", "async_render", "(", ")", "==", "hass", ".", "states", ".", "get", "(", "\"sensor.test\"", ")", ".", "context", ".", "id", "tpl", "=", "template", ".", "Template", "(", "\"{{ states.sensor.test.state_with_unit }}\"", ",", "hass", ",", ")", "assert", "tpl", ".", "async_render", "(", ")", "==", "23", "tpl", "=", "template", ".", "Template", "(", "\"{{ states.sensor.test.invalid_prop }}\"", ",", "hass", ",", ")", "assert", "tpl", ".", "async_render", "(", ")", "==", "\"\"", "tpl", "=", "template", ".", "Template", "(", "\"{{ states.sensor.test.invalid_prop.xx }}\"", ",", "hass", ",", ")", "with", "pytest", ".", "raises", "(", "TemplateError", ")", ":", "tpl", ".", "async_render", "(", ")" ]
[ 2273, 0 ]
[ 2318, 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", "none") tpl = template.Template( "{{ states | selectattr('state', 'in', ['unavailable','unknown','none']) | map(attribute='entity_id') | list | join(', ') }}", hass, ) assert tpl.async_render() == "light.none, light.unavailable, light.unknown" tpl = template.Template( "{{ states.light | selectattr('state', 'in', ['unavailable','unknown','none']) | map(attribute='entity_id') | list | join(', ') }}", hass, ) assert tpl.async_render() == "light.none, light.unavailable, light.unknown"
[ "async", "def", "test_unavailable_states", "(", "hass", ")", ":", "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\"", ",", "\"none\"", ")", "tpl", "=", "template", ".", "Template", "(", "\"{{ states | selectattr('state', 'in', ['unavailable','unknown','none']) | map(attribute='entity_id') | list | join(', ') }}\"", ",", "hass", ",", ")", "assert", "tpl", ".", "async_render", "(", ")", "==", "\"light.none, light.unavailable, light.unknown\"", "tpl", "=", "template", ".", "Template", "(", "\"{{ states.light | selectattr('state', 'in', ['unavailable','unknown','none']) | map(attribute='entity_id') | list | join(', ') }}\"", ",", "hass", ",", ")", "assert", "tpl", ".", "async_render", "(", ")", "==", "\"light.none, light.unavailable, light.unknown\"" ]
[ 2321, 0 ]
[ 2341, 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_ha_core_config(hass, {"legacy_templates": True}) assert ( template.Template("{{ states.sensor.temperature.state }}", hass).async_render() == "12" )
[ "async", "def", "test_legacy_templates", "(", "hass", ")", ":", "hass", ".", "states", ".", "async_set", "(", "\"sensor.temperature\"", ",", "\"12\"", ")", "assert", "(", "template", ".", "Template", "(", "\"{{ states.sensor.temperature.state }}\"", ",", "hass", ")", ".", "async_render", "(", ")", "==", "12", ")", "await", "async_process_ha_core_config", "(", "hass", ",", "{", "\"legacy_templates\"", ":", "True", "}", ")", "assert", "(", "template", ".", "Template", "(", "\"{{ states.sensor.temperature.state }}\"", ",", "hass", ")", ".", "async_render", "(", ")", "==", "\"12\"", ")" ]
[ 2344, 0 ]
[ 2357, 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" ) assert ( template.Template("{{ false }}", hass).async_render(parse_result=False) == "False" ) assert ( template.Template("{{ [1, 2, 3] }}", hass).async_render(parse_result=False) == "[1, 2, 3]" )
[ "async", "def", "test_no_result_parsing", "(", "hass", ")", ":", "hass", ".", "states", ".", "async_set", "(", "\"sensor.temperature\"", ",", "\"12\"", ")", "assert", "(", "template", ".", "Template", "(", "\"{{ states.sensor.temperature.state }}\"", ",", "hass", ")", ".", "async_render", "(", "parse_result", "=", "False", ")", "==", "\"12\"", ")", "assert", "(", "template", ".", "Template", "(", "\"{{ false }}\"", ",", "hass", ")", ".", "async_render", "(", "parse_result", "=", "False", ")", "==", "\"False\"", ")", "assert", "(", "template", ".", "Template", "(", "\"{{ [1, 2, 3] }}\"", ",", "hass", ")", ".", "async_render", "(", "parse_result", "=", "False", ")", "==", "\"[1, 2, 3]\"", ")" ]
[ 2360, 0 ]
[ 2379, 5 ]
python
en
['en', 'en', 'en']
True
test_is_static_still_ast_evals
(hass)
Test is_static still convers to native type.
Test is_static still convers to native type.
async def test_is_static_still_ast_evals(hass): """Test is_static still convers 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", ",", "2", "]" ]
[ 2382, 0 ]
[ 2386, 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}', {"hello": True}, dict, vol.Schema({"hello": bool})), ): tpl = template.Template(text, hass) result = tpl.async_render() assert isinstance(result, orig_type) assert isinstance(result, template.ResultWrapper) assert result == native assert result.render_result == text schema(result) # should not raise # Result with render text stringifies to original text assert str(result) == text # Result without render text stringifies same as original type assert str(template.RESULT_WRAPPERS[orig_type](native)) == str( orig_type(native) )
[ "async", "def", "test_result_wrappers", "(", "hass", ")", ":", "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}'", ",", "{", "\"hello\"", ":", "True", "}", ",", "dict", ",", "vol", ".", "Schema", "(", "{", "\"hello\"", ":", "bool", "}", ")", ")", ",", ")", ":", "tpl", "=", "template", ".", "Template", "(", "text", ",", "hass", ")", "result", "=", "tpl", ".", "async_render", "(", ")", "assert", "isinstance", "(", "result", ",", "orig_type", ")", "assert", "isinstance", "(", "result", ",", "template", ".", "ResultWrapper", ")", "assert", "result", "==", "native", "assert", "result", ".", "render_result", "==", "text", "schema", "(", "result", ")", "# should not raise", "# Result with render text stringifies to original text", "assert", "str", "(", "result", ")", "==", "text", "# Result without render text stringifies same as original type", "assert", "str", "(", "template", ".", "RESULT_WRAPPERS", "[", "orig_type", "]", "(", "native", ")", ")", "==", "str", "(", "orig_type", "(", "native", ")", ")" ]
[ 2389, 0 ]
[ 2409, 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), ("123.0", 123.0), (".5", 0.5), ("-1", -1), ("-1.0", -1.0), ("+1", 1), ("5.", 5.0), ): assert template.Template(tpl, hass).async_render() == result
[ "async", "def", "test_parse_result", "(", "hass", ")", ":", "for", "tpl", ",", "result", "in", "(", "(", "'{{ \"{{}}\" }}'", ",", "\"{{}}\"", ")", ",", "(", "\"not-something\"", ",", "\"not-something\"", ")", ",", "(", "\"2a\"", ",", "\"2a\"", ")", ",", "(", "\"123E5\"", ",", "\"123E5\"", ")", ",", "(", "\"1j\"", ",", "\"1j\"", ")", ",", "(", "\"1e+100\"", ",", "\"1e+100\"", ")", ",", "(", "\"0xface\"", ",", "\"0xface\"", ")", ",", "(", "\"123\"", ",", "123", ")", ",", "(", "\"123.0\"", ",", "123.0", ")", ",", "(", "\".5\"", ",", "0.5", ")", ",", "(", "\"-1\"", ",", "-", "1", ")", ",", "(", "\"-1.0\"", ",", "-", "1.0", ")", ",", "(", "\"+1\"", ",", "1", ")", ",", "(", "\"5.\"", ",", "5.0", ")", ",", ")", ":", "assert", "template", ".", "Template", "(", "tpl", ",", "hass", ")", ".", "async_render", "(", ")", "==", "result" ]
[ 2412, 0 ]
[ 2430, 68 ]
python
de
['fr', 'de', 'en']
False
async_setup_entry
(hass, config_entry, async_add_entities)
Set up the Zigbee Home Automation device tracker from config entry.
Set up the Zigbee Home Automation device tracker from config entry.
async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the Zigbee Home Automation device tracker from config entry.""" entities_to_create = hass.data[DATA_ZHA][DOMAIN] unsub = async_dispatcher_connect( hass, SIGNAL_ADD_ENTITIES, functools.partial( discovery.async_add_entities, async_add_entities, entities_to_create ), ) hass.data[DATA_ZHA][DATA_ZHA_DISPATCHERS].append(unsub)
[ "async", "def", "async_setup_entry", "(", "hass", ",", "config_entry", ",", "async_add_entities", ")", ":", "entities_to_create", "=", "hass", ".", "data", "[", "DATA_ZHA", "]", "[", "DOMAIN", "]", "unsub", "=", "async_dispatcher_connect", "(", "hass", ",", "SIGNAL_ADD_ENTITIES", ",", "functools", ".", "partial", "(", "discovery", ".", "async_add_entities", ",", "async_add_entities", ",", "entities_to_create", ")", ",", ")", "hass", ".", "data", "[", "DATA_ZHA", "]", "[", "DATA_ZHA_DISPATCHERS", "]", ".", "append", "(", "unsub", ")" ]
[ 24, 0 ]
[ 35, 59 ]
python
en
['en', 'en', 'en']
True
pad_sequence
(sequence, lengths)
:param sequence: [\sum b, .....] sequence :param lengths: [b1, b2, b3...] that sum to \sum b :return: [len(lengths), maxlen(b), .....] tensor
:param sequence: [\sum b, .....] sequence :param lengths: [b1, b2, b3...] that sum to \sum b :return: [len(lengths), maxlen(b), .....] tensor
def pad_sequence(sequence, lengths): """ :param sequence: [\sum b, .....] sequence :param lengths: [b1, b2, b3...] that sum to \sum b :return: [len(lengths), maxlen(b), .....] tensor """ output = sequence.new_zeros(len(lengths), max(lengths), *sequence.shape[1:]) start = 0 for i, diff in enumerate(lengths): if diff > 0: output[i, :diff] = sequence[start:(start + diff)] start += diff return output
[ "def", "pad_sequence", "(", "sequence", ",", "lengths", ")", ":", "output", "=", "sequence", ".", "new_zeros", "(", "len", "(", "lengths", ")", ",", "max", "(", "lengths", ")", ",", "*", "sequence", ".", "shape", "[", "1", ":", "]", ")", "start", "=", "0", "for", "i", ",", "diff", "in", "enumerate", "(", "lengths", ")", ":", "if", "diff", ">", "0", ":", "output", "[", "i", ",", ":", "diff", "]", "=", "sequence", "[", "start", ":", "(", "start", "+", "diff", ")", "]", "start", "+=", "diff", "return", "output" ]
[ 3, 0 ]
[ 16, 17 ]
python
en
['en', 'error', 'th']
False
setup_platform
(hass, config, add_entities, discovery_info=None)
Set up the cover platform for ADS.
Set up the cover platform for ADS.
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the cover platform for ADS.""" ads_hub = hass.data[DATA_ADS] ads_var_is_closed = config.get(CONF_ADS_VAR) ads_var_position = config.get(CONF_ADS_VAR_POSITION) ads_var_pos_set = config.get(CONF_ADS_VAR_SET_POS) ads_var_open = config.get(CONF_ADS_VAR_OPEN) ads_var_close = config.get(CONF_ADS_VAR_CLOSE) ads_var_stop = config.get(CONF_ADS_VAR_STOP) name = config[CONF_NAME] device_class = config.get(CONF_DEVICE_CLASS) add_entities( [ AdsCover( ads_hub, ads_var_is_closed, ads_var_position, ads_var_pos_set, ads_var_open, ads_var_close, ads_var_stop, name, device_class, ) ] )
[ "def", "setup_platform", "(", "hass", ",", "config", ",", "add_entities", ",", "discovery_info", "=", "None", ")", ":", "ads_hub", "=", "hass", ".", "data", "[", "DATA_ADS", "]", "ads_var_is_closed", "=", "config", ".", "get", "(", "CONF_ADS_VAR", ")", "ads_var_position", "=", "config", ".", "get", "(", "CONF_ADS_VAR_POSITION", ")", "ads_var_pos_set", "=", "config", ".", "get", "(", "CONF_ADS_VAR_SET_POS", ")", "ads_var_open", "=", "config", ".", "get", "(", "CONF_ADS_VAR_OPEN", ")", "ads_var_close", "=", "config", ".", "get", "(", "CONF_ADS_VAR_CLOSE", ")", "ads_var_stop", "=", "config", ".", "get", "(", "CONF_ADS_VAR_STOP", ")", "name", "=", "config", "[", "CONF_NAME", "]", "device_class", "=", "config", ".", "get", "(", "CONF_DEVICE_CLASS", ")", "add_entities", "(", "[", "AdsCover", "(", "ads_hub", ",", "ads_var_is_closed", ",", "ads_var_position", ",", "ads_var_pos_set", ",", "ads_var_open", ",", "ads_var_close", ",", "ads_var_stop", ",", "name", ",", "device_class", ",", ")", "]", ")" ]
[ 46, 0 ]
[ 73, 5 ]
python
en
['en', 'da', 'en']
True
AdsCover.__init__
( self, ads_hub, ads_var_is_closed, ads_var_position, ads_var_pos_set, ads_var_open, ads_var_close, ads_var_stop, name, device_class, )
Initialize AdsCover entity.
Initialize AdsCover entity.
def __init__( self, ads_hub, ads_var_is_closed, ads_var_position, ads_var_pos_set, ads_var_open, ads_var_close, ads_var_stop, name, device_class, ): """Initialize AdsCover entity.""" super().__init__(ads_hub, name, ads_var_is_closed) if self._ads_var is None: if ads_var_position is not None: self._unique_id = ads_var_position elif ads_var_pos_set is not None: self._unique_id = ads_var_pos_set elif ads_var_open is not None: self._unique_id = ads_var_open self._state_dict[STATE_KEY_POSITION] = None self._ads_var_position = ads_var_position self._ads_var_pos_set = ads_var_pos_set self._ads_var_open = ads_var_open self._ads_var_close = ads_var_close self._ads_var_stop = ads_var_stop self._device_class = device_class
[ "def", "__init__", "(", "self", ",", "ads_hub", ",", "ads_var_is_closed", ",", "ads_var_position", ",", "ads_var_pos_set", ",", "ads_var_open", ",", "ads_var_close", ",", "ads_var_stop", ",", "name", ",", "device_class", ",", ")", ":", "super", "(", ")", ".", "__init__", "(", "ads_hub", ",", "name", ",", "ads_var_is_closed", ")", "if", "self", ".", "_ads_var", "is", "None", ":", "if", "ads_var_position", "is", "not", "None", ":", "self", ".", "_unique_id", "=", "ads_var_position", "elif", "ads_var_pos_set", "is", "not", "None", ":", "self", ".", "_unique_id", "=", "ads_var_pos_set", "elif", "ads_var_open", "is", "not", "None", ":", "self", ".", "_unique_id", "=", "ads_var_open", "self", ".", "_state_dict", "[", "STATE_KEY_POSITION", "]", "=", "None", "self", ".", "_ads_var_position", "=", "ads_var_position", "self", ".", "_ads_var_pos_set", "=", "ads_var_pos_set", "self", ".", "_ads_var_open", "=", "ads_var_open", "self", ".", "_ads_var_close", "=", "ads_var_close", "self", ".", "_ads_var_stop", "=", "ads_var_stop", "self", ".", "_device_class", "=", "device_class" ]
[ 79, 4 ]
[ 107, 41 ]
python
da
['da', 'en', 'it']
False
AdsCover.async_added_to_hass
(self)
Register device notification.
Register device notification.
async def async_added_to_hass(self): """Register device notification.""" if self._ads_var is not None: await self.async_initialize_device( self._ads_var, self._ads_hub.PLCTYPE_BOOL ) if self._ads_var_position is not None: await self.async_initialize_device( self._ads_var_position, self._ads_hub.PLCTYPE_BYTE, STATE_KEY_POSITION )
[ "async", "def", "async_added_to_hass", "(", "self", ")", ":", "if", "self", ".", "_ads_var", "is", "not", "None", ":", "await", "self", ".", "async_initialize_device", "(", "self", ".", "_ads_var", ",", "self", ".", "_ads_hub", ".", "PLCTYPE_BOOL", ")", "if", "self", ".", "_ads_var_position", "is", "not", "None", ":", "await", "self", ".", "async_initialize_device", "(", "self", ".", "_ads_var_position", ",", "self", ".", "_ads_hub", ".", "PLCTYPE_BYTE", ",", "STATE_KEY_POSITION", ")" ]
[ 109, 4 ]
[ 119, 13 ]
python
en
['da', 'en', 'en']
True
AdsCover.device_class
(self)
Return the class of this cover.
Return the class of this cover.
def device_class(self): """Return the class of this cover.""" return self._device_class
[ "def", "device_class", "(", "self", ")", ":", "return", "self", ".", "_device_class" ]
[ 122, 4 ]
[ 124, 33 ]
python
en
['en', 'en', 'en']
True
AdsCover.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._ads_var is not None: return self._state_dict[STATE_KEY_STATE] if self._ads_var_position is not None: return self._state_dict[STATE_KEY_POSITION] == 0 return None
[ "def", "is_closed", "(", "self", ")", ":", "if", "self", ".", "_ads_var", "is", "not", "None", ":", "return", "self", ".", "_state_dict", "[", "STATE_KEY_STATE", "]", "if", "self", ".", "_ads_var_position", "is", "not", "None", ":", "return", "self", ".", "_state_dict", "[", "STATE_KEY_POSITION", "]", "==", "0", "return", "None" ]
[ 127, 4 ]
[ 133, 19 ]
python
en
['en', 'en', 'en']
True
AdsCover.current_cover_position
(self)
Return current position of cover.
Return current position of cover.
def current_cover_position(self): """Return current position of cover.""" return self._state_dict[STATE_KEY_POSITION]
[ "def", "current_cover_position", "(", "self", ")", ":", "return", "self", ".", "_state_dict", "[", "STATE_KEY_POSITION", "]" ]
[ 136, 4 ]
[ 138, 51 ]
python
en
['en', 'en', 'en']
True
AdsCover.supported_features
(self)
Flag supported features.
Flag supported features.
def supported_features(self): """Flag supported features.""" supported_features = SUPPORT_OPEN | SUPPORT_CLOSE if self._ads_var_stop is not None: supported_features |= SUPPORT_STOP if self._ads_var_pos_set is not None: supported_features |= SUPPORT_SET_POSITION return supported_features
[ "def", "supported_features", "(", "self", ")", ":", "supported_features", "=", "SUPPORT_OPEN", "|", "SUPPORT_CLOSE", "if", "self", ".", "_ads_var_stop", "is", "not", "None", ":", "supported_features", "|=", "SUPPORT_STOP", "if", "self", ".", "_ads_var_pos_set", "is", "not", "None", ":", "supported_features", "|=", "SUPPORT_SET_POSITION", "return", "supported_features" ]
[ 141, 4 ]
[ 151, 33 ]
python
en
['da', 'en', 'en']
True
AdsCover.stop_cover
(self, **kwargs)
Fire the stop action.
Fire the stop action.
def stop_cover(self, **kwargs): """Fire the stop action.""" if self._ads_var_stop: self._ads_hub.write_by_name( self._ads_var_stop, True, self._ads_hub.PLCTYPE_BOOL )
[ "def", "stop_cover", "(", "self", ",", "*", "*", "kwargs", ")", ":", "if", "self", ".", "_ads_var_stop", ":", "self", ".", "_ads_hub", ".", "write_by_name", "(", "self", ".", "_ads_var_stop", ",", "True", ",", "self", ".", "_ads_hub", ".", "PLCTYPE_BOOL", ")" ]
[ 153, 4 ]
[ 158, 13 ]
python
en
['en', 'en', 'en']
True
AdsCover.set_cover_position
(self, **kwargs)
Set cover position.
Set cover position.
def set_cover_position(self, **kwargs): """Set cover position.""" position = kwargs[ATTR_POSITION] if self._ads_var_pos_set is not None: self._ads_hub.write_by_name( self._ads_var_pos_set, position, self._ads_hub.PLCTYPE_BYTE )
[ "def", "set_cover_position", "(", "self", ",", "*", "*", "kwargs", ")", ":", "position", "=", "kwargs", "[", "ATTR_POSITION", "]", "if", "self", ".", "_ads_var_pos_set", "is", "not", "None", ":", "self", ".", "_ads_hub", ".", "write_by_name", "(", "self", ".", "_ads_var_pos_set", ",", "position", ",", "self", ".", "_ads_hub", ".", "PLCTYPE_BYTE", ")" ]
[ 160, 4 ]
[ 166, 13 ]
python
en
['en', 'en', 'en']
True
AdsCover.open_cover
(self, **kwargs)
Move the cover up.
Move the cover up.
def open_cover(self, **kwargs): """Move the cover up.""" if self._ads_var_open is not None: self._ads_hub.write_by_name( self._ads_var_open, True, self._ads_hub.PLCTYPE_BOOL ) elif self._ads_var_pos_set is not None: self.set_cover_position(position=100)
[ "def", "open_cover", "(", "self", ",", "*", "*", "kwargs", ")", ":", "if", "self", ".", "_ads_var_open", "is", "not", "None", ":", "self", ".", "_ads_hub", ".", "write_by_name", "(", "self", ".", "_ads_var_open", ",", "True", ",", "self", ".", "_ads_hub", ".", "PLCTYPE_BOOL", ")", "elif", "self", ".", "_ads_var_pos_set", "is", "not", "None", ":", "self", ".", "set_cover_position", "(", "position", "=", "100", ")" ]
[ 168, 4 ]
[ 175, 49 ]
python
en
['en', 'en', 'en']
True
AdsCover.close_cover
(self, **kwargs)
Move the cover down.
Move the cover down.
def close_cover(self, **kwargs): """Move the cover down.""" if self._ads_var_close is not None: self._ads_hub.write_by_name( self._ads_var_close, True, self._ads_hub.PLCTYPE_BOOL ) elif self._ads_var_pos_set is not None: self.set_cover_position(position=0)
[ "def", "close_cover", "(", "self", ",", "*", "*", "kwargs", ")", ":", "if", "self", ".", "_ads_var_close", "is", "not", "None", ":", "self", ".", "_ads_hub", ".", "write_by_name", "(", "self", ".", "_ads_var_close", ",", "True", ",", "self", ".", "_ads_hub", ".", "PLCTYPE_BOOL", ")", "elif", "self", ".", "_ads_var_pos_set", "is", "not", "None", ":", "self", ".", "set_cover_position", "(", "position", "=", "0", ")" ]
[ 177, 4 ]
[ 184, 47 ]
python
en
['en', 'en', 'en']
True
AdsCover.available
(self)
Return False if state has not been updated yet.
Return False if state has not been updated yet.
def available(self): """Return False if state has not been updated yet.""" if self._ads_var is not None or self._ads_var_position is not None: return ( self._state_dict[STATE_KEY_STATE] is not None or self._state_dict[STATE_KEY_POSITION] is not None ) return True
[ "def", "available", "(", "self", ")", ":", "if", "self", ".", "_ads_var", "is", "not", "None", "or", "self", ".", "_ads_var_position", "is", "not", "None", ":", "return", "(", "self", ".", "_state_dict", "[", "STATE_KEY_STATE", "]", "is", "not", "None", "or", "self", ".", "_state_dict", "[", "STATE_KEY_POSITION", "]", "is", "not", "None", ")", "return", "True" ]
[ 187, 4 ]
[ 194, 19 ]
python
en
['en', 'en', 'en']
True
async_setup_platform
(hass, config, async_add_entities, discovery_info=None)
Set up a Volvo switch.
Set up a Volvo switch.
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up a Volvo switch.""" if discovery_info is None: return async_add_entities([VolvoSwitch(hass.data[DATA_KEY], *discovery_info)])
[ "async", "def", "async_setup_platform", "(", "hass", ",", "config", ",", "async_add_entities", ",", "discovery_info", "=", "None", ")", ":", "if", "discovery_info", "is", "None", ":", "return", "async_add_entities", "(", "[", "VolvoSwitch", "(", "hass", ".", "data", "[", "DATA_KEY", "]", ",", "*", "discovery_info", ")", "]", ")" ]
[ 6, 0 ]
[ 10, 75 ]
python
en
['en', 'en', 'en']
True
VolvoSwitch.is_on
(self)
Return true if switch is on.
Return true if switch is on.
def is_on(self): """Return true if switch is on.""" return self.instrument.state
[ "def", "is_on", "(", "self", ")", ":", "return", "self", ".", "instrument", ".", "state" ]
[ 17, 4 ]
[ 19, 36 ]
python
en
['en', 'fy', 'en']
True
VolvoSwitch.async_turn_on
(self, **kwargs)
Turn the switch on.
Turn the switch on.
async def async_turn_on(self, **kwargs): """Turn the switch on.""" await self.instrument.turn_on() self.async_write_ha_state()
[ "async", "def", "async_turn_on", "(", "self", ",", "*", "*", "kwargs", ")", ":", "await", "self", ".", "instrument", ".", "turn_on", "(", ")", "self", ".", "async_write_ha_state", "(", ")" ]
[ 21, 4 ]
[ 24, 35 ]
python
en
['en', 'en', 'en']
True
VolvoSwitch.async_turn_off
(self, **kwargs)
Turn the switch off.
Turn the switch off.
async def async_turn_off(self, **kwargs): """Turn the switch off.""" await self.instrument.turn_off() self.async_write_ha_state()
[ "async", "def", "async_turn_off", "(", "self", ",", "*", "*", "kwargs", ")", ":", "await", "self", ".", "instrument", ".", "turn_off", "(", ")", "self", ".", "async_write_ha_state", "(", ")" ]
[ 26, 4 ]
[ 29, 35 ]
python
en
['en', 'en', 'en']
True
setup_platform
(hass, config, add_entities, discovery_info=None)
Set up the Wink platform.
Set up the Wink platform.
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Wink platform.""" for fan in pywink.get_fans(): if fan.object_id() + fan.name() not in hass.data[DOMAIN]["unique_ids"]: add_entities([WinkFanDevice(fan, hass)])
[ "def", "setup_platform", "(", "hass", ",", "config", ",", "add_entities", ",", "discovery_info", "=", "None", ")", ":", "for", "fan", "in", "pywink", ".", "get_fans", "(", ")", ":", "if", "fan", ".", "object_id", "(", ")", "+", "fan", ".", "name", "(", ")", "not", "in", "hass", ".", "data", "[", "DOMAIN", "]", "[", "\"unique_ids\"", "]", ":", "add_entities", "(", "[", "WinkFanDevice", "(", "fan", ",", "hass", ")", "]", ")" ]
[ 19, 0 ]
[ 24, 52 ]
python
en
['en', 'da', 'en']
True
WinkFanDevice.async_added_to_hass
(self)
Call when entity is added to hass.
Call when entity is added to hass.
async def async_added_to_hass(self): """Call when entity is added to hass.""" self.hass.data[DOMAIN]["entities"]["fan"].append(self)
[ "async", "def", "async_added_to_hass", "(", "self", ")", ":", "self", ".", "hass", ".", "data", "[", "DOMAIN", "]", "[", "\"entities\"", "]", "[", "\"fan\"", "]", ".", "append", "(", "self", ")" ]
[ 30, 4 ]
[ 32, 62 ]
python
en
['en', 'en', 'en']
True
WinkFanDevice.set_direction
(self, direction: str)
Set the direction of the fan.
Set the direction of the fan.
def set_direction(self, direction: str) -> None: """Set the direction of the fan.""" self.wink.set_fan_direction(direction)
[ "def", "set_direction", "(", "self", ",", "direction", ":", "str", ")", "->", "None", ":", "self", ".", "wink", ".", "set_fan_direction", "(", "direction", ")" ]
[ 34, 4 ]
[ 36, 46 ]
python
en
['en', 'en', 'en']
True
WinkFanDevice.set_speed
(self, speed: str)
Set the speed of the fan.
Set the speed of the fan.
def set_speed(self, speed: str) -> None: """Set the speed of the fan.""" self.wink.set_state(True, speed)
[ "def", "set_speed", "(", "self", ",", "speed", ":", "str", ")", "->", "None", ":", "self", ".", "wink", ".", "set_state", "(", "True", ",", "speed", ")" ]
[ 38, 4 ]
[ 40, 40 ]
python
en
['en', 'en', 'en']
True
WinkFanDevice.turn_on
(self, speed: str = None, **kwargs)
Turn on the fan.
Turn on the fan.
def turn_on(self, speed: str = None, **kwargs) -> None: """Turn on the fan.""" self.wink.set_state(True, speed)
[ "def", "turn_on", "(", "self", ",", "speed", ":", "str", "=", "None", ",", "*", "*", "kwargs", ")", "->", "None", ":", "self", ".", "wink", ".", "set_state", "(", "True", ",", "speed", ")" ]
[ 42, 4 ]
[ 44, 40 ]
python
en
['en', 'fy', 'en']
True
WinkFanDevice.turn_off
(self, **kwargs)
Turn off the fan.
Turn off the fan.
def turn_off(self, **kwargs) -> None: """Turn off the fan.""" self.wink.set_state(False)
[ "def", "turn_off", "(", "self", ",", "*", "*", "kwargs", ")", "->", "None", ":", "self", ".", "wink", ".", "set_state", "(", "False", ")" ]
[ 46, 4 ]
[ 48, 34 ]
python
en
['en', 'fy', 'en']
True
WinkFanDevice.is_on
(self)
Return true if the entity is on.
Return true if the entity is on.
def is_on(self): """Return true if the entity is on.""" return self.wink.state()
[ "def", "is_on", "(", "self", ")", ":", "return", "self", ".", "wink", ".", "state", "(", ")" ]
[ 51, 4 ]
[ 53, 32 ]
python
en
['en', 'en', 'en']
True
WinkFanDevice.speed
(self)
Return the current speed.
Return the current speed.
def speed(self) -> str: """Return the current speed.""" current_wink_speed = self.wink.current_fan_speed() if SPEED_AUTO == current_wink_speed: return SPEED_AUTO if SPEED_LOWEST == current_wink_speed: return SPEED_LOWEST if SPEED_LOW == current_wink_speed: return SPEED_LOW if SPEED_MEDIUM == current_wink_speed: return SPEED_MEDIUM if SPEED_HIGH == current_wink_speed: return SPEED_HIGH return None
[ "def", "speed", "(", "self", ")", "->", "str", ":", "current_wink_speed", "=", "self", ".", "wink", ".", "current_fan_speed", "(", ")", "if", "SPEED_AUTO", "==", "current_wink_speed", ":", "return", "SPEED_AUTO", "if", "SPEED_LOWEST", "==", "current_wink_speed", ":", "return", "SPEED_LOWEST", "if", "SPEED_LOW", "==", "current_wink_speed", ":", "return", "SPEED_LOW", "if", "SPEED_MEDIUM", "==", "current_wink_speed", ":", "return", "SPEED_MEDIUM", "if", "SPEED_HIGH", "==", "current_wink_speed", ":", "return", "SPEED_HIGH", "return", "None" ]
[ 56, 4 ]
[ 69, 19 ]
python
en
['en', 'en', 'en']
True
WinkFanDevice.current_direction
(self)
Return direction of the fan [forward, reverse].
Return direction of the fan [forward, reverse].
def current_direction(self): """Return direction of the fan [forward, reverse].""" return self.wink.current_fan_direction()
[ "def", "current_direction", "(", "self", ")", ":", "return", "self", ".", "wink", ".", "current_fan_direction", "(", ")" ]
[ 72, 4 ]
[ 74, 48 ]
python
en
['en', 'fy', 'en']
True
WinkFanDevice.speed_list
(self)
Get the list of available speeds.
Get the list of available speeds.
def speed_list(self) -> list: """Get the list of available speeds.""" wink_supported_speeds = self.wink.fan_speeds() supported_speeds = [] if SPEED_AUTO in wink_supported_speeds: supported_speeds.append(SPEED_AUTO) if SPEED_LOWEST in wink_supported_speeds: supported_speeds.append(SPEED_LOWEST) if SPEED_LOW in wink_supported_speeds: supported_speeds.append(SPEED_LOW) if SPEED_MEDIUM in wink_supported_speeds: supported_speeds.append(SPEED_MEDIUM) if SPEED_HIGH in wink_supported_speeds: supported_speeds.append(SPEED_HIGH) return supported_speeds
[ "def", "speed_list", "(", "self", ")", "->", "list", ":", "wink_supported_speeds", "=", "self", ".", "wink", ".", "fan_speeds", "(", ")", "supported_speeds", "=", "[", "]", "if", "SPEED_AUTO", "in", "wink_supported_speeds", ":", "supported_speeds", ".", "append", "(", "SPEED_AUTO", ")", "if", "SPEED_LOWEST", "in", "wink_supported_speeds", ":", "supported_speeds", ".", "append", "(", "SPEED_LOWEST", ")", "if", "SPEED_LOW", "in", "wink_supported_speeds", ":", "supported_speeds", ".", "append", "(", "SPEED_LOW", ")", "if", "SPEED_MEDIUM", "in", "wink_supported_speeds", ":", "supported_speeds", ".", "append", "(", "SPEED_MEDIUM", ")", "if", "SPEED_HIGH", "in", "wink_supported_speeds", ":", "supported_speeds", ".", "append", "(", "SPEED_HIGH", ")", "return", "supported_speeds" ]
[ 77, 4 ]
[ 91, 31 ]
python
en
['en', 'en', 'en']
True
WinkFanDevice.supported_features
(self)
Flag supported features.
Flag supported features.
def supported_features(self) -> int: """Flag supported features.""" return SUPPORTED_FEATURES
[ "def", "supported_features", "(", "self", ")", "->", "int", ":", "return", "SUPPORTED_FEATURES" ]
[ 94, 4 ]
[ 96, 33 ]
python
en
['da', 'en', 'en']
True
mock_openzwave
()
Mock out Open Z-Wave.
Mock out Open Z-Wave.
def mock_openzwave(): """Mock out Open Z-Wave.""" base_mock = MagicMock() libopenzwave = base_mock.libopenzwave libopenzwave.__file__ = "test" base_mock.network.ZWaveNetwork = MockNetwork base_mock.option.ZWaveOption = MockOption with patch.dict( "sys.modules", { "libopenzwave": libopenzwave, "openzwave.option": base_mock.option, "openzwave.network": base_mock.network, "openzwave.group": base_mock.group, }, ): yield base_mock
[ "def", "mock_openzwave", "(", ")", ":", "base_mock", "=", "MagicMock", "(", ")", "libopenzwave", "=", "base_mock", ".", "libopenzwave", "libopenzwave", ".", "__file__", "=", "\"test\"", "base_mock", ".", "network", ".", "ZWaveNetwork", "=", "MockNetwork", "base_mock", ".", "option", ".", "ZWaveOption", "=", "MockOption", "with", "patch", ".", "dict", "(", "\"sys.modules\"", ",", "{", "\"libopenzwave\"", ":", "libopenzwave", ",", "\"openzwave.option\"", ":", "base_mock", ".", "option", ",", "\"openzwave.network\"", ":", "base_mock", ".", "network", ",", "\"openzwave.group\"", ":", "base_mock", ".", "group", ",", "}", ",", ")", ":", "yield", "base_mock" ]
[ 11, 0 ]
[ 28, 23 ]
python
en
['en', 'en', 'en']
True
mock_discovery
()
Mock discovery.
Mock discovery.
def mock_discovery(): """Mock discovery.""" discovery = MagicMock() discovery.async_load_platform = AsyncMock(return_value=None) yield discovery
[ "def", "mock_discovery", "(", ")", ":", "discovery", "=", "MagicMock", "(", ")", "discovery", ".", "async_load_platform", "=", "AsyncMock", "(", "return_value", "=", "None", ")", "yield", "discovery" ]
[ 32, 0 ]
[ 36, 19 ]
python
en
['en', 'en', 'en']
False
mock_import_module
()
Mock import module.
Mock import module.
def mock_import_module(): """Mock import module.""" platform = MagicMock() mock_device = MagicMock() mock_device.name = "test_device" platform.get_device.return_value = mock_device import_module = MagicMock() import_module.return_value = platform yield import_module
[ "def", "mock_import_module", "(", ")", ":", "platform", "=", "MagicMock", "(", ")", "mock_device", "=", "MagicMock", "(", ")", "mock_device", ".", "name", "=", "\"test_device\"", "platform", ".", "get_device", ".", "return_value", "=", "mock_device", "import_module", "=", "MagicMock", "(", ")", "import_module", ".", "return_value", "=", "platform", "yield", "import_module" ]
[ 40, 0 ]
[ 49, 23 ]
python
en
['en', 'fy', 'en']
True
mock_values
()
Mock values.
Mock values.
def mock_values(): """Mock values.""" node = MockNode() mock_schema = { const.DISC_COMPONENT: "mock_component", const.DISC_VALUES: { const.DISC_PRIMARY: {const.DISC_COMMAND_CLASS: ["mock_primary_class"]}, "secondary": {const.DISC_COMMAND_CLASS: ["mock_secondary_class"]}, "optional": { const.DISC_COMMAND_CLASS: ["mock_optional_class"], const.DISC_OPTIONAL: True, }, }, } value_class = MagicMock() value_class.primary = MockValue( command_class="mock_primary_class", node=node, value_id=1000 ) value_class.secondary = MockValue(command_class="mock_secondary_class", node=node) value_class.duplicate_secondary = MockValue( command_class="mock_secondary_class", node=node ) value_class.optional = MockValue(command_class="mock_optional_class", node=node) value_class.no_match_value = MockValue(command_class="mock_bad_class", node=node) yield (node, value_class, mock_schema)
[ "def", "mock_values", "(", ")", ":", "node", "=", "MockNode", "(", ")", "mock_schema", "=", "{", "const", ".", "DISC_COMPONENT", ":", "\"mock_component\"", ",", "const", ".", "DISC_VALUES", ":", "{", "const", ".", "DISC_PRIMARY", ":", "{", "const", ".", "DISC_COMMAND_CLASS", ":", "[", "\"mock_primary_class\"", "]", "}", ",", "\"secondary\"", ":", "{", "const", ".", "DISC_COMMAND_CLASS", ":", "[", "\"mock_secondary_class\"", "]", "}", ",", "\"optional\"", ":", "{", "const", ".", "DISC_COMMAND_CLASS", ":", "[", "\"mock_optional_class\"", "]", ",", "const", ".", "DISC_OPTIONAL", ":", "True", ",", "}", ",", "}", ",", "}", "value_class", "=", "MagicMock", "(", ")", "value_class", ".", "primary", "=", "MockValue", "(", "command_class", "=", "\"mock_primary_class\"", ",", "node", "=", "node", ",", "value_id", "=", "1000", ")", "value_class", ".", "secondary", "=", "MockValue", "(", "command_class", "=", "\"mock_secondary_class\"", ",", "node", "=", "node", ")", "value_class", ".", "duplicate_secondary", "=", "MockValue", "(", "command_class", "=", "\"mock_secondary_class\"", ",", "node", "=", "node", ")", "value_class", ".", "optional", "=", "MockValue", "(", "command_class", "=", "\"mock_optional_class\"", ",", "node", "=", "node", ")", "value_class", ".", "no_match_value", "=", "MockValue", "(", "command_class", "=", "\"mock_bad_class\"", ",", "node", "=", "node", ")", "yield", "(", "node", ",", "value_class", ",", "mock_schema", ")" ]
[ 53, 0 ]
[ 78, 42 ]
python
en
['en', 'mg', 'en']
False
async_setup_entry
(hass, config_entry, async_add_entities)
Set up Homekit lighting.
Set up Homekit lighting.
async def async_setup_entry(hass, config_entry, async_add_entities): """Set up Homekit lighting.""" hkid = config_entry.data["AccessoryPairingID"] conn = hass.data[KNOWN_DEVICES][hkid] @callback def async_add_service(service): entity_class = ENTITY_TYPES.get(service.short_type) if not entity_class: return False info = {"aid": service.accessory.aid, "iid": service.iid} async_add_entities([entity_class(conn, info)], True) return True conn.add_listener(async_add_service)
[ "async", "def", "async_setup_entry", "(", "hass", ",", "config_entry", ",", "async_add_entities", ")", ":", "hkid", "=", "config_entry", ".", "data", "[", "\"AccessoryPairingID\"", "]", "conn", "=", "hass", ".", "data", "[", "KNOWN_DEVICES", "]", "[", "hkid", "]", "@", "callback", "def", "async_add_service", "(", "service", ")", ":", "entity_class", "=", "ENTITY_TYPES", ".", "get", "(", "service", ".", "short_type", ")", "if", "not", "entity_class", ":", "return", "False", "info", "=", "{", "\"aid\"", ":", "service", ".", "accessory", ".", "aid", ",", "\"iid\"", ":", "service", ".", "iid", "}", "async_add_entities", "(", "[", "entity_class", "(", "conn", ",", "info", ")", "]", ",", "True", ")", "return", "True", "conn", ".", "add_listener", "(", "async_add_service", ")" ]
[ 136, 0 ]
[ 150, 40 ]
python
en
['en', 'ky', 'en']
True
HomeKitMotionSensor.get_characteristic_types
(self)
Define the homekit characteristics the entity is tracking.
Define the homekit characteristics the entity is tracking.
def get_characteristic_types(self): """Define the homekit characteristics the entity is tracking.""" return [CharacteristicsTypes.MOTION_DETECTED]
[ "def", "get_characteristic_types", "(", "self", ")", ":", "return", "[", "CharacteristicsTypes", ".", "MOTION_DETECTED", "]" ]
[ 21, 4 ]
[ 23, 53 ]
python
en
['en', 'en', 'en']
True
HomeKitMotionSensor.device_class
(self)
Define this binary_sensor as a motion sensor.
Define this binary_sensor as a motion sensor.
def device_class(self): """Define this binary_sensor as a motion sensor.""" return DEVICE_CLASS_MOTION
[ "def", "device_class", "(", "self", ")", ":", "return", "DEVICE_CLASS_MOTION" ]
[ 26, 4 ]
[ 28, 34 ]
python
en
['en', 'pt', 'en']
True
HomeKitMotionSensor.is_on
(self)
Has motion been detected.
Has motion been detected.
def is_on(self): """Has motion been detected.""" return self.service.value(CharacteristicsTypes.MOTION_DETECTED)
[ "def", "is_on", "(", "self", ")", ":", "return", "self", ".", "service", ".", "value", "(", "CharacteristicsTypes", ".", "MOTION_DETECTED", ")" ]
[ 31, 4 ]
[ 33, 71 ]
python
en
['nl', 'en', 'en']
True
HomeKitContactSensor.get_characteristic_types
(self)
Define the homekit characteristics the entity is tracking.
Define the homekit characteristics the entity is tracking.
def get_characteristic_types(self): """Define the homekit characteristics the entity is tracking.""" return [CharacteristicsTypes.CONTACT_STATE]
[ "def", "get_characteristic_types", "(", "self", ")", ":", "return", "[", "CharacteristicsTypes", ".", "CONTACT_STATE", "]" ]
[ 39, 4 ]
[ 41, 51 ]
python
en
['en', 'en', 'en']
True
HomeKitContactSensor.device_class
(self)
Define this binary_sensor as a opening sensor.
Define this binary_sensor as a opening sensor.
def device_class(self): """Define this binary_sensor as a opening sensor.""" return DEVICE_CLASS_OPENING
[ "def", "device_class", "(", "self", ")", ":", "return", "DEVICE_CLASS_OPENING" ]
[ 44, 4 ]
[ 46, 35 ]
python
en
['en', 'pt', 'en']
True
HomeKitContactSensor.is_on
(self)
Return true if the binary sensor is on/open.
Return true if the binary sensor is on/open.
def is_on(self): """Return true if the binary sensor is on/open.""" return self.service.value(CharacteristicsTypes.CONTACT_STATE) == 1
[ "def", "is_on", "(", "self", ")", ":", "return", "self", ".", "service", ".", "value", "(", "CharacteristicsTypes", ".", "CONTACT_STATE", ")", "==", "1" ]
[ 49, 4 ]
[ 51, 74 ]
python
en
['en', 'fy', 'en']
True
HomeKitSmokeSensor.device_class
(self)
Return the class of this sensor.
Return the class of this sensor.
def device_class(self) -> str: """Return the class of this sensor.""" return DEVICE_CLASS_SMOKE
[ "def", "device_class", "(", "self", ")", "->", "str", ":", "return", "DEVICE_CLASS_SMOKE" ]
[ 58, 4 ]
[ 60, 33 ]
python
en
['en', 'en', 'en']
True
HomeKitSmokeSensor.get_characteristic_types
(self)
Define the homekit characteristics the entity is tracking.
Define the homekit characteristics the entity is tracking.
def get_characteristic_types(self): """Define the homekit characteristics the entity is tracking.""" return [CharacteristicsTypes.SMOKE_DETECTED]
[ "def", "get_characteristic_types", "(", "self", ")", ":", "return", "[", "CharacteristicsTypes", ".", "SMOKE_DETECTED", "]" ]
[ 62, 4 ]
[ 64, 52 ]
python
en
['en', 'en', 'en']
True
HomeKitSmokeSensor.is_on
(self)
Return true if smoke is currently detected.
Return true if smoke is currently detected.
def is_on(self): """Return true if smoke is currently detected.""" return self.service.value(CharacteristicsTypes.SMOKE_DETECTED) == 1
[ "def", "is_on", "(", "self", ")", ":", "return", "self", ".", "service", ".", "value", "(", "CharacteristicsTypes", ".", "SMOKE_DETECTED", ")", "==", "1" ]
[ 67, 4 ]
[ 69, 75 ]
python
en
['en', 'en', 'en']
True
HomeKitCarbonMonoxideSensor.device_class
(self)
Return the class of this sensor.
Return the class of this sensor.
def device_class(self) -> str: """Return the class of this sensor.""" return DEVICE_CLASS_GAS
[ "def", "device_class", "(", "self", ")", "->", "str", ":", "return", "DEVICE_CLASS_GAS" ]
[ 76, 4 ]
[ 78, 31 ]
python
en
['en', 'en', 'en']
True
HomeKitCarbonMonoxideSensor.get_characteristic_types
(self)
Define the homekit characteristics the entity is tracking.
Define the homekit characteristics the entity is tracking.
def get_characteristic_types(self): """Define the homekit characteristics the entity is tracking.""" return [CharacteristicsTypes.CARBON_MONOXIDE_DETECTED]
[ "def", "get_characteristic_types", "(", "self", ")", ":", "return", "[", "CharacteristicsTypes", ".", "CARBON_MONOXIDE_DETECTED", "]" ]
[ 80, 4 ]
[ 82, 62 ]
python
en
['en', 'en', 'en']
True
HomeKitCarbonMonoxideSensor.is_on
(self)
Return true if CO is currently detected.
Return true if CO is currently detected.
def is_on(self): """Return true if CO is currently detected.""" return self.service.value(CharacteristicsTypes.CARBON_MONOXIDE_DETECTED) == 1
[ "def", "is_on", "(", "self", ")", ":", "return", "self", ".", "service", ".", "value", "(", "CharacteristicsTypes", ".", "CARBON_MONOXIDE_DETECTED", ")", "==", "1" ]
[ 85, 4 ]
[ 87, 85 ]
python
en
['en', 'en', 'en']
True
HomeKitOccupancySensor.device_class
(self)
Return the class of this sensor.
Return the class of this sensor.
def device_class(self) -> str: """Return the class of this sensor.""" return DEVICE_CLASS_OCCUPANCY
[ "def", "device_class", "(", "self", ")", "->", "str", ":", "return", "DEVICE_CLASS_OCCUPANCY" ]
[ 94, 4 ]
[ 96, 37 ]
python
en
['en', 'en', 'en']
True
HomeKitOccupancySensor.get_characteristic_types
(self)
Define the homekit characteristics the entity is tracking.
Define the homekit characteristics the entity is tracking.
def get_characteristic_types(self): """Define the homekit characteristics the entity is tracking.""" return [CharacteristicsTypes.OCCUPANCY_DETECTED]
[ "def", "get_characteristic_types", "(", "self", ")", ":", "return", "[", "CharacteristicsTypes", ".", "OCCUPANCY_DETECTED", "]" ]
[ 98, 4 ]
[ 100, 56 ]
python
en
['en', 'en', 'en']
True
HomeKitOccupancySensor.is_on
(self)
Return true if occupancy is currently detected.
Return true if occupancy is currently detected.
def is_on(self): """Return true if occupancy is currently detected.""" return self.service.value(CharacteristicsTypes.OCCUPANCY_DETECTED) == 1
[ "def", "is_on", "(", "self", ")", ":", "return", "self", ".", "service", ".", "value", "(", "CharacteristicsTypes", ".", "OCCUPANCY_DETECTED", ")", "==", "1" ]
[ 103, 4 ]
[ 105, 79 ]
python
en
['en', 'en', 'en']
True
HomeKitLeakSensor.get_characteristic_types
(self)
Define the homekit characteristics the entity is tracking.
Define the homekit characteristics the entity is tracking.
def get_characteristic_types(self): """Define the homekit characteristics the entity is tracking.""" return [CharacteristicsTypes.LEAK_DETECTED]
[ "def", "get_characteristic_types", "(", "self", ")", ":", "return", "[", "CharacteristicsTypes", ".", "LEAK_DETECTED", "]" ]
[ 111, 4 ]
[ 113, 51 ]
python
en
['en', 'en', 'en']
True
HomeKitLeakSensor.device_class
(self)
Define this binary_sensor as a leak sensor.
Define this binary_sensor as a leak sensor.
def device_class(self): """Define this binary_sensor as a leak sensor.""" return DEVICE_CLASS_MOISTURE
[ "def", "device_class", "(", "self", ")", ":", "return", "DEVICE_CLASS_MOISTURE" ]
[ 116, 4 ]
[ 118, 36 ]
python
en
['en', 'pt', 'en']
True
HomeKitLeakSensor.is_on
(self)
Return true if a leak is detected from the binary sensor.
Return true if a leak is detected from the binary sensor.
def is_on(self): """Return true if a leak is detected from the binary sensor.""" return self.service.value(CharacteristicsTypes.LEAK_DETECTED) == 1
[ "def", "is_on", "(", "self", ")", ":", "return", "self", ".", "service", ".", "value", "(", "CharacteristicsTypes", ".", "LEAK_DETECTED", ")", "==", "1" ]
[ 121, 4 ]
[ 123, 74 ]
python
en
['en', 'en', 'en']
True
async_register_signal_handling
(hass: HomeAssistant)
Register system signal handler for core.
Register system signal handler for core.
def async_register_signal_handling(hass: HomeAssistant) -> None: """Register system signal handler for core.""" if sys.platform != "win32": @callback def async_signal_handle(exit_code: int) -> None: """Wrap signal handling. * queue call to shutdown task * re-instate default handler """ hass.loop.remove_signal_handler(signal.SIGTERM) hass.loop.remove_signal_handler(signal.SIGINT) hass.async_create_task(hass.async_stop(exit_code)) try: hass.loop.add_signal_handler(signal.SIGTERM, async_signal_handle, 0) except ValueError: _LOGGER.warning("Could not bind to SIGTERM") try: hass.loop.add_signal_handler(signal.SIGINT, async_signal_handle, 0) except ValueError: _LOGGER.warning("Could not bind to SIGINT") try: hass.loop.add_signal_handler( signal.SIGHUP, async_signal_handle, RESTART_EXIT_CODE ) except ValueError: _LOGGER.warning("Could not bind to SIGHUP") else: old_sigterm = None old_sigint = None @callback def async_signal_handle(exit_code: int, frame: FrameType) -> None: """Wrap signal handling. * queue call to shutdown task * re-instate default handler """ signal.signal(signal.SIGTERM, old_sigterm) signal.signal(signal.SIGINT, old_sigint) hass.async_create_task(hass.async_stop(exit_code)) try: old_sigterm = signal.signal(signal.SIGTERM, async_signal_handle) except ValueError: _LOGGER.warning("Could not bind to SIGTERM") try: old_sigint = signal.signal(signal.SIGINT, async_signal_handle) except ValueError: _LOGGER.warning("Could not bind to SIGINT")
[ "def", "async_register_signal_handling", "(", "hass", ":", "HomeAssistant", ")", "->", "None", ":", "if", "sys", ".", "platform", "!=", "\"win32\"", ":", "@", "callback", "def", "async_signal_handle", "(", "exit_code", ":", "int", ")", "->", "None", ":", "\"\"\"Wrap signal handling.\n\n * queue call to shutdown task\n * re-instate default handler\n \"\"\"", "hass", ".", "loop", ".", "remove_signal_handler", "(", "signal", ".", "SIGTERM", ")", "hass", ".", "loop", ".", "remove_signal_handler", "(", "signal", ".", "SIGINT", ")", "hass", ".", "async_create_task", "(", "hass", ".", "async_stop", "(", "exit_code", ")", ")", "try", ":", "hass", ".", "loop", ".", "add_signal_handler", "(", "signal", ".", "SIGTERM", ",", "async_signal_handle", ",", "0", ")", "except", "ValueError", ":", "_LOGGER", ".", "warning", "(", "\"Could not bind to SIGTERM\"", ")", "try", ":", "hass", ".", "loop", ".", "add_signal_handler", "(", "signal", ".", "SIGINT", ",", "async_signal_handle", ",", "0", ")", "except", "ValueError", ":", "_LOGGER", ".", "warning", "(", "\"Could not bind to SIGINT\"", ")", "try", ":", "hass", ".", "loop", ".", "add_signal_handler", "(", "signal", ".", "SIGHUP", ",", "async_signal_handle", ",", "RESTART_EXIT_CODE", ")", "except", "ValueError", ":", "_LOGGER", ".", "warning", "(", "\"Could not bind to SIGHUP\"", ")", "else", ":", "old_sigterm", "=", "None", "old_sigint", "=", "None", "@", "callback", "def", "async_signal_handle", "(", "exit_code", ":", "int", ",", "frame", ":", "FrameType", ")", "->", "None", ":", "\"\"\"Wrap signal handling.\n\n * queue call to shutdown task\n * re-instate default handler\n \"\"\"", "signal", ".", "signal", "(", "signal", ".", "SIGTERM", ",", "old_sigterm", ")", "signal", ".", "signal", "(", "signal", ".", "SIGINT", ",", "old_sigint", ")", "hass", ".", "async_create_task", "(", "hass", ".", "async_stop", "(", "exit_code", ")", ")", "try", ":", "old_sigterm", "=", "signal", ".", "signal", "(", "signal", ".", "SIGTERM", ",", "async_signal_handle", ")", "except", "ValueError", ":", "_LOGGER", ".", "warning", "(", "\"Could not bind to SIGTERM\"", ")", "try", ":", "old_sigint", "=", "signal", ".", "signal", "(", "signal", ".", "SIGINT", ",", "async_signal_handle", ")", "except", "ValueError", ":", "_LOGGER", ".", "warning", "(", "\"Could not bind to SIGINT\"", ")" ]
[ 15, 0 ]
[ 70, 55 ]
python
da
['da', 'da', 'en']
True
test_validate
(hass)
Test validating pin.
Test validating pin.
async def test_validate(hass): """Test validating pin.""" auth_module = await auth_mfa_module_from_config( hass, { "type": "insecure_example", "data": [{"user_id": "test-user", "pin": "123456"}], }, ) result = await auth_module.async_validate("test-user", {"pin": "123456"}) assert result is True result = await auth_module.async_validate("test-user", {"pin": "invalid"}) assert result is False result = await auth_module.async_validate("invalid-user", {"pin": "123456"}) assert result is False
[ "async", "def", "test_validate", "(", "hass", ")", ":", "auth_module", "=", "await", "auth_mfa_module_from_config", "(", "hass", ",", "{", "\"type\"", ":", "\"insecure_example\"", ",", "\"data\"", ":", "[", "{", "\"user_id\"", ":", "\"test-user\"", ",", "\"pin\"", ":", "\"123456\"", "}", "]", ",", "}", ",", ")", "result", "=", "await", "auth_module", ".", "async_validate", "(", "\"test-user\"", ",", "{", "\"pin\"", ":", "\"123456\"", "}", ")", "assert", "result", "is", "True", "result", "=", "await", "auth_module", ".", "async_validate", "(", "\"test-user\"", ",", "{", "\"pin\"", ":", "\"invalid\"", "}", ")", "assert", "result", "is", "False", "result", "=", "await", "auth_module", ".", "async_validate", "(", "\"invalid-user\"", ",", "{", "\"pin\"", ":", "\"123456\"", "}", ")", "assert", "result", "is", "False" ]
[ 8, 0 ]
[ 25, 26 ]
python
fil
['nl', 'fil', 'it']
False
test_setup_user
(hass)
Test setup user.
Test setup user.
async def test_setup_user(hass): """Test setup user.""" auth_module = await auth_mfa_module_from_config( hass, {"type": "insecure_example", "data": []} ) await auth_module.async_setup_user("test-user", {"pin": "123456"}) assert len(auth_module._data) == 1 result = await auth_module.async_validate("test-user", {"pin": "123456"}) assert result is True
[ "async", "def", "test_setup_user", "(", "hass", ")", ":", "auth_module", "=", "await", "auth_mfa_module_from_config", "(", "hass", ",", "{", "\"type\"", ":", "\"insecure_example\"", ",", "\"data\"", ":", "[", "]", "}", ")", "await", "auth_module", ".", "async_setup_user", "(", "\"test-user\"", ",", "{", "\"pin\"", ":", "\"123456\"", "}", ")", "assert", "len", "(", "auth_module", ".", "_data", ")", "==", "1", "result", "=", "await", "auth_module", ".", "async_validate", "(", "\"test-user\"", ",", "{", "\"pin\"", ":", "\"123456\"", "}", ")", "assert", "result", "is", "True" ]
[ 28, 0 ]
[ 38, 25 ]
python
en
['en', 'da', 'en']
True
test_depose_user
(hass)
Test despose user.
Test despose user.
async def test_depose_user(hass): """Test despose user.""" auth_module = await auth_mfa_module_from_config( hass, { "type": "insecure_example", "data": [{"user_id": "test-user", "pin": "123456"}], }, ) assert len(auth_module._data) == 1 await auth_module.async_depose_user("test-user") assert len(auth_module._data) == 0
[ "async", "def", "test_depose_user", "(", "hass", ")", ":", "auth_module", "=", "await", "auth_mfa_module_from_config", "(", "hass", ",", "{", "\"type\"", ":", "\"insecure_example\"", ",", "\"data\"", ":", "[", "{", "\"user_id\"", ":", "\"test-user\"", ",", "\"pin\"", ":", "\"123456\"", "}", "]", ",", "}", ",", ")", "assert", "len", "(", "auth_module", ".", "_data", ")", "==", "1", "await", "auth_module", ".", "async_depose_user", "(", "\"test-user\"", ")", "assert", "len", "(", "auth_module", ".", "_data", ")", "==", "0" ]
[ 41, 0 ]
[ 53, 38 ]
python
ca
['ca', 'la', 'fr']
False
test_is_user_setup
(hass)
Test is user setup.
Test is user setup.
async def test_is_user_setup(hass): """Test is user setup.""" auth_module = await auth_mfa_module_from_config( hass, { "type": "insecure_example", "data": [{"user_id": "test-user", "pin": "123456"}], }, ) assert await auth_module.async_is_user_setup("test-user") is True assert await auth_module.async_is_user_setup("invalid-user") is False
[ "async", "def", "test_is_user_setup", "(", "hass", ")", ":", "auth_module", "=", "await", "auth_mfa_module_from_config", "(", "hass", ",", "{", "\"type\"", ":", "\"insecure_example\"", ",", "\"data\"", ":", "[", "{", "\"user_id\"", ":", "\"test-user\"", ",", "\"pin\"", ":", "\"123456\"", "}", "]", ",", "}", ",", ")", "assert", "await", "auth_module", ".", "async_is_user_setup", "(", "\"test-user\"", ")", "is", "True", "assert", "await", "auth_module", ".", "async_is_user_setup", "(", "\"invalid-user\"", ")", "is", "False" ]
[ 56, 0 ]
[ 66, 73 ]
python
en
['en', 'da', 'en']
True
test_login
(hass)
Test login flow with auth module.
Test login flow with auth module.
async def test_login(hass): """Test login flow with auth module.""" hass.auth = await auth.auth_manager_from_config( hass, [ { "type": "insecure_example", "users": [{"username": "test-user", "password": "test-pass"}], } ], [ { "type": "insecure_example", "data": [{"user_id": "mock-user", "pin": "123456"}], } ], ) user = MockUser( id="mock-user", is_owner=False, is_active=False, name="Paulus" ).add_to_auth_manager(hass.auth) await hass.auth.async_link_user( user, Credentials( id="mock-id", auth_provider_type="insecure_example", auth_provider_id=None, data={"username": "test-user"}, is_new=False, ), ) provider = hass.auth.auth_providers[0] result = await hass.auth.login_flow.async_init((provider.type, provider.id)) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM result = await hass.auth.login_flow.async_configure( result["flow_id"], {"username": "incorrect-user", "password": "test-pass"} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["errors"]["base"] == "invalid_auth" result = await hass.auth.login_flow.async_configure( result["flow_id"], {"username": "test-user", "password": "incorrect-pass"} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["errors"]["base"] == "invalid_auth" result = await hass.auth.login_flow.async_configure( result["flow_id"], {"username": "test-user", "password": "test-pass"} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "mfa" assert result["data_schema"].schema.get("pin") == str result = await hass.auth.login_flow.async_configure( result["flow_id"], {"pin": "invalid-code"} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["errors"]["base"] == "invalid_code" result = await hass.auth.login_flow.async_configure( result["flow_id"], {"pin": "123456"} ) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["data"].id == "mock-user"
[ "async", "def", "test_login", "(", "hass", ")", ":", "hass", ".", "auth", "=", "await", "auth", ".", "auth_manager_from_config", "(", "hass", ",", "[", "{", "\"type\"", ":", "\"insecure_example\"", ",", "\"users\"", ":", "[", "{", "\"username\"", ":", "\"test-user\"", ",", "\"password\"", ":", "\"test-pass\"", "}", "]", ",", "}", "]", ",", "[", "{", "\"type\"", ":", "\"insecure_example\"", ",", "\"data\"", ":", "[", "{", "\"user_id\"", ":", "\"mock-user\"", ",", "\"pin\"", ":", "\"123456\"", "}", "]", ",", "}", "]", ",", ")", "user", "=", "MockUser", "(", "id", "=", "\"mock-user\"", ",", "is_owner", "=", "False", ",", "is_active", "=", "False", ",", "name", "=", "\"Paulus\"", ")", ".", "add_to_auth_manager", "(", "hass", ".", "auth", ")", "await", "hass", ".", "auth", ".", "async_link_user", "(", "user", ",", "Credentials", "(", "id", "=", "\"mock-id\"", ",", "auth_provider_type", "=", "\"insecure_example\"", ",", "auth_provider_id", "=", "None", ",", "data", "=", "{", "\"username\"", ":", "\"test-user\"", "}", ",", "is_new", "=", "False", ",", ")", ",", ")", "provider", "=", "hass", ".", "auth", ".", "auth_providers", "[", "0", "]", "result", "=", "await", "hass", ".", "auth", ".", "login_flow", ".", "async_init", "(", "(", "provider", ".", "type", ",", "provider", ".", "id", ")", ")", "assert", "result", "[", "\"type\"", "]", "==", "data_entry_flow", ".", "RESULT_TYPE_FORM", "result", "=", "await", "hass", ".", "auth", ".", "login_flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "\"username\"", ":", "\"incorrect-user\"", ",", "\"password\"", ":", "\"test-pass\"", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "data_entry_flow", ".", "RESULT_TYPE_FORM", "assert", "result", "[", "\"errors\"", "]", "[", "\"base\"", "]", "==", "\"invalid_auth\"", "result", "=", "await", "hass", ".", "auth", ".", "login_flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "\"username\"", ":", "\"test-user\"", ",", "\"password\"", ":", "\"incorrect-pass\"", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "data_entry_flow", ".", "RESULT_TYPE_FORM", "assert", "result", "[", "\"errors\"", "]", "[", "\"base\"", "]", "==", "\"invalid_auth\"", "result", "=", "await", "hass", ".", "auth", ".", "login_flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "\"username\"", ":", "\"test-user\"", ",", "\"password\"", ":", "\"test-pass\"", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "data_entry_flow", ".", "RESULT_TYPE_FORM", "assert", "result", "[", "\"step_id\"", "]", "==", "\"mfa\"", "assert", "result", "[", "\"data_schema\"", "]", ".", "schema", ".", "get", "(", "\"pin\"", ")", "==", "str", "result", "=", "await", "hass", ".", "auth", ".", "login_flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "\"pin\"", ":", "\"invalid-code\"", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "data_entry_flow", ".", "RESULT_TYPE_FORM", "assert", "result", "[", "\"errors\"", "]", "[", "\"base\"", "]", "==", "\"invalid_code\"", "result", "=", "await", "hass", ".", "auth", ".", "login_flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "\"pin\"", ":", "\"123456\"", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "data_entry_flow", ".", "RESULT_TYPE_CREATE_ENTRY", "assert", "result", "[", "\"data\"", "]", ".", "id", "==", "\"mock-user\"" ]
[ 69, 0 ]
[ 133, 43 ]
python
en
['en', 'en', 'en']
True
test_setup_flow
(hass)
Test validating pin.
Test validating pin.
async def test_setup_flow(hass): """Test validating pin.""" auth_module = await auth_mfa_module_from_config( hass, { "type": "insecure_example", "data": [{"user_id": "test-user", "pin": "123456"}], }, ) flow = await auth_module.async_setup_flow("new-user") result = await flow.async_step_init() assert result["type"] == data_entry_flow.RESULT_TYPE_FORM result = await flow.async_step_init({"pin": "abcdefg"}) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert auth_module._data[1]["user_id"] == "new-user" assert auth_module._data[1]["pin"] == "abcdefg"
[ "async", "def", "test_setup_flow", "(", "hass", ")", ":", "auth_module", "=", "await", "auth_mfa_module_from_config", "(", "hass", ",", "{", "\"type\"", ":", "\"insecure_example\"", ",", "\"data\"", ":", "[", "{", "\"user_id\"", ":", "\"test-user\"", ",", "\"pin\"", ":", "\"123456\"", "}", "]", ",", "}", ",", ")", "flow", "=", "await", "auth_module", ".", "async_setup_flow", "(", "\"new-user\"", ")", "result", "=", "await", "flow", ".", "async_step_init", "(", ")", "assert", "result", "[", "\"type\"", "]", "==", "data_entry_flow", ".", "RESULT_TYPE_FORM", "result", "=", "await", "flow", ".", "async_step_init", "(", "{", "\"pin\"", ":", "\"abcdefg\"", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "data_entry_flow", ".", "RESULT_TYPE_CREATE_ENTRY", "assert", "auth_module", ".", "_data", "[", "1", "]", "[", "\"user_id\"", "]", "==", "\"new-user\"", "assert", "auth_module", ".", "_data", "[", "1", "]", "[", "\"pin\"", "]", "==", "\"abcdefg\"" ]
[ 136, 0 ]
[ 154, 51 ]
python
fil
['nl', 'fil', 'it']
False
device_switch
(hass, zigpy_device_mock, zha_device_joined)
Test zha switch platform.
Test zha switch platform.
async def device_switch(hass, zigpy_device_mock, zha_device_joined): """Test zha switch platform.""" zigpy_device = zigpy_device_mock( { 1: { "in_clusters": [general.OnOff.cluster_id, general.Basic.cluster_id], "out_clusters": [], "device_type": zigpy.profiles.zha.DeviceType.ON_OFF_SWITCH, } }, ieee=IEEE_SWITCH_DEVICE, ) zha_device = await zha_device_joined(zigpy_device) zha_device.available = True return zha_device
[ "async", "def", "device_switch", "(", "hass", ",", "zigpy_device_mock", ",", "zha_device_joined", ")", ":", "zigpy_device", "=", "zigpy_device_mock", "(", "{", "1", ":", "{", "\"in_clusters\"", ":", "[", "general", ".", "OnOff", ".", "cluster_id", ",", "general", ".", "Basic", ".", "cluster_id", "]", ",", "\"out_clusters\"", ":", "[", "]", ",", "\"device_type\"", ":", "zigpy", ".", "profiles", ".", "zha", ".", "DeviceType", ".", "ON_OFF_SWITCH", ",", "}", "}", ",", "ieee", "=", "IEEE_SWITCH_DEVICE", ",", ")", "zha_device", "=", "await", "zha_device_joined", "(", "zigpy_device", ")", "zha_device", ".", "available", "=", "True", "return", "zha_device" ]
[ 50, 0 ]
[ 65, 21 ]
python
pl
['cs', 'pl', 'pl']
True
device_groupable
(hass, zigpy_device_mock, zha_device_joined)
Test zha light platform.
Test zha light platform.
async def device_groupable(hass, zigpy_device_mock, zha_device_joined): """Test zha light platform.""" zigpy_device = zigpy_device_mock( { 1: { "in_clusters": [ general.OnOff.cluster_id, general.Basic.cluster_id, general.Groups.cluster_id, ], "out_clusters": [], "device_type": zigpy.profiles.zha.DeviceType.ON_OFF_SWITCH, } }, ieee=IEEE_GROUPABLE_DEVICE, ) zha_device = await zha_device_joined(zigpy_device) zha_device.available = True return zha_device
[ "async", "def", "device_groupable", "(", "hass", ",", "zigpy_device_mock", ",", "zha_device_joined", ")", ":", "zigpy_device", "=", "zigpy_device_mock", "(", "{", "1", ":", "{", "\"in_clusters\"", ":", "[", "general", ".", "OnOff", ".", "cluster_id", ",", "general", ".", "Basic", ".", "cluster_id", ",", "general", ".", "Groups", ".", "cluster_id", ",", "]", ",", "\"out_clusters\"", ":", "[", "]", ",", "\"device_type\"", ":", "zigpy", ".", "profiles", ".", "zha", ".", "DeviceType", ".", "ON_OFF_SWITCH", ",", "}", "}", ",", "ieee", "=", "IEEE_GROUPABLE_DEVICE", ",", ")", "zha_device", "=", "await", "zha_device_joined", "(", "zigpy_device", ")", "zha_device", ".", "available", "=", "True", "return", "zha_device" ]
[ 69, 0 ]
[ 88, 21 ]
python
cs
['cs', 'lb', 'pl']
False
zha_client
(hass, hass_ws_client, device_switch, device_groupable)
Test zha switch platform.
Test zha switch platform.
async def zha_client(hass, hass_ws_client, device_switch, device_groupable): """Test zha switch platform.""" # load the ZHA API async_load_api(hass) return await hass_ws_client(hass)
[ "async", "def", "zha_client", "(", "hass", ",", "hass_ws_client", ",", "device_switch", ",", "device_groupable", ")", ":", "# load the ZHA API", "async_load_api", "(", "hass", ")", "return", "await", "hass_ws_client", "(", "hass", ")" ]
[ 92, 0 ]
[ 97, 37 ]
python
pl
['cs', 'pl', 'pl']
True
test_device_clusters
(hass, zha_client)
Test getting device cluster info.
Test getting device cluster info.
async def test_device_clusters(hass, zha_client): """Test getting device cluster info.""" await zha_client.send_json( {ID: 5, TYPE: "zha/devices/clusters", ATTR_IEEE: IEEE_SWITCH_DEVICE} ) msg = await zha_client.receive_json() assert len(msg["result"]) == 2 cluster_infos = sorted(msg["result"], key=lambda k: k[ID]) cluster_info = cluster_infos[0] assert cluster_info[TYPE] == CLUSTER_TYPE_IN assert cluster_info[ID] == 0 assert cluster_info[ATTR_NAME] == "Basic" cluster_info = cluster_infos[1] assert cluster_info[TYPE] == CLUSTER_TYPE_IN assert cluster_info[ID] == 6 assert cluster_info[ATTR_NAME] == "OnOff"
[ "async", "def", "test_device_clusters", "(", "hass", ",", "zha_client", ")", ":", "await", "zha_client", ".", "send_json", "(", "{", "ID", ":", "5", ",", "TYPE", ":", "\"zha/devices/clusters\"", ",", "ATTR_IEEE", ":", "IEEE_SWITCH_DEVICE", "}", ")", "msg", "=", "await", "zha_client", ".", "receive_json", "(", ")", "assert", "len", "(", "msg", "[", "\"result\"", "]", ")", "==", "2", "cluster_infos", "=", "sorted", "(", "msg", "[", "\"result\"", "]", ",", "key", "=", "lambda", "k", ":", "k", "[", "ID", "]", ")", "cluster_info", "=", "cluster_infos", "[", "0", "]", "assert", "cluster_info", "[", "TYPE", "]", "==", "CLUSTER_TYPE_IN", "assert", "cluster_info", "[", "ID", "]", "==", "0", "assert", "cluster_info", "[", "ATTR_NAME", "]", "==", "\"Basic\"", "cluster_info", "=", "cluster_infos", "[", "1", "]", "assert", "cluster_info", "[", "TYPE", "]", "==", "CLUSTER_TYPE_IN", "assert", "cluster_info", "[", "ID", "]", "==", "6", "assert", "cluster_info", "[", "ATTR_NAME", "]", "==", "\"OnOff\"" ]
[ 100, 0 ]
[ 120, 45 ]
python
en
['de', 'en', 'en']
True
test_device_cluster_attributes
(zha_client)
Test getting device cluster attributes.
Test getting device cluster attributes.
async def test_device_cluster_attributes(zha_client): """Test getting device cluster attributes.""" await zha_client.send_json( { ID: 5, TYPE: "zha/devices/clusters/attributes", ATTR_ENDPOINT_ID: 1, ATTR_IEEE: IEEE_SWITCH_DEVICE, ATTR_CLUSTER_ID: 6, ATTR_CLUSTER_TYPE: CLUSTER_TYPE_IN, } ) msg = await zha_client.receive_json() attributes = msg["result"] assert len(attributes) == 4 for attribute in attributes: assert attribute[ID] is not None assert attribute[ATTR_NAME] is not None
[ "async", "def", "test_device_cluster_attributes", "(", "zha_client", ")", ":", "await", "zha_client", ".", "send_json", "(", "{", "ID", ":", "5", ",", "TYPE", ":", "\"zha/devices/clusters/attributes\"", ",", "ATTR_ENDPOINT_ID", ":", "1", ",", "ATTR_IEEE", ":", "IEEE_SWITCH_DEVICE", ",", "ATTR_CLUSTER_ID", ":", "6", ",", "ATTR_CLUSTER_TYPE", ":", "CLUSTER_TYPE_IN", ",", "}", ")", "msg", "=", "await", "zha_client", ".", "receive_json", "(", ")", "attributes", "=", "msg", "[", "\"result\"", "]", "assert", "len", "(", "attributes", ")", "==", "4", "for", "attribute", "in", "attributes", ":", "assert", "attribute", "[", "ID", "]", "is", "not", "None", "assert", "attribute", "[", "ATTR_NAME", "]", "is", "not", "None" ]
[ 123, 0 ]
[ 143, 47 ]
python
en
['de', 'en', 'en']
True
test_device_cluster_commands
(zha_client)
Test getting device cluster commands.
Test getting device cluster commands.
async def test_device_cluster_commands(zha_client): """Test getting device cluster commands.""" await zha_client.send_json( { ID: 5, TYPE: "zha/devices/clusters/commands", ATTR_ENDPOINT_ID: 1, ATTR_IEEE: IEEE_SWITCH_DEVICE, ATTR_CLUSTER_ID: 6, ATTR_CLUSTER_TYPE: CLUSTER_TYPE_IN, } ) msg = await zha_client.receive_json() commands = msg["result"] assert len(commands) == 6 for command in commands: assert command[ID] is not None assert command[ATTR_NAME] is not None assert command[TYPE] is not None
[ "async", "def", "test_device_cluster_commands", "(", "zha_client", ")", ":", "await", "zha_client", ".", "send_json", "(", "{", "ID", ":", "5", ",", "TYPE", ":", "\"zha/devices/clusters/commands\"", ",", "ATTR_ENDPOINT_ID", ":", "1", ",", "ATTR_IEEE", ":", "IEEE_SWITCH_DEVICE", ",", "ATTR_CLUSTER_ID", ":", "6", ",", "ATTR_CLUSTER_TYPE", ":", "CLUSTER_TYPE_IN", ",", "}", ")", "msg", "=", "await", "zha_client", ".", "receive_json", "(", ")", "commands", "=", "msg", "[", "\"result\"", "]", "assert", "len", "(", "commands", ")", "==", "6", "for", "command", "in", "commands", ":", "assert", "command", "[", "ID", "]", "is", "not", "None", "assert", "command", "[", "ATTR_NAME", "]", "is", "not", "None", "assert", "command", "[", "TYPE", "]", "is", "not", "None" ]
[ 146, 0 ]
[ 167, 40 ]
python
en
['de', 'en', 'en']
True
test_list_devices
(zha_client)
Test getting zha devices.
Test getting zha devices.
async def test_list_devices(zha_client): """Test getting zha devices.""" await zha_client.send_json({ID: 5, TYPE: "zha/devices"}) msg = await zha_client.receive_json() devices = msg["result"] assert len(devices) == 2 msg_id = 100 for device in devices: msg_id += 1 assert device[ATTR_IEEE] is not None assert device[ATTR_MANUFACTURER] is not None assert device[ATTR_MODEL] is not None assert device[ATTR_NAME] is not None assert device[ATTR_QUIRK_APPLIED] is not None assert device["entities"] is not None assert device[ATTR_NEIGHBORS] is not None assert device[ATTR_ENDPOINT_NAMES] is not None for entity_reference in device["entities"]: assert entity_reference[ATTR_NAME] is not None assert entity_reference["entity_id"] is not None await zha_client.send_json( {ID: msg_id, TYPE: "zha/device", ATTR_IEEE: device[ATTR_IEEE]} ) msg = await zha_client.receive_json() device2 = msg["result"] assert device == device2
[ "async", "def", "test_list_devices", "(", "zha_client", ")", ":", "await", "zha_client", ".", "send_json", "(", "{", "ID", ":", "5", ",", "TYPE", ":", "\"zha/devices\"", "}", ")", "msg", "=", "await", "zha_client", ".", "receive_json", "(", ")", "devices", "=", "msg", "[", "\"result\"", "]", "assert", "len", "(", "devices", ")", "==", "2", "msg_id", "=", "100", "for", "device", "in", "devices", ":", "msg_id", "+=", "1", "assert", "device", "[", "ATTR_IEEE", "]", "is", "not", "None", "assert", "device", "[", "ATTR_MANUFACTURER", "]", "is", "not", "None", "assert", "device", "[", "ATTR_MODEL", "]", "is", "not", "None", "assert", "device", "[", "ATTR_NAME", "]", "is", "not", "None", "assert", "device", "[", "ATTR_QUIRK_APPLIED", "]", "is", "not", "None", "assert", "device", "[", "\"entities\"", "]", "is", "not", "None", "assert", "device", "[", "ATTR_NEIGHBORS", "]", "is", "not", "None", "assert", "device", "[", "ATTR_ENDPOINT_NAMES", "]", "is", "not", "None", "for", "entity_reference", "in", "device", "[", "\"entities\"", "]", ":", "assert", "entity_reference", "[", "ATTR_NAME", "]", "is", "not", "None", "assert", "entity_reference", "[", "\"entity_id\"", "]", "is", "not", "None", "await", "zha_client", ".", "send_json", "(", "{", "ID", ":", "msg_id", ",", "TYPE", ":", "\"zha/device\"", ",", "ATTR_IEEE", ":", "device", "[", "ATTR_IEEE", "]", "}", ")", "msg", "=", "await", "zha_client", ".", "receive_json", "(", ")", "device2", "=", "msg", "[", "\"result\"", "]", "assert", "device", "==", "device2" ]
[ 170, 0 ]
[ 200, 32 ]
python
en
['br', 'en', 'en']
True