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_proxy_config | (hass) | Test use_x_forwarded_for must config together with trusted_proxies. | Test use_x_forwarded_for must config together with trusted_proxies. | async def test_proxy_config(hass):
"""Test use_x_forwarded_for must config together with trusted_proxies."""
assert (
await async_setup_component(
hass,
"http",
{
"http": {
http.CONF_USE_X_FORWARDED_FOR: True,
http.CONF_TRUSTED_PROXIES: ["127.0.0.1"],
}
},
)
is True
) | [
"async",
"def",
"test_proxy_config",
"(",
"hass",
")",
":",
"assert",
"(",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"http\"",
",",
"{",
"\"http\"",
":",
"{",
"http",
".",
"CONF_USE_X_FORWARDED_FOR",
":",
"True",
",",
"http",
".",
"CONF_TRUSTED_PRO... | [
146,
0
] | [
160,
5
] | python | en | ['en', 'en', 'en'] | True |
test_proxy_config_only_use_xff | (hass) | Test use_x_forwarded_for must config together with trusted_proxies. | Test use_x_forwarded_for must config together with trusted_proxies. | async def test_proxy_config_only_use_xff(hass):
"""Test use_x_forwarded_for must config together with trusted_proxies."""
assert (
await async_setup_component(
hass, "http", {"http": {http.CONF_USE_X_FORWARDED_FOR: True}}
)
is not True
) | [
"async",
"def",
"test_proxy_config_only_use_xff",
"(",
"hass",
")",
":",
"assert",
"(",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"http\"",
",",
"{",
"\"http\"",
":",
"{",
"http",
".",
"CONF_USE_X_FORWARDED_FOR",
":",
"True",
"}",
"}",
")",
"is",
... | [
163,
0
] | [
170,
5
] | python | en | ['en', 'en', 'en'] | True |
test_proxy_config_only_trust_proxies | (hass) | Test use_x_forwarded_for must config together with trusted_proxies. | Test use_x_forwarded_for must config together with trusted_proxies. | async def test_proxy_config_only_trust_proxies(hass):
"""Test use_x_forwarded_for must config together with trusted_proxies."""
assert (
await async_setup_component(
hass, "http", {"http": {http.CONF_TRUSTED_PROXIES: ["127.0.0.1"]}}
)
is not True
) | [
"async",
"def",
"test_proxy_config_only_trust_proxies",
"(",
"hass",
")",
":",
"assert",
"(",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"http\"",
",",
"{",
"\"http\"",
":",
"{",
"http",
".",
"CONF_TRUSTED_PROXIES",
":",
"[",
"\"127.0.0.1\"",
"]",
"}"... | [
173,
0
] | [
180,
5
] | python | en | ['en', 'en', 'en'] | True |
test_ssl_profile_defaults_modern | (hass) | Test default ssl profile. | Test default ssl profile. | async def test_ssl_profile_defaults_modern(hass):
"""Test default ssl profile."""
assert await async_setup_component(hass, "http", {}) is True
hass.http.ssl_certificate = "bla"
with patch("ssl.SSLContext.load_cert_chain"), patch(
"homeassistant.util.ssl.server_context_modern",
side_effect=server_context_modern,
) as mock_context:
await hass.async_start()
await hass.async_block_till_done()
assert len(mock_context.mock_calls) == 1 | [
"async",
"def",
"test_ssl_profile_defaults_modern",
"(",
"hass",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"http\"",
",",
"{",
"}",
")",
"is",
"True",
"hass",
".",
"http",
".",
"ssl_certificate",
"=",
"\"bla\"",
"with",
"patch",... | [
183,
0
] | [
196,
44
] | python | fr | ['fr', 'fr', 'en'] | True |
test_ssl_profile_change_intermediate | (hass) | Test setting ssl profile to intermediate. | Test setting ssl profile to intermediate. | async def test_ssl_profile_change_intermediate(hass):
"""Test setting ssl profile to intermediate."""
assert (
await async_setup_component(
hass, "http", {"http": {"ssl_profile": "intermediate"}}
)
is True
)
hass.http.ssl_certificate = "bla"
with patch("ssl.SSLContext.load_cert_chain"), patch(
"homeassistant.util.ssl.server_context_intermediate",
side_effect=server_context_intermediate,
) as mock_context:
await hass.async_start()
await hass.async_block_till_done()
assert len(mock_context.mock_calls) == 1 | [
"async",
"def",
"test_ssl_profile_change_intermediate",
"(",
"hass",
")",
":",
"assert",
"(",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"http\"",
",",
"{",
"\"http\"",
":",
"{",
"\"ssl_profile\"",
":",
"\"intermediate\"",
"}",
"}",
")",
"is",
"True",... | [
199,
0
] | [
217,
44
] | python | en | ['en', 'it', 'en'] | True |
test_ssl_profile_change_modern | (hass) | Test setting ssl profile to modern. | Test setting ssl profile to modern. | async def test_ssl_profile_change_modern(hass):
"""Test setting ssl profile to modern."""
assert (
await async_setup_component(hass, "http", {"http": {"ssl_profile": "modern"}})
is True
)
hass.http.ssl_certificate = "bla"
with patch("ssl.SSLContext.load_cert_chain"), patch(
"homeassistant.util.ssl.server_context_modern",
side_effect=server_context_modern,
) as mock_context:
await hass.async_start()
await hass.async_block_till_done()
assert len(mock_context.mock_calls) == 1 | [
"async",
"def",
"test_ssl_profile_change_modern",
"(",
"hass",
")",
":",
"assert",
"(",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"http\"",
",",
"{",
"\"http\"",
":",
"{",
"\"ssl_profile\"",
":",
"\"modern\"",
"}",
"}",
")",
"is",
"True",
")",
"h... | [
220,
0
] | [
236,
44
] | python | en | ['en', 'en', 'en'] | True |
test_cors_defaults | (hass) | Test the CORS default settings. | Test the CORS default settings. | async def test_cors_defaults(hass):
"""Test the CORS default settings."""
with patch("homeassistant.components.http.setup_cors") as mock_setup:
assert await async_setup_component(hass, "http", {})
assert len(mock_setup.mock_calls) == 1
assert mock_setup.mock_calls[0][1][1] == ["https://cast.home-assistant.io"] | [
"async",
"def",
"test_cors_defaults",
"(",
"hass",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.http.setup_cors\"",
")",
"as",
"mock_setup",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"http\"",
",",
"{",
"}",
")",
"assert",... | [
239,
0
] | [
245,
79
] | python | en | ['en', 'en', 'en'] | True |
test_storing_config | (hass, aiohttp_client, aiohttp_unused_port) | Test that we store last working config. | Test that we store last working config. | async def test_storing_config(hass, aiohttp_client, aiohttp_unused_port):
"""Test that we store last working config."""
config = {
http.CONF_SERVER_PORT: aiohttp_unused_port(),
"use_x_forwarded_for": True,
"trusted_proxies": ["192.168.1.100"],
}
assert await async_setup_component(hass, http.DOMAIN, {http.DOMAIN: config})
await hass.async_start()
restored = await hass.components.http.async_get_last_config()
restored["trusted_proxies"][0] = ip_network(restored["trusted_proxies"][0])
assert restored == http.HTTP_SCHEMA(config) | [
"async",
"def",
"test_storing_config",
"(",
"hass",
",",
"aiohttp_client",
",",
"aiohttp_unused_port",
")",
":",
"config",
"=",
"{",
"http",
".",
"CONF_SERVER_PORT",
":",
"aiohttp_unused_port",
"(",
")",
",",
"\"use_x_forwarded_for\"",
":",
"True",
",",
"\"trusted... | [
248,
0
] | [
262,
47
] | python | en | ['en', 'en', 'en'] | True |
test_use_of_base_url | (hass) | Test detection base_url usage when called without integration context. | Test detection base_url usage when called without integration context. | async def test_use_of_base_url(hass):
"""Test detection base_url usage when called without integration context."""
await async_setup_component(hass, "http", {"http": {}})
with patch(
"homeassistant.components.http.extract_stack",
return_value=[
Mock(
filename="/home/frenck/homeassistant/core.py",
lineno="21",
line="do_something()",
),
Mock(
filename="/home/frenck/homeassistant/core.py",
lineno="42",
line="url = hass.config.api.base_url",
),
Mock(
filename="/home/frenck/example/client.py",
lineno="21",
line="something()",
),
],
), pytest.raises(RuntimeError):
hass.config.api.base_url | [
"async",
"def",
"test_use_of_base_url",
"(",
"hass",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"http\"",
",",
"{",
"\"http\"",
":",
"{",
"}",
"}",
")",
"with",
"patch",
"(",
"\"homeassistant.components.http.extract_stack\"",
",",
"return_valu... | [
265,
0
] | [
288,
32
] | python | en | ['en', 'en', 'en'] | True |
test_use_of_base_url_integration | (hass, caplog) | Test detection base_url usage when called with integration context. | Test detection base_url usage when called with integration context. | async def test_use_of_base_url_integration(hass, caplog):
"""Test detection base_url usage when called with integration context."""
await async_setup_component(hass, "http", {"http": {}})
with patch(
"homeassistant.components.http.extract_stack",
return_value=[
Mock(
filename="/home/frenck/homeassistant/core.py",
lineno="21",
line="do_something()",
),
Mock(
filename="/home/frenck/homeassistant/components/example/__init__.py",
lineno="42",
line="url = hass.config.api.base_url",
),
Mock(
filename="/home/frenck/example/client.py",
lineno="21",
line="something()",
),
],
):
assert hass.config.api.base_url == "http://127.0.0.1:8123"
assert (
"Detected use of deprecated `base_url` property, use `homeassistant.helpers.network.get_url` method instead. Please report issue for example using this method at homeassistant/components/example/__init__.py, line 42: url = hass.config.api.base_url"
in caplog.text
) | [
"async",
"def",
"test_use_of_base_url_integration",
"(",
"hass",
",",
"caplog",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"http\"",
",",
"{",
"\"http\"",
":",
"{",
"}",
"}",
")",
"with",
"patch",
"(",
"\"homeassistant.components.http.extract_... | [
291,
0
] | [
319,
5
] | python | en | ['en', 'en', 'en'] | True |
test_use_of_base_url_integration_webhook | (hass, caplog) | Test detection base_url usage when called with integration context. | Test detection base_url usage when called with integration context. | async def test_use_of_base_url_integration_webhook(hass, caplog):
"""Test detection base_url usage when called with integration context."""
await async_setup_component(hass, "http", {"http": {}})
with patch(
"homeassistant.components.http.extract_stack",
return_value=[
Mock(
filename="/home/frenck/homeassistant/core.py",
lineno="21",
line="do_something()",
),
Mock(
filename="/home/frenck/homeassistant/components/example/__init__.py",
lineno="42",
line="url = hass.config.api.base_url",
),
Mock(
filename="/home/frenck/homeassistant/components/webhook/__init__.py",
lineno="42",
line="return get_url(hass)",
),
Mock(
filename="/home/frenck/example/client.py",
lineno="21",
line="something()",
),
],
):
assert hass.config.api.base_url == "http://127.0.0.1:8123"
assert (
"Detected use of deprecated `base_url` property, use `homeassistant.helpers.network.get_url` method instead. Please report issue for example using this method at homeassistant/components/example/__init__.py, line 42: url = hass.config.api.base_url"
in caplog.text
) | [
"async",
"def",
"test_use_of_base_url_integration_webhook",
"(",
"hass",
",",
"caplog",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"http\"",
",",
"{",
"\"http\"",
":",
"{",
"}",
"}",
")",
"with",
"patch",
"(",
"\"homeassistant.components.http.... | [
322,
0
] | [
355,
5
] | python | en | ['en', 'en', 'en'] | True |
test_use_of_base_url_custom_component | (hass, caplog) | Test detection base_url usage when called with custom component context. | Test detection base_url usage when called with custom component context. | async def test_use_of_base_url_custom_component(hass, caplog):
"""Test detection base_url usage when called with custom component context."""
await async_setup_component(hass, "http", {"http": {}})
with patch(
"homeassistant.components.http.extract_stack",
return_value=[
Mock(
filename="/home/frenck/homeassistant/core.py",
lineno="21",
line="do_something()",
),
Mock(
filename="/home/frenck/.homeassistant/custom_components/example/__init__.py",
lineno="42",
line="url = hass.config.api.base_url",
),
Mock(
filename="/home/frenck/example/client.py",
lineno="21",
line="something()",
),
],
):
assert hass.config.api.base_url == "http://127.0.0.1:8123"
assert (
"Detected use of deprecated `base_url` property, use `homeassistant.helpers.network.get_url` method instead. Please report issue to the custom component author for example using this method at custom_components/example/__init__.py, line 42: url = hass.config.api.base_url"
in caplog.text
) | [
"async",
"def",
"test_use_of_base_url_custom_component",
"(",
"hass",
",",
"caplog",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"http\"",
",",
"{",
"\"http\"",
":",
"{",
"}",
"}",
")",
"with",
"patch",
"(",
"\"homeassistant.components.http.ext... | [
358,
0
] | [
386,
5
] | python | en | ['en', 'en', 'en'] | True |
TestView.get | (self, request) | Return a get request. | Return a get request. | async def get(self, request):
"""Return a get request."""
return "hello" | [
"async",
"def",
"get",
"(",
"self",
",",
"request",
")",
":",
"return",
"\"hello\""
] | [
45,
4
] | [
47,
22
] | python | en | ['en', 'co', 'en'] | True |
test_brightness_light | (hass) | Test brightness trait support for light domain. | Test brightness trait support for light domain. | async def test_brightness_light(hass):
"""Test brightness trait support for light domain."""
assert helpers.get_google_type(light.DOMAIN, None) is not None
assert trait.BrightnessTrait.supported(light.DOMAIN, light.SUPPORT_BRIGHTNESS, None)
trt = trait.BrightnessTrait(
hass,
State("light.bla", light.STATE_ON, {light.ATTR_BRIGHTNESS: 243}),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {}
assert trt.query_attributes() == {"brightness": 95}
events = []
hass.bus.async_listen(EVENT_CALL_SERVICE, events.append)
calls = async_mock_service(hass, light.DOMAIN, light.SERVICE_TURN_ON)
await trt.execute(
trait.COMMAND_BRIGHTNESS_ABSOLUTE, BASIC_DATA, {"brightness": 50}, {}
)
await hass.async_block_till_done()
assert len(calls) == 1
assert calls[0].data == {ATTR_ENTITY_ID: "light.bla", light.ATTR_BRIGHTNESS_PCT: 50}
assert len(events) == 1
assert events[0].data == {
"domain": "light",
"service": "turn_on",
"service_data": {"brightness_pct": 50, "entity_id": "light.bla"},
} | [
"async",
"def",
"test_brightness_light",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"light",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"BrightnessTrait",
".",
"supported",
"(",
"light",
".",
... | [
71,
0
] | [
103,
5
] | python | en | ['en', 'no', 'en'] | True |
test_camera_stream | (hass) | Test camera stream trait support for camera domain. | Test camera stream trait support for camera domain. | async def test_camera_stream(hass):
"""Test camera stream trait support for camera domain."""
await async_process_ha_core_config(
hass,
{"external_url": "https://example.com"},
)
assert helpers.get_google_type(camera.DOMAIN, None) is not None
assert trait.CameraStreamTrait.supported(camera.DOMAIN, camera.SUPPORT_STREAM, None)
trt = trait.CameraStreamTrait(
hass, State("camera.bla", camera.STATE_IDLE, {}), BASIC_CONFIG
)
assert trt.sync_attributes() == {
"cameraStreamSupportedProtocols": ["hls"],
"cameraStreamNeedAuthToken": False,
"cameraStreamNeedDrmEncryption": False,
}
assert trt.query_attributes() == {}
with patch(
"homeassistant.components.camera.async_request_stream",
return_value="/api/streams/bla",
):
await trt.execute(trait.COMMAND_GET_CAMERA_STREAM, BASIC_DATA, {}, {})
assert trt.query_attributes() == {
"cameraStreamAccessUrl": "https://example.com/api/streams/bla",
"cameraStreamReceiverAppId": "B12CE3CA",
} | [
"async",
"def",
"test_camera_stream",
"(",
"hass",
")",
":",
"await",
"async_process_ha_core_config",
"(",
"hass",
",",
"{",
"\"external_url\"",
":",
"\"https://example.com\"",
"}",
",",
")",
"assert",
"helpers",
".",
"get_google_type",
"(",
"camera",
".",
"DOMAIN... | [
106,
0
] | [
136,
5
] | python | en | ['fr', 'en', 'en'] | True |
test_onoff_group | (hass) | Test OnOff trait support for group domain. | Test OnOff trait support for group domain. | async def test_onoff_group(hass):
"""Test OnOff trait support for group domain."""
assert helpers.get_google_type(group.DOMAIN, None) is not None
assert trait.OnOffTrait.supported(group.DOMAIN, 0, None)
trt_on = trait.OnOffTrait(hass, State("group.bla", STATE_ON), BASIC_CONFIG)
assert trt_on.sync_attributes() == {}
assert trt_on.query_attributes() == {"on": True}
trt_off = trait.OnOffTrait(hass, State("group.bla", STATE_OFF), BASIC_CONFIG)
assert trt_off.query_attributes() == {"on": False}
on_calls = async_mock_service(hass, HA_DOMAIN, SERVICE_TURN_ON)
await trt_on.execute(trait.COMMAND_ONOFF, BASIC_DATA, {"on": True}, {})
assert len(on_calls) == 1
assert on_calls[0].data == {ATTR_ENTITY_ID: "group.bla"}
off_calls = async_mock_service(hass, HA_DOMAIN, SERVICE_TURN_OFF)
await trt_on.execute(trait.COMMAND_ONOFF, BASIC_DATA, {"on": False}, {})
assert len(off_calls) == 1
assert off_calls[0].data == {ATTR_ENTITY_ID: "group.bla"} | [
"async",
"def",
"test_onoff_group",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"group",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"OnOffTrait",
".",
"supported",
"(",
"group",
".",
"DOMAIN",... | [
139,
0
] | [
162,
61
] | python | en | ['en', 'en', 'en'] | True |
test_onoff_input_boolean | (hass) | Test OnOff trait support for input_boolean domain. | Test OnOff trait support for input_boolean domain. | async def test_onoff_input_boolean(hass):
"""Test OnOff trait support for input_boolean domain."""
assert helpers.get_google_type(input_boolean.DOMAIN, None) is not None
assert trait.OnOffTrait.supported(input_boolean.DOMAIN, 0, None)
trt_on = trait.OnOffTrait(hass, State("input_boolean.bla", STATE_ON), BASIC_CONFIG)
assert trt_on.sync_attributes() == {}
assert trt_on.query_attributes() == {"on": True}
trt_off = trait.OnOffTrait(
hass, State("input_boolean.bla", STATE_OFF), BASIC_CONFIG
)
assert trt_off.query_attributes() == {"on": False}
on_calls = async_mock_service(hass, input_boolean.DOMAIN, SERVICE_TURN_ON)
await trt_on.execute(trait.COMMAND_ONOFF, BASIC_DATA, {"on": True}, {})
assert len(on_calls) == 1
assert on_calls[0].data == {ATTR_ENTITY_ID: "input_boolean.bla"}
off_calls = async_mock_service(hass, input_boolean.DOMAIN, SERVICE_TURN_OFF)
await trt_on.execute(trait.COMMAND_ONOFF, BASIC_DATA, {"on": False}, {})
assert len(off_calls) == 1
assert off_calls[0].data == {ATTR_ENTITY_ID: "input_boolean.bla"} | [
"async",
"def",
"test_onoff_input_boolean",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"input_boolean",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"OnOffTrait",
".",
"supported",
"(",
"input_bool... | [
165,
0
] | [
190,
69
] | python | en | ['fr', 'en', 'nl'] | False |
test_onoff_switch | (hass) | Test OnOff trait support for switch domain. | Test OnOff trait support for switch domain. | async def test_onoff_switch(hass):
"""Test OnOff trait support for switch domain."""
assert helpers.get_google_type(switch.DOMAIN, None) is not None
assert trait.OnOffTrait.supported(switch.DOMAIN, 0, None)
trt_on = trait.OnOffTrait(hass, State("switch.bla", STATE_ON), BASIC_CONFIG)
assert trt_on.sync_attributes() == {}
assert trt_on.query_attributes() == {"on": True}
trt_off = trait.OnOffTrait(hass, State("switch.bla", STATE_OFF), BASIC_CONFIG)
assert trt_off.query_attributes() == {"on": False}
trt_assumed = trait.OnOffTrait(
hass, State("switch.bla", STATE_OFF, {"assumed_state": True}), BASIC_CONFIG
)
assert trt_assumed.sync_attributes() == {"commandOnlyOnOff": True}
on_calls = async_mock_service(hass, switch.DOMAIN, SERVICE_TURN_ON)
await trt_on.execute(trait.COMMAND_ONOFF, BASIC_DATA, {"on": True}, {})
assert len(on_calls) == 1
assert on_calls[0].data == {ATTR_ENTITY_ID: "switch.bla"}
off_calls = async_mock_service(hass, switch.DOMAIN, SERVICE_TURN_OFF)
await trt_on.execute(trait.COMMAND_ONOFF, BASIC_DATA, {"on": False}, {})
assert len(off_calls) == 1
assert off_calls[0].data == {ATTR_ENTITY_ID: "switch.bla"} | [
"async",
"def",
"test_onoff_switch",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"switch",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"OnOffTrait",
".",
"supported",
"(",
"switch",
".",
"DOMAI... | [
193,
0
] | [
221,
62
] | python | en | ['en', 'en', 'en'] | True |
test_onoff_fan | (hass) | Test OnOff trait support for fan domain. | Test OnOff trait support for fan domain. | async def test_onoff_fan(hass):
"""Test OnOff trait support for fan domain."""
assert helpers.get_google_type(fan.DOMAIN, None) is not None
assert trait.OnOffTrait.supported(fan.DOMAIN, 0, None)
trt_on = trait.OnOffTrait(hass, State("fan.bla", STATE_ON), BASIC_CONFIG)
assert trt_on.sync_attributes() == {}
assert trt_on.query_attributes() == {"on": True}
trt_off = trait.OnOffTrait(hass, State("fan.bla", STATE_OFF), BASIC_CONFIG)
assert trt_off.query_attributes() == {"on": False}
on_calls = async_mock_service(hass, fan.DOMAIN, SERVICE_TURN_ON)
await trt_on.execute(trait.COMMAND_ONOFF, BASIC_DATA, {"on": True}, {})
assert len(on_calls) == 1
assert on_calls[0].data == {ATTR_ENTITY_ID: "fan.bla"}
off_calls = async_mock_service(hass, fan.DOMAIN, SERVICE_TURN_OFF)
await trt_on.execute(trait.COMMAND_ONOFF, BASIC_DATA, {"on": False}, {})
assert len(off_calls) == 1
assert off_calls[0].data == {ATTR_ENTITY_ID: "fan.bla"} | [
"async",
"def",
"test_onoff_fan",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"fan",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"OnOffTrait",
".",
"supported",
"(",
"fan",
".",
"DOMAIN",
","... | [
224,
0
] | [
246,
59
] | python | en | ['fr', 'en', 'en'] | True |
test_onoff_light | (hass) | Test OnOff trait support for light domain. | Test OnOff trait support for light domain. | async def test_onoff_light(hass):
"""Test OnOff trait support for light domain."""
assert helpers.get_google_type(light.DOMAIN, None) is not None
assert trait.OnOffTrait.supported(light.DOMAIN, 0, None)
trt_on = trait.OnOffTrait(hass, State("light.bla", STATE_ON), BASIC_CONFIG)
assert trt_on.sync_attributes() == {}
assert trt_on.query_attributes() == {"on": True}
trt_off = trait.OnOffTrait(hass, State("light.bla", STATE_OFF), BASIC_CONFIG)
assert trt_off.query_attributes() == {"on": False}
on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
await trt_on.execute(trait.COMMAND_ONOFF, BASIC_DATA, {"on": True}, {})
assert len(on_calls) == 1
assert on_calls[0].data == {ATTR_ENTITY_ID: "light.bla"}
off_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_OFF)
await trt_on.execute(trait.COMMAND_ONOFF, BASIC_DATA, {"on": False}, {})
assert len(off_calls) == 1
assert off_calls[0].data == {ATTR_ENTITY_ID: "light.bla"} | [
"async",
"def",
"test_onoff_light",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"light",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"OnOffTrait",
".",
"supported",
"(",
"light",
".",
"DOMAIN",... | [
249,
0
] | [
272,
61
] | python | en | ['en', 'en', 'en'] | True |
test_onoff_media_player | (hass) | Test OnOff trait support for media_player domain. | Test OnOff trait support for media_player domain. | async def test_onoff_media_player(hass):
"""Test OnOff trait support for media_player domain."""
assert helpers.get_google_type(media_player.DOMAIN, None) is not None
assert trait.OnOffTrait.supported(media_player.DOMAIN, 0, None)
trt_on = trait.OnOffTrait(hass, State("media_player.bla", STATE_ON), BASIC_CONFIG)
assert trt_on.sync_attributes() == {}
assert trt_on.query_attributes() == {"on": True}
trt_off = trait.OnOffTrait(hass, State("media_player.bla", STATE_OFF), BASIC_CONFIG)
assert trt_off.query_attributes() == {"on": False}
on_calls = async_mock_service(hass, media_player.DOMAIN, SERVICE_TURN_ON)
await trt_on.execute(trait.COMMAND_ONOFF, BASIC_DATA, {"on": True}, {})
assert len(on_calls) == 1
assert on_calls[0].data == {ATTR_ENTITY_ID: "media_player.bla"}
off_calls = async_mock_service(hass, media_player.DOMAIN, SERVICE_TURN_OFF)
await trt_on.execute(trait.COMMAND_ONOFF, BASIC_DATA, {"on": False}, {})
assert len(off_calls) == 1
assert off_calls[0].data == {ATTR_ENTITY_ID: "media_player.bla"} | [
"async",
"def",
"test_onoff_media_player",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"media_player",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"OnOffTrait",
".",
"supported",
"(",
"media_player... | [
275,
0
] | [
299,
68
] | python | en | ['fr', 'en', 'en'] | True |
test_onoff_humidifier | (hass) | Test OnOff trait support for humidifier domain. | Test OnOff trait support for humidifier domain. | async def test_onoff_humidifier(hass):
"""Test OnOff trait support for humidifier domain."""
assert helpers.get_google_type(humidifier.DOMAIN, None) is not None
assert trait.OnOffTrait.supported(humidifier.DOMAIN, 0, None)
trt_on = trait.OnOffTrait(hass, State("humidifier.bla", STATE_ON), BASIC_CONFIG)
assert trt_on.sync_attributes() == {}
assert trt_on.query_attributes() == {"on": True}
trt_off = trait.OnOffTrait(hass, State("humidifier.bla", STATE_OFF), BASIC_CONFIG)
assert trt_off.query_attributes() == {"on": False}
on_calls = async_mock_service(hass, humidifier.DOMAIN, SERVICE_TURN_ON)
await trt_on.execute(trait.COMMAND_ONOFF, BASIC_DATA, {"on": True}, {})
assert len(on_calls) == 1
assert on_calls[0].data == {ATTR_ENTITY_ID: "humidifier.bla"}
off_calls = async_mock_service(hass, humidifier.DOMAIN, SERVICE_TURN_OFF)
await trt_on.execute(trait.COMMAND_ONOFF, BASIC_DATA, {"on": False}, {})
assert len(off_calls) == 1
assert off_calls[0].data == {ATTR_ENTITY_ID: "humidifier.bla"} | [
"async",
"def",
"test_onoff_humidifier",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"humidifier",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"OnOffTrait",
".",
"supported",
"(",
"humidifier",
"... | [
302,
0
] | [
326,
66
] | python | en | ['en', 'en', 'en'] | True |
test_dock_vacuum | (hass) | Test dock trait support for vacuum domain. | Test dock trait support for vacuum domain. | async def test_dock_vacuum(hass):
"""Test dock trait support for vacuum domain."""
assert helpers.get_google_type(vacuum.DOMAIN, None) is not None
assert trait.DockTrait.supported(vacuum.DOMAIN, 0, None)
trt = trait.DockTrait(hass, State("vacuum.bla", vacuum.STATE_IDLE), BASIC_CONFIG)
assert trt.sync_attributes() == {}
assert trt.query_attributes() == {"isDocked": False}
calls = async_mock_service(hass, vacuum.DOMAIN, vacuum.SERVICE_RETURN_TO_BASE)
await trt.execute(trait.COMMAND_DOCK, BASIC_DATA, {}, {})
assert len(calls) == 1
assert calls[0].data == {ATTR_ENTITY_ID: "vacuum.bla"} | [
"async",
"def",
"test_dock_vacuum",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"vacuum",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"DockTrait",
".",
"supported",
"(",
"vacuum",
".",
"DOMAIN"... | [
329,
0
] | [
343,
58
] | python | en | ['fr', 'en', 'en'] | True |
test_startstop_vacuum | (hass) | Test startStop trait support for vacuum domain. | Test startStop trait support for vacuum domain. | async def test_startstop_vacuum(hass):
"""Test startStop trait support for vacuum domain."""
assert helpers.get_google_type(vacuum.DOMAIN, None) is not None
assert trait.StartStopTrait.supported(vacuum.DOMAIN, 0, None)
trt = trait.StartStopTrait(
hass,
State(
"vacuum.bla",
vacuum.STATE_PAUSED,
{ATTR_SUPPORTED_FEATURES: vacuum.SUPPORT_PAUSE},
),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {"pausable": True}
assert trt.query_attributes() == {"isRunning": False, "isPaused": True}
start_calls = async_mock_service(hass, vacuum.DOMAIN, vacuum.SERVICE_START)
await trt.execute(trait.COMMAND_STARTSTOP, BASIC_DATA, {"start": True}, {})
assert len(start_calls) == 1
assert start_calls[0].data == {ATTR_ENTITY_ID: "vacuum.bla"}
stop_calls = async_mock_service(hass, vacuum.DOMAIN, vacuum.SERVICE_STOP)
await trt.execute(trait.COMMAND_STARTSTOP, BASIC_DATA, {"start": False}, {})
assert len(stop_calls) == 1
assert stop_calls[0].data == {ATTR_ENTITY_ID: "vacuum.bla"}
pause_calls = async_mock_service(hass, vacuum.DOMAIN, vacuum.SERVICE_PAUSE)
await trt.execute(trait.COMMAND_PAUSEUNPAUSE, BASIC_DATA, {"pause": True}, {})
assert len(pause_calls) == 1
assert pause_calls[0].data == {ATTR_ENTITY_ID: "vacuum.bla"}
unpause_calls = async_mock_service(hass, vacuum.DOMAIN, vacuum.SERVICE_START)
await trt.execute(trait.COMMAND_PAUSEUNPAUSE, BASIC_DATA, {"pause": False}, {})
assert len(unpause_calls) == 1
assert unpause_calls[0].data == {ATTR_ENTITY_ID: "vacuum.bla"} | [
"async",
"def",
"test_startstop_vacuum",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"vacuum",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"StartStopTrait",
".",
"supported",
"(",
"vacuum",
".",
... | [
346,
0
] | [
383,
66
] | python | en | ['fr', 'en', 'en'] | True |
test_color_setting_color_light | (hass) | Test ColorSpectrum trait support for light domain. | Test ColorSpectrum trait support for light domain. | async def test_color_setting_color_light(hass):
"""Test ColorSpectrum trait support for light domain."""
assert helpers.get_google_type(light.DOMAIN, None) is not None
assert not trait.ColorSettingTrait.supported(light.DOMAIN, 0, None)
assert trait.ColorSettingTrait.supported(light.DOMAIN, light.SUPPORT_COLOR, None)
trt = trait.ColorSettingTrait(
hass,
State(
"light.bla",
STATE_ON,
{
light.ATTR_HS_COLOR: (20, 94),
light.ATTR_BRIGHTNESS: 200,
ATTR_SUPPORTED_FEATURES: light.SUPPORT_COLOR,
},
),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {"colorModel": "hsv"}
assert trt.query_attributes() == {
"color": {"spectrumHsv": {"hue": 20, "saturation": 0.94, "value": 200 / 255}}
}
assert trt.can_execute(
trait.COMMAND_COLOR_ABSOLUTE, {"color": {"spectrumRGB": 16715792}}
)
calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
await trt.execute(
trait.COMMAND_COLOR_ABSOLUTE,
BASIC_DATA,
{"color": {"spectrumRGB": 1052927}},
{},
)
assert len(calls) == 1
assert calls[0].data == {
ATTR_ENTITY_ID: "light.bla",
light.ATTR_HS_COLOR: (240, 93.725),
}
await trt.execute(
trait.COMMAND_COLOR_ABSOLUTE,
BASIC_DATA,
{"color": {"spectrumHSV": {"hue": 100, "saturation": 0.50, "value": 0.20}}},
{},
)
assert len(calls) == 2
assert calls[1].data == {
ATTR_ENTITY_ID: "light.bla",
light.ATTR_HS_COLOR: [100, 50],
light.ATTR_BRIGHTNESS: 0.2 * 255,
} | [
"async",
"def",
"test_color_setting_color_light",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"light",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"not",
"trait",
".",
"ColorSettingTrait",
".",
"supported",
"(",... | [
386,
0
] | [
440,
5
] | python | fr | ['fr', 'fr', 'en'] | True |
test_color_setting_temperature_light | (hass) | Test ColorTemperature trait support for light domain. | Test ColorTemperature trait support for light domain. | async def test_color_setting_temperature_light(hass):
"""Test ColorTemperature trait support for light domain."""
assert helpers.get_google_type(light.DOMAIN, None) is not None
assert not trait.ColorSettingTrait.supported(light.DOMAIN, 0, None)
assert trait.ColorSettingTrait.supported(
light.DOMAIN, light.SUPPORT_COLOR_TEMP, None
)
trt = trait.ColorSettingTrait(
hass,
State(
"light.bla",
STATE_ON,
{
light.ATTR_MIN_MIREDS: 200,
light.ATTR_COLOR_TEMP: 300,
light.ATTR_MAX_MIREDS: 500,
ATTR_SUPPORTED_FEATURES: light.SUPPORT_COLOR_TEMP,
},
),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {
"colorTemperatureRange": {"temperatureMinK": 2000, "temperatureMaxK": 5000}
}
assert trt.query_attributes() == {"color": {"temperatureK": 3333}}
assert trt.can_execute(
trait.COMMAND_COLOR_ABSOLUTE, {"color": {"temperature": 400}}
)
calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
with pytest.raises(helpers.SmartHomeError) as err:
await trt.execute(
trait.COMMAND_COLOR_ABSOLUTE,
BASIC_DATA,
{"color": {"temperature": 5555}},
{},
)
assert err.value.code == const.ERR_VALUE_OUT_OF_RANGE
await trt.execute(
trait.COMMAND_COLOR_ABSOLUTE, BASIC_DATA, {"color": {"temperature": 2857}}, {}
)
assert len(calls) == 1
assert calls[0].data == {
ATTR_ENTITY_ID: "light.bla",
light.ATTR_COLOR_TEMP: color.color_temperature_kelvin_to_mired(2857),
} | [
"async",
"def",
"test_color_setting_temperature_light",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"light",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"not",
"trait",
".",
"ColorSettingTrait",
".",
"supported",
... | [
443,
0
] | [
493,
5
] | python | en | ['fr', 'en', 'en'] | True |
test_color_light_temperature_light_bad_temp | (hass) | Test ColorTemperature trait support for light domain. | Test ColorTemperature trait support for light domain. | async def test_color_light_temperature_light_bad_temp(hass):
"""Test ColorTemperature trait support for light domain."""
assert helpers.get_google_type(light.DOMAIN, None) is not None
assert not trait.ColorSettingTrait.supported(light.DOMAIN, 0, None)
assert trait.ColorSettingTrait.supported(
light.DOMAIN, light.SUPPORT_COLOR_TEMP, None
)
trt = trait.ColorSettingTrait(
hass,
State(
"light.bla",
STATE_ON,
{
light.ATTR_MIN_MIREDS: 200,
light.ATTR_COLOR_TEMP: 0,
light.ATTR_MAX_MIREDS: 500,
},
),
BASIC_CONFIG,
)
assert trt.query_attributes() == {} | [
"async",
"def",
"test_color_light_temperature_light_bad_temp",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"light",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"not",
"trait",
".",
"ColorSettingTrait",
".",
"suppo... | [
496,
0
] | [
518,
39
] | python | en | ['fr', 'en', 'en'] | True |
test_light_modes | (hass) | Test Light Mode trait. | Test Light Mode trait. | async def test_light_modes(hass):
"""Test Light Mode trait."""
assert helpers.get_google_type(light.DOMAIN, None) is not None
assert trait.ModesTrait.supported(light.DOMAIN, light.SUPPORT_EFFECT, None)
trt = trait.ModesTrait(
hass,
State(
"light.living_room",
light.STATE_ON,
attributes={
light.ATTR_EFFECT_LIST: ["random", "colorloop"],
light.ATTR_EFFECT: "random",
},
),
BASIC_CONFIG,
)
attribs = trt.sync_attributes()
assert attribs == {
"availableModes": [
{
"name": "effect",
"name_values": [{"name_synonym": ["effect"], "lang": "en"}],
"settings": [
{
"setting_name": "random",
"setting_values": [
{"setting_synonym": ["random"], "lang": "en"}
],
},
{
"setting_name": "colorloop",
"setting_values": [
{"setting_synonym": ["colorloop"], "lang": "en"}
],
},
],
"ordered": False,
}
]
}
assert trt.query_attributes() == {
"currentModeSettings": {"effect": "random"},
"on": True,
}
assert trt.can_execute(
trait.COMMAND_MODES,
params={"updateModeSettings": {"effect": "colorloop"}},
)
calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
await trt.execute(
trait.COMMAND_MODES,
BASIC_DATA,
{"updateModeSettings": {"effect": "colorloop"}},
{},
)
assert len(calls) == 1
assert calls[0].data == {
"entity_id": "light.living_room",
"effect": "colorloop",
} | [
"async",
"def",
"test_light_modes",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"light",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"ModesTrait",
".",
"supported",
"(",
"light",
".",
"DOMAIN",... | [
521,
0
] | [
586,
5
] | python | fr | ['fr', 'fr', 'en'] | True |
test_scene_scene | (hass) | Test Scene trait support for scene domain. | Test Scene trait support for scene domain. | async def test_scene_scene(hass):
"""Test Scene trait support for scene domain."""
assert helpers.get_google_type(scene.DOMAIN, None) is not None
assert trait.SceneTrait.supported(scene.DOMAIN, 0, None)
trt = trait.SceneTrait(hass, State("scene.bla", scene.STATE), BASIC_CONFIG)
assert trt.sync_attributes() == {}
assert trt.query_attributes() == {}
assert trt.can_execute(trait.COMMAND_ACTIVATE_SCENE, {})
calls = async_mock_service(hass, scene.DOMAIN, SERVICE_TURN_ON)
await trt.execute(trait.COMMAND_ACTIVATE_SCENE, BASIC_DATA, {}, {})
assert len(calls) == 1
assert calls[0].data == {ATTR_ENTITY_ID: "scene.bla"} | [
"async",
"def",
"test_scene_scene",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"scene",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"SceneTrait",
".",
"supported",
"(",
"scene",
".",
"DOMAIN",... | [
589,
0
] | [
602,
57
] | python | en | ['fr', 'no', 'en'] | False |
test_scene_script | (hass) | Test Scene trait support for script domain. | Test Scene trait support for script domain. | async def test_scene_script(hass):
"""Test Scene trait support for script domain."""
assert helpers.get_google_type(script.DOMAIN, None) is not None
assert trait.SceneTrait.supported(script.DOMAIN, 0, None)
trt = trait.SceneTrait(hass, State("script.bla", STATE_OFF), BASIC_CONFIG)
assert trt.sync_attributes() == {}
assert trt.query_attributes() == {}
assert trt.can_execute(trait.COMMAND_ACTIVATE_SCENE, {})
calls = async_mock_service(hass, script.DOMAIN, SERVICE_TURN_ON)
await trt.execute(trait.COMMAND_ACTIVATE_SCENE, BASIC_DATA, {}, {})
# We don't wait till script execution is done.
await hass.async_block_till_done()
assert len(calls) == 1
assert calls[0].data == {ATTR_ENTITY_ID: "script.bla"} | [
"async",
"def",
"test_scene_script",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"script",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"SceneTrait",
".",
"supported",
"(",
"script",
".",
"DOMAI... | [
605,
0
] | [
622,
58
] | python | en | ['fr', 'no', 'en'] | False |
test_temperature_setting_climate_onoff | (hass) | Test TemperatureSetting trait support for climate domain - range. | Test TemperatureSetting trait support for climate domain - range. | async def test_temperature_setting_climate_onoff(hass):
"""Test TemperatureSetting trait support for climate domain - range."""
assert helpers.get_google_type(climate.DOMAIN, None) is not None
assert trait.TemperatureSettingTrait.supported(climate.DOMAIN, 0, None)
hass.config.units.temperature_unit = TEMP_FAHRENHEIT
trt = trait.TemperatureSettingTrait(
hass,
State(
"climate.bla",
climate.HVAC_MODE_AUTO,
{
ATTR_SUPPORTED_FEATURES: climate.SUPPORT_TARGET_TEMPERATURE_RANGE,
climate.ATTR_HVAC_MODES: [
climate.HVAC_MODE_OFF,
climate.HVAC_MODE_COOL,
climate.HVAC_MODE_HEAT,
climate.HVAC_MODE_HEAT_COOL,
],
climate.ATTR_MIN_TEMP: None,
climate.ATTR_MAX_TEMP: None,
},
),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {
"availableThermostatModes": "off,cool,heat,heatcool,on",
"thermostatTemperatureUnit": "F",
}
assert trt.can_execute(trait.COMMAND_THERMOSTAT_SET_MODE, {})
calls = async_mock_service(hass, climate.DOMAIN, SERVICE_TURN_ON)
await trt.execute(
trait.COMMAND_THERMOSTAT_SET_MODE, BASIC_DATA, {"thermostatMode": "on"}, {}
)
assert len(calls) == 1
calls = async_mock_service(hass, climate.DOMAIN, SERVICE_TURN_OFF)
await trt.execute(
trait.COMMAND_THERMOSTAT_SET_MODE, BASIC_DATA, {"thermostatMode": "off"}, {}
)
assert len(calls) == 1 | [
"async",
"def",
"test_temperature_setting_climate_onoff",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"climate",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"TemperatureSettingTrait",
".",
"supported",... | [
625,
0
] | [
667,
26
] | python | en | ['en', 'en', 'en'] | True |
test_temperature_setting_climate_no_modes | (hass) | Test TemperatureSetting trait support for climate domain not supporting any modes. | Test TemperatureSetting trait support for climate domain not supporting any modes. | async def test_temperature_setting_climate_no_modes(hass):
"""Test TemperatureSetting trait support for climate domain not supporting any modes."""
assert helpers.get_google_type(climate.DOMAIN, None) is not None
assert trait.TemperatureSettingTrait.supported(climate.DOMAIN, 0, None)
hass.config.units.temperature_unit = TEMP_CELSIUS
trt = trait.TemperatureSettingTrait(
hass,
State(
"climate.bla",
climate.HVAC_MODE_AUTO,
{
climate.ATTR_HVAC_MODES: [],
climate.ATTR_MIN_TEMP: None,
climate.ATTR_MAX_TEMP: None,
},
),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {
"availableThermostatModes": "heat",
"thermostatTemperatureUnit": "C",
} | [
"async",
"def",
"test_temperature_setting_climate_no_modes",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"climate",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"TemperatureSettingTrait",
".",
"supporte... | [
670,
0
] | [
693,
5
] | python | en | ['en', 'en', 'en'] | True |
test_temperature_setting_climate_range | (hass) | Test TemperatureSetting trait support for climate domain - range. | Test TemperatureSetting trait support for climate domain - range. | async def test_temperature_setting_climate_range(hass):
"""Test TemperatureSetting trait support for climate domain - range."""
assert helpers.get_google_type(climate.DOMAIN, None) is not None
assert trait.TemperatureSettingTrait.supported(climate.DOMAIN, 0, None)
hass.config.units.temperature_unit = TEMP_FAHRENHEIT
trt = trait.TemperatureSettingTrait(
hass,
State(
"climate.bla",
climate.HVAC_MODE_AUTO,
{
climate.ATTR_CURRENT_TEMPERATURE: 70,
climate.ATTR_CURRENT_HUMIDITY: 25,
ATTR_SUPPORTED_FEATURES: climate.SUPPORT_TARGET_TEMPERATURE_RANGE,
climate.ATTR_HVAC_MODES: [
STATE_OFF,
climate.HVAC_MODE_COOL,
climate.HVAC_MODE_HEAT,
climate.HVAC_MODE_AUTO,
],
climate.ATTR_TARGET_TEMP_HIGH: 75,
climate.ATTR_TARGET_TEMP_LOW: 65,
climate.ATTR_MIN_TEMP: 50,
climate.ATTR_MAX_TEMP: 80,
},
),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {
"availableThermostatModes": "off,cool,heat,auto,on",
"thermostatTemperatureUnit": "F",
}
assert trt.query_attributes() == {
"thermostatMode": "auto",
"thermostatTemperatureAmbient": 21.1,
"thermostatHumidityAmbient": 25,
"thermostatTemperatureSetpointLow": 18.3,
"thermostatTemperatureSetpointHigh": 23.9,
}
assert trt.can_execute(trait.COMMAND_THERMOSTAT_TEMPERATURE_SET_RANGE, {})
assert trt.can_execute(trait.COMMAND_THERMOSTAT_SET_MODE, {})
calls = async_mock_service(hass, climate.DOMAIN, climate.SERVICE_SET_TEMPERATURE)
await trt.execute(
trait.COMMAND_THERMOSTAT_TEMPERATURE_SET_RANGE,
BASIC_DATA,
{
"thermostatTemperatureSetpointHigh": 25,
"thermostatTemperatureSetpointLow": 20,
},
{},
)
assert len(calls) == 1
assert calls[0].data == {
ATTR_ENTITY_ID: "climate.bla",
climate.ATTR_TARGET_TEMP_HIGH: 77,
climate.ATTR_TARGET_TEMP_LOW: 68,
}
calls = async_mock_service(hass, climate.DOMAIN, climate.SERVICE_SET_HVAC_MODE)
await trt.execute(
trait.COMMAND_THERMOSTAT_SET_MODE, BASIC_DATA, {"thermostatMode": "cool"}, {}
)
assert len(calls) == 1
assert calls[0].data == {
ATTR_ENTITY_ID: "climate.bla",
climate.ATTR_HVAC_MODE: climate.HVAC_MODE_COOL,
}
with pytest.raises(helpers.SmartHomeError) as err:
await trt.execute(
trait.COMMAND_THERMOSTAT_TEMPERATURE_SETPOINT,
BASIC_DATA,
{"thermostatTemperatureSetpoint": -100},
{},
)
assert err.value.code == const.ERR_VALUE_OUT_OF_RANGE
hass.config.units.temperature_unit = TEMP_CELSIUS | [
"async",
"def",
"test_temperature_setting_climate_range",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"climate",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"TemperatureSettingTrait",
".",
"supported",... | [
696,
0
] | [
775,
53
] | python | en | ['en', 'en', 'en'] | True |
test_temperature_setting_climate_setpoint | (hass) | Test TemperatureSetting trait support for climate domain - setpoint. | Test TemperatureSetting trait support for climate domain - setpoint. | async def test_temperature_setting_climate_setpoint(hass):
"""Test TemperatureSetting trait support for climate domain - setpoint."""
assert helpers.get_google_type(climate.DOMAIN, None) is not None
assert trait.TemperatureSettingTrait.supported(climate.DOMAIN, 0, None)
hass.config.units.temperature_unit = TEMP_CELSIUS
trt = trait.TemperatureSettingTrait(
hass,
State(
"climate.bla",
climate.HVAC_MODE_COOL,
{
climate.ATTR_HVAC_MODES: [STATE_OFF, climate.HVAC_MODE_COOL],
climate.ATTR_MIN_TEMP: 10,
climate.ATTR_MAX_TEMP: 30,
ATTR_TEMPERATURE: 18,
climate.ATTR_CURRENT_TEMPERATURE: 20,
},
),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {
"availableThermostatModes": "off,cool,on",
"thermostatTemperatureUnit": "C",
}
assert trt.query_attributes() == {
"thermostatMode": "cool",
"thermostatTemperatureAmbient": 20,
"thermostatTemperatureSetpoint": 18,
}
assert trt.can_execute(trait.COMMAND_THERMOSTAT_TEMPERATURE_SETPOINT, {})
assert trt.can_execute(trait.COMMAND_THERMOSTAT_SET_MODE, {})
calls = async_mock_service(hass, climate.DOMAIN, climate.SERVICE_SET_TEMPERATURE)
with pytest.raises(helpers.SmartHomeError):
await trt.execute(
trait.COMMAND_THERMOSTAT_TEMPERATURE_SETPOINT,
BASIC_DATA,
{"thermostatTemperatureSetpoint": -100},
{},
)
await trt.execute(
trait.COMMAND_THERMOSTAT_TEMPERATURE_SETPOINT,
BASIC_DATA,
{"thermostatTemperatureSetpoint": 19},
{},
)
assert len(calls) == 1
assert calls[0].data == {ATTR_ENTITY_ID: "climate.bla", ATTR_TEMPERATURE: 19} | [
"async",
"def",
"test_temperature_setting_climate_setpoint",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"climate",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"TemperatureSettingTrait",
".",
"supporte... | [
778,
0
] | [
829,
81
] | python | en | ['en', 'en', 'en'] | True |
test_temperature_setting_climate_setpoint_auto | (hass) |
Test TemperatureSetting trait support for climate domain.
Setpoint in auto mode.
|
Test TemperatureSetting trait support for climate domain. | async def test_temperature_setting_climate_setpoint_auto(hass):
"""
Test TemperatureSetting trait support for climate domain.
Setpoint in auto mode.
"""
hass.config.units.temperature_unit = TEMP_CELSIUS
trt = trait.TemperatureSettingTrait(
hass,
State(
"climate.bla",
climate.HVAC_MODE_HEAT_COOL,
{
climate.ATTR_HVAC_MODES: [
climate.HVAC_MODE_OFF,
climate.HVAC_MODE_HEAT_COOL,
],
climate.ATTR_MIN_TEMP: 10,
climate.ATTR_MAX_TEMP: 30,
ATTR_TEMPERATURE: 18,
climate.ATTR_CURRENT_TEMPERATURE: 20,
},
),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {
"availableThermostatModes": "off,heatcool,on",
"thermostatTemperatureUnit": "C",
}
assert trt.query_attributes() == {
"thermostatMode": "heatcool",
"thermostatTemperatureAmbient": 20,
"thermostatTemperatureSetpointHigh": 18,
"thermostatTemperatureSetpointLow": 18,
}
assert trt.can_execute(trait.COMMAND_THERMOSTAT_TEMPERATURE_SETPOINT, {})
assert trt.can_execute(trait.COMMAND_THERMOSTAT_SET_MODE, {})
calls = async_mock_service(hass, climate.DOMAIN, climate.SERVICE_SET_TEMPERATURE)
await trt.execute(
trait.COMMAND_THERMOSTAT_TEMPERATURE_SETPOINT,
BASIC_DATA,
{"thermostatTemperatureSetpoint": 19},
{},
)
assert len(calls) == 1
assert calls[0].data == {ATTR_ENTITY_ID: "climate.bla", ATTR_TEMPERATURE: 19} | [
"async",
"def",
"test_temperature_setting_climate_setpoint_auto",
"(",
"hass",
")",
":",
"hass",
".",
"config",
".",
"units",
".",
"temperature_unit",
"=",
"TEMP_CELSIUS",
"trt",
"=",
"trait",
".",
"TemperatureSettingTrait",
"(",
"hass",
",",
"State",
"(",
"\"clim... | [
832,
0
] | [
880,
81
] | python | en | ['en', 'error', 'th'] | False |
test_humidity_setting_humidifier_setpoint | (hass) | Test HumiditySetting trait support for humidifier domain - setpoint. | Test HumiditySetting trait support for humidifier domain - setpoint. | async def test_humidity_setting_humidifier_setpoint(hass):
"""Test HumiditySetting trait support for humidifier domain - setpoint."""
assert helpers.get_google_type(humidifier.DOMAIN, None) is not None
assert trait.HumiditySettingTrait.supported(humidifier.DOMAIN, 0, None)
trt = trait.HumiditySettingTrait(
hass,
State(
"humidifier.bla",
STATE_ON,
{
humidifier.ATTR_MIN_HUMIDITY: 20,
humidifier.ATTR_MAX_HUMIDITY: 90,
humidifier.ATTR_HUMIDITY: 38,
},
),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {
"humiditySetpointRange": {"minPercent": 20, "maxPercent": 90}
}
assert trt.query_attributes() == {
"humiditySetpointPercent": 38,
}
assert trt.can_execute(trait.COMMAND_SET_HUMIDITY, {})
calls = async_mock_service(hass, humidifier.DOMAIN, humidifier.SERVICE_SET_HUMIDITY)
await trt.execute(trait.COMMAND_SET_HUMIDITY, BASIC_DATA, {"humidity": 32}, {})
assert len(calls) == 1
assert calls[0].data == {
ATTR_ENTITY_ID: "humidifier.bla",
humidifier.ATTR_HUMIDITY: 32,
} | [
"async",
"def",
"test_humidity_setting_humidifier_setpoint",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"humidifier",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"HumiditySettingTrait",
".",
"supporte... | [
883,
0
] | [
916,
5
] | python | en | ['en', 'en', 'en'] | True |
test_lock_unlock_lock | (hass) | Test LockUnlock trait locking support for lock domain. | Test LockUnlock trait locking support for lock domain. | async def test_lock_unlock_lock(hass):
"""Test LockUnlock trait locking support for lock domain."""
assert helpers.get_google_type(lock.DOMAIN, None) is not None
assert trait.LockUnlockTrait.supported(lock.DOMAIN, lock.SUPPORT_OPEN, None)
assert trait.LockUnlockTrait.might_2fa(lock.DOMAIN, lock.SUPPORT_OPEN, None)
trt = trait.LockUnlockTrait(
hass, State("lock.front_door", lock.STATE_LOCKED), PIN_CONFIG
)
assert trt.sync_attributes() == {}
assert trt.query_attributes() == {"isLocked": True}
assert trt.can_execute(trait.COMMAND_LOCKUNLOCK, {"lock": True})
calls = async_mock_service(hass, lock.DOMAIN, lock.SERVICE_LOCK)
await trt.execute(trait.COMMAND_LOCKUNLOCK, PIN_DATA, {"lock": True}, {})
assert len(calls) == 1
assert calls[0].data == {ATTR_ENTITY_ID: "lock.front_door"} | [
"async",
"def",
"test_lock_unlock_lock",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"lock",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"LockUnlockTrait",
".",
"supported",
"(",
"lock",
".",
"... | [
919,
0
] | [
940,
63
] | python | de | ['fr', 'de', 'en'] | False |
test_lock_unlock_unlock | (hass) | Test LockUnlock trait unlocking support for lock domain. | Test LockUnlock trait unlocking support for lock domain. | async def test_lock_unlock_unlock(hass):
"""Test LockUnlock trait unlocking support for lock domain."""
assert helpers.get_google_type(lock.DOMAIN, None) is not None
assert trait.LockUnlockTrait.supported(lock.DOMAIN, lock.SUPPORT_OPEN, None)
trt = trait.LockUnlockTrait(
hass, State("lock.front_door", lock.STATE_LOCKED), PIN_CONFIG
)
assert trt.sync_attributes() == {}
assert trt.query_attributes() == {"isLocked": True}
assert trt.can_execute(trait.COMMAND_LOCKUNLOCK, {"lock": False})
calls = async_mock_service(hass, lock.DOMAIN, lock.SERVICE_UNLOCK)
# No challenge data
with pytest.raises(error.ChallengeNeeded) as err:
await trt.execute(trait.COMMAND_LOCKUNLOCK, PIN_DATA, {"lock": False}, {})
assert len(calls) == 0
assert err.value.code == const.ERR_CHALLENGE_NEEDED
assert err.value.challenge_type == const.CHALLENGE_PIN_NEEDED
# invalid pin
with pytest.raises(error.ChallengeNeeded) as err:
await trt.execute(
trait.COMMAND_LOCKUNLOCK, PIN_DATA, {"lock": False}, {"pin": 9999}
)
assert len(calls) == 0
assert err.value.code == const.ERR_CHALLENGE_NEEDED
assert err.value.challenge_type == const.CHALLENGE_FAILED_PIN_NEEDED
await trt.execute(
trait.COMMAND_LOCKUNLOCK, PIN_DATA, {"lock": False}, {"pin": "1234"}
)
assert len(calls) == 1
assert calls[0].data == {ATTR_ENTITY_ID: "lock.front_door"}
# Test without pin
trt = trait.LockUnlockTrait(
hass, State("lock.front_door", lock.STATE_LOCKED), BASIC_CONFIG
)
with pytest.raises(error.SmartHomeError) as err:
await trt.execute(trait.COMMAND_LOCKUNLOCK, BASIC_DATA, {"lock": False}, {})
assert len(calls) == 1
assert err.value.code == const.ERR_CHALLENGE_NOT_SETUP
# Test with 2FA override
with patch.object(
BASIC_CONFIG,
"should_2fa",
return_value=False,
):
await trt.execute(trait.COMMAND_LOCKUNLOCK, BASIC_DATA, {"lock": False}, {})
assert len(calls) == 2 | [
"async",
"def",
"test_lock_unlock_unlock",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"lock",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"LockUnlockTrait",
".",
"supported",
"(",
"lock",
".",
... | [
943,
0
] | [
1000,
26
] | python | de | ['fr', 'de', 'en'] | False |
test_arm_disarm_arm_away | (hass) | Test ArmDisarm trait Arming support for alarm_control_panel domain. | Test ArmDisarm trait Arming support for alarm_control_panel domain. | async def test_arm_disarm_arm_away(hass):
"""Test ArmDisarm trait Arming support for alarm_control_panel domain."""
assert helpers.get_google_type(alarm_control_panel.DOMAIN, None) is not None
assert trait.ArmDisArmTrait.supported(alarm_control_panel.DOMAIN, 0, None)
assert trait.ArmDisArmTrait.might_2fa(alarm_control_panel.DOMAIN, 0, None)
trt = trait.ArmDisArmTrait(
hass,
State(
"alarm_control_panel.alarm",
STATE_ALARM_ARMED_AWAY,
{
alarm_control_panel.ATTR_CODE_ARM_REQUIRED: True,
ATTR_SUPPORTED_FEATURES: alarm_control_panel.const.SUPPORT_ALARM_ARM_HOME
| alarm_control_panel.const.SUPPORT_ALARM_ARM_AWAY,
},
),
PIN_CONFIG,
)
assert trt.sync_attributes() == {
"availableArmLevels": {
"levels": [
{
"level_name": "armed_home",
"level_values": [
{"level_synonym": ["armed home", "home"], "lang": "en"}
],
},
{
"level_name": "armed_away",
"level_values": [
{"level_synonym": ["armed away", "away"], "lang": "en"}
],
},
],
"ordered": False,
}
}
assert trt.query_attributes() == {
"isArmed": True,
"currentArmLevel": STATE_ALARM_ARMED_AWAY,
}
assert trt.can_execute(
trait.COMMAND_ARMDISARM, {"arm": True, "armLevel": STATE_ALARM_ARMED_AWAY}
)
calls = async_mock_service(
hass, alarm_control_panel.DOMAIN, alarm_control_panel.SERVICE_ALARM_ARM_AWAY
)
# Test with no secure_pin configured
with pytest.raises(error.SmartHomeError) as err:
trt = trait.ArmDisArmTrait(
hass,
State(
"alarm_control_panel.alarm",
STATE_ALARM_DISARMED,
{alarm_control_panel.ATTR_CODE_ARM_REQUIRED: True},
),
BASIC_CONFIG,
)
await trt.execute(
trait.COMMAND_ARMDISARM,
BASIC_DATA,
{"arm": True, "armLevel": STATE_ALARM_ARMED_AWAY},
{},
)
assert len(calls) == 0
assert err.value.code == const.ERR_CHALLENGE_NOT_SETUP
trt = trait.ArmDisArmTrait(
hass,
State(
"alarm_control_panel.alarm",
STATE_ALARM_DISARMED,
{alarm_control_panel.ATTR_CODE_ARM_REQUIRED: True},
),
PIN_CONFIG,
)
# No challenge data
with pytest.raises(error.ChallengeNeeded) as err:
await trt.execute(
trait.COMMAND_ARMDISARM,
PIN_DATA,
{"arm": True, "armLevel": STATE_ALARM_ARMED_AWAY},
{},
)
assert len(calls) == 0
assert err.value.code == const.ERR_CHALLENGE_NEEDED
assert err.value.challenge_type == const.CHALLENGE_PIN_NEEDED
# invalid pin
with pytest.raises(error.ChallengeNeeded) as err:
await trt.execute(
trait.COMMAND_ARMDISARM,
PIN_DATA,
{"arm": True, "armLevel": STATE_ALARM_ARMED_AWAY},
{"pin": 9999},
)
assert len(calls) == 0
assert err.value.code == const.ERR_CHALLENGE_NEEDED
assert err.value.challenge_type == const.CHALLENGE_FAILED_PIN_NEEDED
# correct pin
await trt.execute(
trait.COMMAND_ARMDISARM,
PIN_DATA,
{"arm": True, "armLevel": STATE_ALARM_ARMED_AWAY},
{"pin": "1234"},
)
assert len(calls) == 1
# Test already armed
with pytest.raises(error.SmartHomeError) as err:
trt = trait.ArmDisArmTrait(
hass,
State(
"alarm_control_panel.alarm",
STATE_ALARM_ARMED_AWAY,
{alarm_control_panel.ATTR_CODE_ARM_REQUIRED: True},
),
PIN_CONFIG,
)
await trt.execute(
trait.COMMAND_ARMDISARM,
PIN_DATA,
{"arm": True, "armLevel": STATE_ALARM_ARMED_AWAY},
{},
)
assert len(calls) == 1
assert err.value.code == const.ERR_ALREADY_ARMED
# Test with code_arm_required False
trt = trait.ArmDisArmTrait(
hass,
State(
"alarm_control_panel.alarm",
STATE_ALARM_DISARMED,
{alarm_control_panel.ATTR_CODE_ARM_REQUIRED: False},
),
PIN_CONFIG,
)
await trt.execute(
trait.COMMAND_ARMDISARM,
PIN_DATA,
{"arm": True, "armLevel": STATE_ALARM_ARMED_AWAY},
{},
)
assert len(calls) == 2
with pytest.raises(error.SmartHomeError) as err:
await trt.execute(
trait.COMMAND_ARMDISARM,
PIN_DATA,
{"arm": True},
{},
) | [
"async",
"def",
"test_arm_disarm_arm_away",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"alarm_control_panel",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"ArmDisArmTrait",
".",
"supported",
"(",
"... | [
1003,
0
] | [
1163,
9
] | python | en | ['en', 'en', 'en'] | True |
test_arm_disarm_disarm | (hass) | Test ArmDisarm trait Disarming support for alarm_control_panel domain. | Test ArmDisarm trait Disarming support for alarm_control_panel domain. | async def test_arm_disarm_disarm(hass):
"""Test ArmDisarm trait Disarming support for alarm_control_panel domain."""
assert helpers.get_google_type(alarm_control_panel.DOMAIN, None) is not None
assert trait.ArmDisArmTrait.supported(alarm_control_panel.DOMAIN, 0, None)
assert trait.ArmDisArmTrait.might_2fa(alarm_control_panel.DOMAIN, 0, None)
trt = trait.ArmDisArmTrait(
hass,
State(
"alarm_control_panel.alarm",
STATE_ALARM_DISARMED,
{
alarm_control_panel.ATTR_CODE_ARM_REQUIRED: True,
ATTR_SUPPORTED_FEATURES: alarm_control_panel.const.SUPPORT_ALARM_TRIGGER
| alarm_control_panel.const.SUPPORT_ALARM_ARM_CUSTOM_BYPASS,
},
),
PIN_CONFIG,
)
assert trt.sync_attributes() == {
"availableArmLevels": {
"levels": [
{
"level_name": "armed_custom_bypass",
"level_values": [
{
"level_synonym": ["armed custom bypass", "custom"],
"lang": "en",
}
],
},
{
"level_name": "triggered",
"level_values": [{"level_synonym": ["triggered"], "lang": "en"}],
},
],
"ordered": False,
}
}
assert trt.query_attributes() == {"isArmed": False}
assert trt.can_execute(trait.COMMAND_ARMDISARM, {"arm": False})
calls = async_mock_service(
hass, alarm_control_panel.DOMAIN, alarm_control_panel.SERVICE_ALARM_DISARM
)
# Test without secure_pin configured
with pytest.raises(error.SmartHomeError) as err:
trt = trait.ArmDisArmTrait(
hass,
State(
"alarm_control_panel.alarm",
STATE_ALARM_ARMED_AWAY,
{alarm_control_panel.ATTR_CODE_ARM_REQUIRED: True},
),
BASIC_CONFIG,
)
await trt.execute(trait.COMMAND_ARMDISARM, BASIC_DATA, {"arm": False}, {})
assert len(calls) == 0
assert err.value.code == const.ERR_CHALLENGE_NOT_SETUP
trt = trait.ArmDisArmTrait(
hass,
State(
"alarm_control_panel.alarm",
STATE_ALARM_ARMED_AWAY,
{alarm_control_panel.ATTR_CODE_ARM_REQUIRED: True},
),
PIN_CONFIG,
)
# No challenge data
with pytest.raises(error.ChallengeNeeded) as err:
await trt.execute(trait.COMMAND_ARMDISARM, PIN_DATA, {"arm": False}, {})
assert len(calls) == 0
assert err.value.code == const.ERR_CHALLENGE_NEEDED
assert err.value.challenge_type == const.CHALLENGE_PIN_NEEDED
# invalid pin
with pytest.raises(error.ChallengeNeeded) as err:
await trt.execute(
trait.COMMAND_ARMDISARM, PIN_DATA, {"arm": False}, {"pin": 9999}
)
assert len(calls) == 0
assert err.value.code == const.ERR_CHALLENGE_NEEDED
assert err.value.challenge_type == const.CHALLENGE_FAILED_PIN_NEEDED
# correct pin
await trt.execute(
trait.COMMAND_ARMDISARM, PIN_DATA, {"arm": False}, {"pin": "1234"}
)
assert len(calls) == 1
# Test already disarmed
with pytest.raises(error.SmartHomeError) as err:
trt = trait.ArmDisArmTrait(
hass,
State(
"alarm_control_panel.alarm",
STATE_ALARM_DISARMED,
{alarm_control_panel.ATTR_CODE_ARM_REQUIRED: True},
),
PIN_CONFIG,
)
await trt.execute(trait.COMMAND_ARMDISARM, PIN_DATA, {"arm": False}, {})
assert len(calls) == 1
assert err.value.code == const.ERR_ALREADY_DISARMED
# Cancel arming after already armed will require pin
with pytest.raises(error.SmartHomeError) as err:
trt = trait.ArmDisArmTrait(
hass,
State(
"alarm_control_panel.alarm",
STATE_ALARM_ARMED_AWAY,
{alarm_control_panel.ATTR_CODE_ARM_REQUIRED: False},
),
PIN_CONFIG,
)
await trt.execute(
trait.COMMAND_ARMDISARM, PIN_DATA, {"arm": True, "cancel": True}, {}
)
assert len(calls) == 1
assert err.value.code == const.ERR_CHALLENGE_NEEDED
assert err.value.challenge_type == const.CHALLENGE_PIN_NEEDED
# Cancel arming while pending to arm doesn't require pin
trt = trait.ArmDisArmTrait(
hass,
State(
"alarm_control_panel.alarm",
STATE_ALARM_PENDING,
{alarm_control_panel.ATTR_CODE_ARM_REQUIRED: False},
),
PIN_CONFIG,
)
await trt.execute(
trait.COMMAND_ARMDISARM, PIN_DATA, {"arm": True, "cancel": True}, {}
)
assert len(calls) == 2 | [
"async",
"def",
"test_arm_disarm_disarm",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"alarm_control_panel",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"ArmDisArmTrait",
".",
"supported",
"(",
"al... | [
1166,
0
] | [
1309,
26
] | python | en | ['en', 'en', 'en'] | True |
test_fan_speed | (hass) | Test FanSpeed trait speed control support for fan domain. | Test FanSpeed trait speed control support for fan domain. | async def test_fan_speed(hass):
"""Test FanSpeed trait speed control support for fan domain."""
assert helpers.get_google_type(fan.DOMAIN, None) is not None
assert trait.FanSpeedTrait.supported(fan.DOMAIN, fan.SUPPORT_SET_SPEED, None)
trt = trait.FanSpeedTrait(
hass,
State(
"fan.living_room_fan",
fan.SPEED_HIGH,
attributes={
"speed_list": [
fan.SPEED_OFF,
fan.SPEED_LOW,
fan.SPEED_MEDIUM,
fan.SPEED_HIGH,
],
"speed": "low",
},
),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {
"availableFanSpeeds": {
"ordered": True,
"speeds": [
{
"speed_name": "off",
"speed_values": [{"speed_synonym": ["stop", "off"], "lang": "en"}],
},
{
"speed_name": "low",
"speed_values": [
{
"speed_synonym": ["slow", "low", "slowest", "lowest"],
"lang": "en",
}
],
},
{
"speed_name": "medium",
"speed_values": [
{"speed_synonym": ["medium", "mid", "middle"], "lang": "en"}
],
},
{
"speed_name": "high",
"speed_values": [
{
"speed_synonym": [
"high",
"max",
"fast",
"highest",
"fastest",
"maximum",
],
"lang": "en",
}
],
},
],
},
"reversible": False,
}
assert trt.query_attributes() == {
"currentFanSpeedSetting": "low",
"on": True,
}
assert trt.can_execute(trait.COMMAND_FANSPEED, params={"fanSpeed": "medium"})
calls = async_mock_service(hass, fan.DOMAIN, fan.SERVICE_SET_SPEED)
await trt.execute(trait.COMMAND_FANSPEED, BASIC_DATA, {"fanSpeed": "medium"}, {})
assert len(calls) == 1
assert calls[0].data == {"entity_id": "fan.living_room_fan", "speed": "medium"} | [
"async",
"def",
"test_fan_speed",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"fan",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"FanSpeedTrait",
".",
"supported",
"(",
"fan",
".",
"DOMAIN",
... | [
1312,
0
] | [
1390,
83
] | python | en | ['en', 'fy', 'en'] | True |
test_climate_fan_speed | (hass) | Test FanSpeed trait speed control support for climate domain. | Test FanSpeed trait speed control support for climate domain. | async def test_climate_fan_speed(hass):
"""Test FanSpeed trait speed control support for climate domain."""
assert helpers.get_google_type(climate.DOMAIN, None) is not None
assert trait.FanSpeedTrait.supported(climate.DOMAIN, climate.SUPPORT_FAN_MODE, None)
trt = trait.FanSpeedTrait(
hass,
State(
"climate.living_room_ac",
"on",
attributes={
"fan_modes": ["auto", "low", "medium", "high"],
"fan_mode": "low",
},
),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {
"availableFanSpeeds": {
"ordered": True,
"speeds": [
{
"speed_name": "auto",
"speed_values": [{"speed_synonym": ["auto"], "lang": "en"}],
},
{
"speed_name": "low",
"speed_values": [{"speed_synonym": ["low"], "lang": "en"}],
},
{
"speed_name": "medium",
"speed_values": [{"speed_synonym": ["medium"], "lang": "en"}],
},
{
"speed_name": "high",
"speed_values": [{"speed_synonym": ["high"], "lang": "en"}],
},
],
},
"reversible": False,
}
assert trt.query_attributes() == {
"currentFanSpeedSetting": "low",
}
assert trt.can_execute(trait.COMMAND_FANSPEED, params={"fanSpeed": "medium"})
calls = async_mock_service(hass, climate.DOMAIN, climate.SERVICE_SET_FAN_MODE)
await trt.execute(trait.COMMAND_FANSPEED, BASIC_DATA, {"fanSpeed": "medium"}, {})
assert len(calls) == 1
assert calls[0].data == {
"entity_id": "climate.living_room_ac",
"fan_mode": "medium",
} | [
"async",
"def",
"test_climate_fan_speed",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"climate",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"FanSpeedTrait",
".",
"supported",
"(",
"climate",
"."... | [
1393,
0
] | [
1449,
5
] | python | en | ['en', 'en', 'en'] | True |
test_inputselector | (hass) | Test input selector trait. | Test input selector trait. | async def test_inputselector(hass):
"""Test input selector trait."""
assert helpers.get_google_type(media_player.DOMAIN, None) is not None
assert trait.InputSelectorTrait.supported(
media_player.DOMAIN, media_player.SUPPORT_SELECT_SOURCE, None
)
trt = trait.InputSelectorTrait(
hass,
State(
"media_player.living_room",
media_player.STATE_PLAYING,
attributes={
media_player.ATTR_INPUT_SOURCE_LIST: [
"media",
"game",
"chromecast",
"plex",
],
media_player.ATTR_INPUT_SOURCE: "game",
},
),
BASIC_CONFIG,
)
attribs = trt.sync_attributes()
assert attribs == {
"availableInputs": [
{"key": "media", "names": [{"name_synonym": ["media"], "lang": "en"}]},
{"key": "game", "names": [{"name_synonym": ["game"], "lang": "en"}]},
{
"key": "chromecast",
"names": [{"name_synonym": ["chromecast"], "lang": "en"}],
},
{"key": "plex", "names": [{"name_synonym": ["plex"], "lang": "en"}]},
],
"orderedInputs": True,
}
assert trt.query_attributes() == {
"currentInput": "game",
}
assert trt.can_execute(
trait.COMMAND_INPUT,
params={"newInput": "media"},
)
calls = async_mock_service(
hass, media_player.DOMAIN, media_player.SERVICE_SELECT_SOURCE
)
await trt.execute(
trait.COMMAND_INPUT,
BASIC_DATA,
{"newInput": "media"},
{},
)
assert len(calls) == 1
assert calls[0].data == {"entity_id": "media_player.living_room", "source": "media"} | [
"async",
"def",
"test_inputselector",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"media_player",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"InputSelectorTrait",
".",
"supported",
"(",
"media_pla... | [
1452,
0
] | [
1511,
88
] | python | en | ['en', 'fr', 'en'] | True |
test_inputselector_nextprev | (hass, sources, source, source_next, source_prev) | Test input selector trait. | Test input selector trait. | async def test_inputselector_nextprev(hass, sources, source, source_next, source_prev):
"""Test input selector trait."""
trt = trait.InputSelectorTrait(
hass,
State(
"media_player.living_room",
media_player.STATE_PLAYING,
attributes={
media_player.ATTR_INPUT_SOURCE_LIST: sources,
media_player.ATTR_INPUT_SOURCE: source,
},
),
BASIC_CONFIG,
)
assert trt.can_execute("action.devices.commands.NextInput", params={})
assert trt.can_execute("action.devices.commands.PreviousInput", params={})
calls = async_mock_service(
hass, media_player.DOMAIN, media_player.SERVICE_SELECT_SOURCE
)
await trt.execute(
"action.devices.commands.NextInput",
BASIC_DATA,
{},
{},
)
await trt.execute(
"action.devices.commands.PreviousInput",
BASIC_DATA,
{},
{},
)
assert len(calls) == 2
assert calls[0].data == {
"entity_id": "media_player.living_room",
"source": source_next,
}
assert calls[1].data == {
"entity_id": "media_player.living_room",
"source": source_prev,
} | [
"async",
"def",
"test_inputselector_nextprev",
"(",
"hass",
",",
"sources",
",",
"source",
",",
"source_next",
",",
"source_prev",
")",
":",
"trt",
"=",
"trait",
".",
"InputSelectorTrait",
"(",
"hass",
",",
"State",
"(",
"\"media_player.living_room\"",
",",
"med... | [
1522,
0
] | [
1564,
5
] | python | en | ['en', 'fr', 'en'] | True |
test_inputselector_nextprev_invalid | (hass, sources, source) | Test input selector trait. | Test input selector trait. | async def test_inputselector_nextprev_invalid(hass, sources, source):
"""Test input selector trait."""
trt = trait.InputSelectorTrait(
hass,
State(
"media_player.living_room",
media_player.STATE_PLAYING,
attributes={
media_player.ATTR_INPUT_SOURCE_LIST: sources,
media_player.ATTR_INPUT_SOURCE: source,
},
),
BASIC_CONFIG,
)
with pytest.raises(SmartHomeError):
await trt.execute(
"action.devices.commands.NextInput",
BASIC_DATA,
{},
{},
)
with pytest.raises(SmartHomeError):
await trt.execute(
"action.devices.commands.PreviousInput",
BASIC_DATA,
{},
{},
)
with pytest.raises(SmartHomeError):
await trt.execute(
"action.devices.commands.InvalidCommand",
BASIC_DATA,
{},
{},
) | [
"async",
"def",
"test_inputselector_nextprev_invalid",
"(",
"hass",
",",
"sources",
",",
"source",
")",
":",
"trt",
"=",
"trait",
".",
"InputSelectorTrait",
"(",
"hass",
",",
"State",
"(",
"\"media_player.living_room\"",
",",
"media_player",
".",
"STATE_PLAYING",
... | [
1570,
0
] | [
1607,
9
] | python | en | ['en', 'fr', 'en'] | True |
test_modes_input_select | (hass) | Test Input Select Mode trait. | Test Input Select Mode trait. | async def test_modes_input_select(hass):
"""Test Input Select Mode trait."""
assert helpers.get_google_type(input_select.DOMAIN, None) is not None
assert trait.ModesTrait.supported(input_select.DOMAIN, None, None)
trt = trait.ModesTrait(
hass,
State("input_select.bla", "unavailable"),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {"availableModes": []}
trt = trait.ModesTrait(
hass,
State(
"input_select.bla",
"abc",
attributes={input_select.ATTR_OPTIONS: ["abc", "123", "xyz"]},
),
BASIC_CONFIG,
)
attribs = trt.sync_attributes()
assert attribs == {
"availableModes": [
{
"name": "option",
"name_values": [
{
"name_synonym": ["option", "setting", "mode", "value"],
"lang": "en",
}
],
"settings": [
{
"setting_name": "abc",
"setting_values": [{"setting_synonym": ["abc"], "lang": "en"}],
},
{
"setting_name": "123",
"setting_values": [{"setting_synonym": ["123"], "lang": "en"}],
},
{
"setting_name": "xyz",
"setting_values": [{"setting_synonym": ["xyz"], "lang": "en"}],
},
],
"ordered": False,
}
]
}
assert trt.query_attributes() == {
"currentModeSettings": {"option": "abc"},
"on": True,
}
assert trt.can_execute(
trait.COMMAND_MODES,
params={"updateModeSettings": {"option": "xyz"}},
)
calls = async_mock_service(
hass, input_select.DOMAIN, input_select.SERVICE_SELECT_OPTION
)
await trt.execute(
trait.COMMAND_MODES,
BASIC_DATA,
{"updateModeSettings": {"option": "xyz"}},
{},
)
assert len(calls) == 1
assert calls[0].data == {"entity_id": "input_select.bla", "option": "xyz"} | [
"async",
"def",
"test_modes_input_select",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"input_select",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"ModesTrait",
".",
"supported",
"(",
"input_select... | [
1610,
0
] | [
1683,
78
] | python | en | ['fr', 'en', 'en'] | True |
test_modes_humidifier | (hass) | Test Humidifier Mode trait. | Test Humidifier Mode trait. | async def test_modes_humidifier(hass):
"""Test Humidifier Mode trait."""
assert helpers.get_google_type(humidifier.DOMAIN, None) is not None
assert trait.ModesTrait.supported(humidifier.DOMAIN, humidifier.SUPPORT_MODES, None)
trt = trait.ModesTrait(
hass,
State(
"humidifier.humidifier",
STATE_OFF,
attributes={
humidifier.ATTR_AVAILABLE_MODES: [
humidifier.MODE_NORMAL,
humidifier.MODE_AUTO,
humidifier.MODE_AWAY,
],
ATTR_SUPPORTED_FEATURES: humidifier.SUPPORT_MODES,
humidifier.ATTR_MIN_HUMIDITY: 30,
humidifier.ATTR_MAX_HUMIDITY: 99,
humidifier.ATTR_HUMIDITY: 50,
humidifier.ATTR_MODE: humidifier.MODE_AUTO,
},
),
BASIC_CONFIG,
)
attribs = trt.sync_attributes()
assert attribs == {
"availableModes": [
{
"name": "mode",
"name_values": [{"name_synonym": ["mode"], "lang": "en"}],
"settings": [
{
"setting_name": "normal",
"setting_values": [
{"setting_synonym": ["normal"], "lang": "en"}
],
},
{
"setting_name": "auto",
"setting_values": [{"setting_synonym": ["auto"], "lang": "en"}],
},
{
"setting_name": "away",
"setting_values": [{"setting_synonym": ["away"], "lang": "en"}],
},
],
"ordered": False,
},
]
}
assert trt.query_attributes() == {
"currentModeSettings": {"mode": "auto"},
"on": False,
}
assert trt.can_execute(
trait.COMMAND_MODES, params={"updateModeSettings": {"mode": "away"}}
)
calls = async_mock_service(hass, humidifier.DOMAIN, humidifier.SERVICE_SET_MODE)
await trt.execute(
trait.COMMAND_MODES,
BASIC_DATA,
{"updateModeSettings": {"mode": "away"}},
{},
)
assert len(calls) == 1
assert calls[0].data == {
"entity_id": "humidifier.humidifier",
"mode": "away",
} | [
"async",
"def",
"test_modes_humidifier",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"humidifier",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"ModesTrait",
".",
"supported",
"(",
"humidifier",
"... | [
1686,
0
] | [
1760,
5
] | python | en | ['fr', 'en', 'en'] | True |
test_sound_modes | (hass) | Test Mode trait. | Test Mode trait. | async def test_sound_modes(hass):
"""Test Mode trait."""
assert helpers.get_google_type(media_player.DOMAIN, None) is not None
assert trait.ModesTrait.supported(
media_player.DOMAIN, media_player.SUPPORT_SELECT_SOUND_MODE, None
)
trt = trait.ModesTrait(
hass,
State(
"media_player.living_room",
media_player.STATE_PLAYING,
attributes={
media_player.ATTR_SOUND_MODE_LIST: ["stereo", "prologic"],
media_player.ATTR_SOUND_MODE: "stereo",
},
),
BASIC_CONFIG,
)
attribs = trt.sync_attributes()
assert attribs == {
"availableModes": [
{
"name": "sound mode",
"name_values": [
{"name_synonym": ["sound mode", "effects"], "lang": "en"}
],
"settings": [
{
"setting_name": "stereo",
"setting_values": [
{"setting_synonym": ["stereo"], "lang": "en"}
],
},
{
"setting_name": "prologic",
"setting_values": [
{"setting_synonym": ["prologic"], "lang": "en"}
],
},
],
"ordered": False,
}
]
}
assert trt.query_attributes() == {
"currentModeSettings": {"sound mode": "stereo"},
"on": True,
}
assert trt.can_execute(
trait.COMMAND_MODES,
params={"updateModeSettings": {"sound mode": "stereo"}},
)
calls = async_mock_service(
hass, media_player.DOMAIN, media_player.SERVICE_SELECT_SOUND_MODE
)
await trt.execute(
trait.COMMAND_MODES,
BASIC_DATA,
{"updateModeSettings": {"sound mode": "stereo"}},
{},
)
assert len(calls) == 1
assert calls[0].data == {
"entity_id": "media_player.living_room",
"sound_mode": "stereo",
} | [
"async",
"def",
"test_sound_modes",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"media_player",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"ModesTrait",
".",
"supported",
"(",
"media_player",
".... | [
1763,
0
] | [
1834,
5
] | python | fr | ['fr', 'fr', 'it'] | True |
test_openclose_cover | (hass) | Test OpenClose trait support for cover domain. | Test OpenClose trait support for cover domain. | async def test_openclose_cover(hass):
"""Test OpenClose trait support for cover domain."""
assert helpers.get_google_type(cover.DOMAIN, None) is not None
assert trait.OpenCloseTrait.supported(
cover.DOMAIN, cover.SUPPORT_SET_POSITION, None
)
trt = trait.OpenCloseTrait(
hass,
State(
"cover.bla",
cover.STATE_OPEN,
{
cover.ATTR_CURRENT_POSITION: 75,
ATTR_SUPPORTED_FEATURES: cover.SUPPORT_SET_POSITION,
},
),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {}
assert trt.query_attributes() == {"openPercent": 75}
calls = async_mock_service(hass, cover.DOMAIN, cover.SERVICE_SET_COVER_POSITION)
await trt.execute(trait.COMMAND_OPENCLOSE, BASIC_DATA, {"openPercent": 50}, {})
await trt.execute(
trait.COMMAND_OPENCLOSE_RELATIVE, BASIC_DATA, {"openRelativePercent": 50}, {}
)
assert len(calls) == 2
assert calls[0].data == {ATTR_ENTITY_ID: "cover.bla", cover.ATTR_POSITION: 50}
assert calls[1].data == {ATTR_ENTITY_ID: "cover.bla", cover.ATTR_POSITION: 100} | [
"async",
"def",
"test_openclose_cover",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"cover",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"OpenCloseTrait",
".",
"supported",
"(",
"cover",
".",
"... | [
1837,
0
] | [
1867,
83
] | python | en | ['fr', 'en', 'en'] | True |
test_openclose_cover_unknown_state | (hass) | Test OpenClose trait support for cover domain with unknown state. | Test OpenClose trait support for cover domain with unknown state. | async def test_openclose_cover_unknown_state(hass):
"""Test OpenClose trait support for cover domain with unknown state."""
assert helpers.get_google_type(cover.DOMAIN, None) is not None
assert trait.OpenCloseTrait.supported(
cover.DOMAIN, cover.SUPPORT_SET_POSITION, None
)
# No state
trt = trait.OpenCloseTrait(
hass,
State(
"cover.bla", STATE_UNKNOWN, {ATTR_SUPPORTED_FEATURES: cover.SUPPORT_OPEN}
),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {"discreteOnlyOpenClose": True}
with pytest.raises(helpers.SmartHomeError):
trt.query_attributes()
calls = async_mock_service(hass, cover.DOMAIN, cover.SERVICE_OPEN_COVER)
await trt.execute(trait.COMMAND_OPENCLOSE, BASIC_DATA, {"openPercent": 100}, {})
assert len(calls) == 1
assert calls[0].data == {ATTR_ENTITY_ID: "cover.bla"}
with pytest.raises(helpers.SmartHomeError):
trt.query_attributes() | [
"async",
"def",
"test_openclose_cover_unknown_state",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"cover",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"OpenCloseTrait",
".",
"supported",
"(",
"cove... | [
1870,
0
] | [
1897,
30
] | python | en | ['en', 'en', 'en'] | True |
test_openclose_cover_assumed_state | (hass) | Test OpenClose trait support for cover domain. | Test OpenClose trait support for cover domain. | async def test_openclose_cover_assumed_state(hass):
"""Test OpenClose trait support for cover domain."""
assert helpers.get_google_type(cover.DOMAIN, None) is not None
assert trait.OpenCloseTrait.supported(
cover.DOMAIN, cover.SUPPORT_SET_POSITION, None
)
trt = trait.OpenCloseTrait(
hass,
State(
"cover.bla",
cover.STATE_OPEN,
{
ATTR_ASSUMED_STATE: True,
ATTR_SUPPORTED_FEATURES: cover.SUPPORT_SET_POSITION,
},
),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {"commandOnlyOpenClose": True}
assert trt.query_attributes() == {}
calls = async_mock_service(hass, cover.DOMAIN, cover.SERVICE_SET_COVER_POSITION)
await trt.execute(trait.COMMAND_OPENCLOSE, BASIC_DATA, {"openPercent": 40}, {})
assert len(calls) == 1
assert calls[0].data == {ATTR_ENTITY_ID: "cover.bla", cover.ATTR_POSITION: 40} | [
"async",
"def",
"test_openclose_cover_assumed_state",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"cover",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"OpenCloseTrait",
".",
"supported",
"(",
"cove... | [
1900,
0
] | [
1927,
82
] | python | en | ['fr', 'en', 'en'] | True |
test_openclose_cover_query_only | (hass) | Test OpenClose trait support for cover domain. | Test OpenClose trait support for cover domain. | async def test_openclose_cover_query_only(hass):
"""Test OpenClose trait support for cover domain."""
assert helpers.get_google_type(cover.DOMAIN, None) is not None
assert trait.OpenCloseTrait.supported(cover.DOMAIN, 0, None)
state = State(
"cover.bla",
cover.STATE_OPEN,
)
trt = trait.OpenCloseTrait(
hass,
state,
BASIC_CONFIG,
)
assert trt.sync_attributes() == {
"discreteOnlyOpenClose": True,
"queryOnlyOpenClose": True,
}
assert trt.query_attributes() == {"openPercent": 100} | [
"async",
"def",
"test_openclose_cover_query_only",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"cover",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"OpenCloseTrait",
".",
"supported",
"(",
"cover",... | [
1930,
0
] | [
1950,
57
] | python | en | ['fr', 'en', 'en'] | True |
test_openclose_cover_no_position | (hass) | Test OpenClose trait support for cover domain. | Test OpenClose trait support for cover domain. | async def test_openclose_cover_no_position(hass):
"""Test OpenClose trait support for cover domain."""
assert helpers.get_google_type(cover.DOMAIN, None) is not None
assert trait.OpenCloseTrait.supported(
cover.DOMAIN, cover.SUPPORT_OPEN | cover.SUPPORT_CLOSE, None
)
state = State(
"cover.bla",
cover.STATE_OPEN,
{
ATTR_SUPPORTED_FEATURES: cover.SUPPORT_OPEN | cover.SUPPORT_CLOSE,
},
)
trt = trait.OpenCloseTrait(
hass,
state,
BASIC_CONFIG,
)
assert trt.sync_attributes() == {"discreteOnlyOpenClose": True}
assert trt.query_attributes() == {"openPercent": 100}
state.state = cover.STATE_CLOSED
assert trt.sync_attributes() == {"discreteOnlyOpenClose": True}
assert trt.query_attributes() == {"openPercent": 0}
calls = async_mock_service(hass, cover.DOMAIN, cover.SERVICE_CLOSE_COVER)
await trt.execute(trait.COMMAND_OPENCLOSE, BASIC_DATA, {"openPercent": 0}, {})
assert len(calls) == 1
assert calls[0].data == {ATTR_ENTITY_ID: "cover.bla"}
calls = async_mock_service(hass, cover.DOMAIN, cover.SERVICE_OPEN_COVER)
await trt.execute(trait.COMMAND_OPENCLOSE, BASIC_DATA, {"openPercent": 100}, {})
assert len(calls) == 1
assert calls[0].data == {ATTR_ENTITY_ID: "cover.bla"}
with pytest.raises(
SmartHomeError, match=r"Current position not know for relative command"
):
await trt.execute(
trait.COMMAND_OPENCLOSE_RELATIVE,
BASIC_DATA,
{"openRelativePercent": 100},
{},
)
with pytest.raises(SmartHomeError, match=r"No support for partial open close"):
await trt.execute(trait.COMMAND_OPENCLOSE, BASIC_DATA, {"openPercent": 50}, {}) | [
"async",
"def",
"test_openclose_cover_no_position",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"cover",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"OpenCloseTrait",
".",
"supported",
"(",
"cover"... | [
1953,
0
] | [
2003,
87
] | python | en | ['fr', 'en', 'en'] | True |
test_openclose_cover_secure | (hass, device_class) | Test OpenClose trait support for cover domain. | Test OpenClose trait support for cover domain. | async def test_openclose_cover_secure(hass, device_class):
"""Test OpenClose trait support for cover domain."""
assert helpers.get_google_type(cover.DOMAIN, device_class) is not None
assert trait.OpenCloseTrait.supported(
cover.DOMAIN, cover.SUPPORT_SET_POSITION, device_class
)
assert trait.OpenCloseTrait.might_2fa(
cover.DOMAIN, cover.SUPPORT_SET_POSITION, device_class
)
trt = trait.OpenCloseTrait(
hass,
State(
"cover.bla",
cover.STATE_OPEN,
{
ATTR_DEVICE_CLASS: device_class,
ATTR_SUPPORTED_FEATURES: cover.SUPPORT_SET_POSITION,
cover.ATTR_CURRENT_POSITION: 75,
},
),
PIN_CONFIG,
)
assert trt.sync_attributes() == {}
assert trt.query_attributes() == {"openPercent": 75}
calls = async_mock_service(hass, cover.DOMAIN, cover.SERVICE_SET_COVER_POSITION)
# No challenge data
with pytest.raises(error.ChallengeNeeded) as err:
await trt.execute(trait.COMMAND_OPENCLOSE, PIN_DATA, {"openPercent": 50}, {})
assert len(calls) == 0
assert err.value.code == const.ERR_CHALLENGE_NEEDED
assert err.value.challenge_type == const.CHALLENGE_PIN_NEEDED
# invalid pin
with pytest.raises(error.ChallengeNeeded) as err:
await trt.execute(
trait.COMMAND_OPENCLOSE, PIN_DATA, {"openPercent": 50}, {"pin": "9999"}
)
assert len(calls) == 0
assert err.value.code == const.ERR_CHALLENGE_NEEDED
assert err.value.challenge_type == const.CHALLENGE_FAILED_PIN_NEEDED
await trt.execute(
trait.COMMAND_OPENCLOSE, PIN_DATA, {"openPercent": 50}, {"pin": "1234"}
)
assert len(calls) == 1
assert calls[0].data == {ATTR_ENTITY_ID: "cover.bla", cover.ATTR_POSITION: 50}
# no challenge on close
await trt.execute(trait.COMMAND_OPENCLOSE, PIN_DATA, {"openPercent": 0}, {})
assert len(calls) == 2
assert calls[1].data == {ATTR_ENTITY_ID: "cover.bla", cover.ATTR_POSITION: 0} | [
"async",
"def",
"test_openclose_cover_secure",
"(",
"hass",
",",
"device_class",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"cover",
".",
"DOMAIN",
",",
"device_class",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"OpenCloseTrait",
".",
"... | [
2010,
0
] | [
2064,
81
] | python | en | ['fr', 'en', 'en'] | True |
test_openclose_binary_sensor | (hass, device_class) | Test OpenClose trait support for binary_sensor domain. | Test OpenClose trait support for binary_sensor domain. | async def test_openclose_binary_sensor(hass, device_class):
"""Test OpenClose trait support for binary_sensor domain."""
assert helpers.get_google_type(binary_sensor.DOMAIN, device_class) is not None
assert trait.OpenCloseTrait.supported(binary_sensor.DOMAIN, 0, device_class)
trt = trait.OpenCloseTrait(
hass,
State("binary_sensor.test", STATE_ON, {ATTR_DEVICE_CLASS: device_class}),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {
"queryOnlyOpenClose": True,
"discreteOnlyOpenClose": True,
}
assert trt.query_attributes() == {"openPercent": 100}
trt = trait.OpenCloseTrait(
hass,
State("binary_sensor.test", STATE_OFF, {ATTR_DEVICE_CLASS: device_class}),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {
"queryOnlyOpenClose": True,
"discreteOnlyOpenClose": True,
}
assert trt.query_attributes() == {"openPercent": 0} | [
"async",
"def",
"test_openclose_binary_sensor",
"(",
"hass",
",",
"device_class",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"binary_sensor",
".",
"DOMAIN",
",",
"device_class",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"OpenCloseTrait",
... | [
2077,
0
] | [
2106,
55
] | python | en | ['fr', 'en', 'en'] | True |
test_volume_media_player | (hass) | Test volume trait support for media player domain. | Test volume trait support for media player domain. | async def test_volume_media_player(hass):
"""Test volume trait support for media player domain."""
assert helpers.get_google_type(media_player.DOMAIN, None) is not None
assert trait.VolumeTrait.supported(
media_player.DOMAIN,
media_player.SUPPORT_VOLUME_SET,
None,
)
trt = trait.VolumeTrait(
hass,
State(
"media_player.bla",
media_player.STATE_PLAYING,
{
ATTR_SUPPORTED_FEATURES: media_player.SUPPORT_VOLUME_SET,
media_player.ATTR_MEDIA_VOLUME_LEVEL: 0.3,
},
),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {
"volumeMaxLevel": 100,
"levelStepSize": 10,
"volumeCanMuteAndUnmute": False,
"commandOnlyVolume": False,
}
assert trt.query_attributes() == {"currentVolume": 30}
calls = async_mock_service(
hass, media_player.DOMAIN, media_player.SERVICE_VOLUME_SET
)
await trt.execute(trait.COMMAND_SET_VOLUME, BASIC_DATA, {"volumeLevel": 60}, {})
assert len(calls) == 1
assert calls[0].data == {
ATTR_ENTITY_ID: "media_player.bla",
media_player.ATTR_MEDIA_VOLUME_LEVEL: 0.6,
}
calls = async_mock_service(
hass, media_player.DOMAIN, media_player.SERVICE_VOLUME_SET
)
await trt.execute(
trait.COMMAND_VOLUME_RELATIVE, BASIC_DATA, {"relativeSteps": 10}, {}
)
assert len(calls) == 1
assert calls[0].data == {
ATTR_ENTITY_ID: "media_player.bla",
media_player.ATTR_MEDIA_VOLUME_LEVEL: 0.4,
} | [
"async",
"def",
"test_volume_media_player",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"media_player",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"VolumeTrait",
".",
"supported",
"(",
"media_play... | [
2109,
0
] | [
2160,
5
] | python | en | ['fr', 'en', 'en'] | True |
test_volume_media_player_relative | (hass) | Test volume trait support for relative-volume-only media players. | Test volume trait support for relative-volume-only media players. | async def test_volume_media_player_relative(hass):
"""Test volume trait support for relative-volume-only media players."""
assert trait.VolumeTrait.supported(
media_player.DOMAIN,
media_player.SUPPORT_VOLUME_STEP,
None,
)
trt = trait.VolumeTrait(
hass,
State(
"media_player.bla",
media_player.STATE_PLAYING,
{
ATTR_ASSUMED_STATE: True,
ATTR_SUPPORTED_FEATURES: media_player.SUPPORT_VOLUME_STEP,
},
),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {
"volumeMaxLevel": 100,
"levelStepSize": 10,
"volumeCanMuteAndUnmute": False,
"commandOnlyVolume": True,
}
assert trt.query_attributes() == {}
calls = async_mock_service(
hass, media_player.DOMAIN, media_player.SERVICE_VOLUME_UP
)
await trt.execute(
trait.COMMAND_VOLUME_RELATIVE,
BASIC_DATA,
{"relativeSteps": 10},
{},
)
assert len(calls) == 10
for call in calls:
assert call.data == {
ATTR_ENTITY_ID: "media_player.bla",
}
calls = async_mock_service(
hass, media_player.DOMAIN, media_player.SERVICE_VOLUME_DOWN
)
await trt.execute(
trait.COMMAND_VOLUME_RELATIVE,
BASIC_DATA,
{"relativeSteps": -10},
{},
)
assert len(calls) == 10
for call in calls:
assert call.data == {
ATTR_ENTITY_ID: "media_player.bla",
}
with pytest.raises(SmartHomeError):
await trt.execute(trait.COMMAND_SET_VOLUME, BASIC_DATA, {"volumeLevel": 42}, {})
with pytest.raises(SmartHomeError):
await trt.execute(trait.COMMAND_MUTE, BASIC_DATA, {"mute": True}, {}) | [
"async",
"def",
"test_volume_media_player_relative",
"(",
"hass",
")",
":",
"assert",
"trait",
".",
"VolumeTrait",
".",
"supported",
"(",
"media_player",
".",
"DOMAIN",
",",
"media_player",
".",
"SUPPORT_VOLUME_STEP",
",",
"None",
",",
")",
"trt",
"=",
"trait",
... | [
2163,
0
] | [
2227,
77
] | python | en | ['en', 'en', 'en'] | True |
test_media_player_mute | (hass) | Test volume trait support for muting. | Test volume trait support for muting. | async def test_media_player_mute(hass):
"""Test volume trait support for muting."""
assert trait.VolumeTrait.supported(
media_player.DOMAIN,
media_player.SUPPORT_VOLUME_STEP | media_player.SUPPORT_VOLUME_MUTE,
None,
)
trt = trait.VolumeTrait(
hass,
State(
"media_player.bla",
media_player.STATE_PLAYING,
{
ATTR_SUPPORTED_FEATURES: (
media_player.SUPPORT_VOLUME_STEP | media_player.SUPPORT_VOLUME_MUTE
),
media_player.ATTR_MEDIA_VOLUME_MUTED: False,
},
),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {
"volumeMaxLevel": 100,
"levelStepSize": 10,
"volumeCanMuteAndUnmute": True,
"commandOnlyVolume": False,
}
assert trt.query_attributes() == {"isMuted": False}
mute_calls = async_mock_service(
hass, media_player.DOMAIN, media_player.SERVICE_VOLUME_MUTE
)
await trt.execute(
trait.COMMAND_MUTE,
BASIC_DATA,
{"mute": True},
{},
)
assert len(mute_calls) == 1
assert mute_calls[0].data == {
ATTR_ENTITY_ID: "media_player.bla",
media_player.ATTR_MEDIA_VOLUME_MUTED: True,
}
unmute_calls = async_mock_service(
hass, media_player.DOMAIN, media_player.SERVICE_VOLUME_MUTE
)
await trt.execute(
trait.COMMAND_MUTE,
BASIC_DATA,
{"mute": False},
{},
)
assert len(unmute_calls) == 1
assert unmute_calls[0].data == {
ATTR_ENTITY_ID: "media_player.bla",
media_player.ATTR_MEDIA_VOLUME_MUTED: False,
} | [
"async",
"def",
"test_media_player_mute",
"(",
"hass",
")",
":",
"assert",
"trait",
".",
"VolumeTrait",
".",
"supported",
"(",
"media_player",
".",
"DOMAIN",
",",
"media_player",
".",
"SUPPORT_VOLUME_STEP",
"|",
"media_player",
".",
"SUPPORT_VOLUME_MUTE",
",",
"No... | [
2230,
0
] | [
2288,
5
] | python | en | ['fr', 'en', 'en'] | True |
test_temperature_setting_sensor | (hass) | Test TemperatureSetting trait support for temperature sensor. | Test TemperatureSetting trait support for temperature sensor. | async def test_temperature_setting_sensor(hass):
"""Test TemperatureSetting trait support for temperature sensor."""
assert (
helpers.get_google_type(sensor.DOMAIN, sensor.DEVICE_CLASS_TEMPERATURE)
is not None
)
assert not trait.TemperatureSettingTrait.supported(
sensor.DOMAIN, 0, sensor.DEVICE_CLASS_HUMIDITY
)
assert trait.TemperatureSettingTrait.supported(
sensor.DOMAIN, 0, sensor.DEVICE_CLASS_TEMPERATURE
) | [
"async",
"def",
"test_temperature_setting_sensor",
"(",
"hass",
")",
":",
"assert",
"(",
"helpers",
".",
"get_google_type",
"(",
"sensor",
".",
"DOMAIN",
",",
"sensor",
".",
"DEVICE_CLASS_TEMPERATURE",
")",
"is",
"not",
"None",
")",
"assert",
"not",
"trait",
"... | [
2291,
0
] | [
2302,
5
] | python | en | ['en', 'la', 'en'] | True |
test_temperature_setting_sensor_data | (hass, unit_in, unit_out, state, ambient) | Test TemperatureSetting trait support for temperature sensor. | Test TemperatureSetting trait support for temperature sensor. | async def test_temperature_setting_sensor_data(hass, unit_in, unit_out, state, ambient):
"""Test TemperatureSetting trait support for temperature sensor."""
hass.config.units.temperature_unit = unit_in
trt = trait.TemperatureSettingTrait(
hass,
State(
"sensor.test", state, {ATTR_DEVICE_CLASS: sensor.DEVICE_CLASS_TEMPERATURE}
),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {
"queryOnlyTemperatureSetting": True,
"thermostatTemperatureUnit": unit_out,
}
if ambient:
assert trt.query_attributes() == {"thermostatTemperatureAmbient": ambient}
else:
assert trt.query_attributes() == {}
hass.config.units.temperature_unit = TEMP_CELSIUS | [
"async",
"def",
"test_temperature_setting_sensor_data",
"(",
"hass",
",",
"unit_in",
",",
"unit_out",
",",
"state",
",",
"ambient",
")",
":",
"hass",
".",
"config",
".",
"units",
".",
"temperature_unit",
"=",
"unit_in",
"trt",
"=",
"trait",
".",
"TemperatureSe... | [
2314,
0
] | [
2335,
53
] | python | en | ['en', 'la', 'en'] | True |
test_humidity_setting_sensor | (hass) | Test HumiditySetting trait support for humidity sensor. | Test HumiditySetting trait support for humidity sensor. | async def test_humidity_setting_sensor(hass):
"""Test HumiditySetting trait support for humidity sensor."""
assert (
helpers.get_google_type(sensor.DOMAIN, sensor.DEVICE_CLASS_HUMIDITY) is not None
)
assert not trait.HumiditySettingTrait.supported(
sensor.DOMAIN, 0, sensor.DEVICE_CLASS_TEMPERATURE
)
assert trait.HumiditySettingTrait.supported(
sensor.DOMAIN, 0, sensor.DEVICE_CLASS_HUMIDITY
) | [
"async",
"def",
"test_humidity_setting_sensor",
"(",
"hass",
")",
":",
"assert",
"(",
"helpers",
".",
"get_google_type",
"(",
"sensor",
".",
"DOMAIN",
",",
"sensor",
".",
"DEVICE_CLASS_HUMIDITY",
")",
"is",
"not",
"None",
")",
"assert",
"not",
"trait",
".",
... | [
2338,
0
] | [
2348,
5
] | python | en | ['en', 'en', 'en'] | True |
test_humidity_setting_sensor_data | (hass, state, ambient) | Test HumiditySetting trait support for humidity sensor. | Test HumiditySetting trait support for humidity sensor. | async def test_humidity_setting_sensor_data(hass, state, ambient):
"""Test HumiditySetting trait support for humidity sensor."""
trt = trait.HumiditySettingTrait(
hass,
State("sensor.test", state, {ATTR_DEVICE_CLASS: sensor.DEVICE_CLASS_HUMIDITY}),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {"queryOnlyHumiditySetting": True}
if ambient:
assert trt.query_attributes() == {"humidityAmbientPercent": ambient}
else:
assert trt.query_attributes() == {}
with pytest.raises(helpers.SmartHomeError) as err:
await trt.execute(trait.COMMAND_ONOFF, BASIC_DATA, {"on": False}, {})
assert err.value.code == const.ERR_NOT_SUPPORTED | [
"async",
"def",
"test_humidity_setting_sensor_data",
"(",
"hass",
",",
"state",
",",
"ambient",
")",
":",
"trt",
"=",
"trait",
".",
"HumiditySettingTrait",
"(",
"hass",
",",
"State",
"(",
"\"sensor.test\"",
",",
"state",
",",
"{",
"ATTR_DEVICE_CLASS",
":",
"se... | [
2354,
0
] | [
2370,
52
] | python | en | ['en', 'en', 'en'] | True |
test_transport_control | (hass) | Test the TransportControlTrait. | Test the TransportControlTrait. | async def test_transport_control(hass):
"""Test the TransportControlTrait."""
assert helpers.get_google_type(media_player.DOMAIN, None) is not None
for feature in trait.MEDIA_COMMAND_SUPPORT_MAPPING.values():
assert trait.TransportControlTrait.supported(media_player.DOMAIN, feature, None)
now = datetime(2020, 1, 1)
trt = trait.TransportControlTrait(
hass,
State(
"media_player.bla",
media_player.STATE_PLAYING,
{
media_player.ATTR_MEDIA_POSITION: 100,
media_player.ATTR_MEDIA_DURATION: 200,
media_player.ATTR_MEDIA_POSITION_UPDATED_AT: now
- timedelta(seconds=10),
media_player.ATTR_MEDIA_VOLUME_LEVEL: 0.5,
ATTR_SUPPORTED_FEATURES: media_player.SUPPORT_PLAY
| media_player.SUPPORT_STOP,
},
),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {
"transportControlSupportedCommands": ["RESUME", "STOP"]
}
assert trt.query_attributes() == {}
# COMMAND_MEDIA_SEEK_RELATIVE
calls = async_mock_service(
hass, media_player.DOMAIN, media_player.SERVICE_MEDIA_SEEK
)
# Patch to avoid time ticking over during the command failing the test
with patch("homeassistant.util.dt.utcnow", return_value=now):
await trt.execute(
trait.COMMAND_MEDIA_SEEK_RELATIVE,
BASIC_DATA,
{"relativePositionMs": 10000},
{},
)
assert len(calls) == 1
assert calls[0].data == {
ATTR_ENTITY_ID: "media_player.bla",
# 100s (current position) + 10s (from command) + 10s (from updated_at)
media_player.ATTR_MEDIA_SEEK_POSITION: 120,
}
# COMMAND_MEDIA_SEEK_TO_POSITION
calls = async_mock_service(
hass, media_player.DOMAIN, media_player.SERVICE_MEDIA_SEEK
)
await trt.execute(
trait.COMMAND_MEDIA_SEEK_TO_POSITION, BASIC_DATA, {"absPositionMs": 50000}, {}
)
assert len(calls) == 1
assert calls[0].data == {
ATTR_ENTITY_ID: "media_player.bla",
media_player.ATTR_MEDIA_SEEK_POSITION: 50,
}
# COMMAND_MEDIA_NEXT
calls = async_mock_service(
hass, media_player.DOMAIN, media_player.SERVICE_MEDIA_NEXT_TRACK
)
await trt.execute(trait.COMMAND_MEDIA_NEXT, BASIC_DATA, {}, {})
assert len(calls) == 1
assert calls[0].data == {ATTR_ENTITY_ID: "media_player.bla"}
# COMMAND_MEDIA_PAUSE
calls = async_mock_service(
hass, media_player.DOMAIN, media_player.SERVICE_MEDIA_PAUSE
)
await trt.execute(trait.COMMAND_MEDIA_PAUSE, BASIC_DATA, {}, {})
assert len(calls) == 1
assert calls[0].data == {ATTR_ENTITY_ID: "media_player.bla"}
# COMMAND_MEDIA_PREVIOUS
calls = async_mock_service(
hass, media_player.DOMAIN, media_player.SERVICE_MEDIA_PREVIOUS_TRACK
)
await trt.execute(trait.COMMAND_MEDIA_PREVIOUS, BASIC_DATA, {}, {})
assert len(calls) == 1
assert calls[0].data == {ATTR_ENTITY_ID: "media_player.bla"}
# COMMAND_MEDIA_RESUME
calls = async_mock_service(
hass, media_player.DOMAIN, media_player.SERVICE_MEDIA_PLAY
)
await trt.execute(trait.COMMAND_MEDIA_RESUME, BASIC_DATA, {}, {})
assert len(calls) == 1
assert calls[0].data == {ATTR_ENTITY_ID: "media_player.bla"}
# COMMAND_MEDIA_SHUFFLE
calls = async_mock_service(
hass, media_player.DOMAIN, media_player.SERVICE_SHUFFLE_SET
)
await trt.execute(trait.COMMAND_MEDIA_SHUFFLE, BASIC_DATA, {}, {})
assert len(calls) == 1
assert calls[0].data == {
ATTR_ENTITY_ID: "media_player.bla",
media_player.ATTR_MEDIA_SHUFFLE: True,
}
# COMMAND_MEDIA_STOP
calls = async_mock_service(
hass, media_player.DOMAIN, media_player.SERVICE_MEDIA_STOP
)
await trt.execute(trait.COMMAND_MEDIA_STOP, BASIC_DATA, {}, {})
assert len(calls) == 1
assert calls[0].data == {ATTR_ENTITY_ID: "media_player.bla"} | [
"async",
"def",
"test_transport_control",
"(",
"hass",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"media_player",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"for",
"feature",
"in",
"trait",
".",
"MEDIA_COMMAND_SUPPORT_MAPPING",
".",
... | [
2373,
0
] | [
2487,
64
] | python | en | ['en', 'fr', 'en'] | True |
test_media_state | (hass, state) | Test the MediaStateTrait. | Test the MediaStateTrait. | async def test_media_state(hass, state):
"""Test the MediaStateTrait."""
assert helpers.get_google_type(media_player.DOMAIN, None) is not None
assert trait.TransportControlTrait.supported(
media_player.DOMAIN, media_player.SUPPORT_PLAY, None
)
trt = trait.MediaStateTrait(
hass,
State(
"media_player.bla",
state,
{
media_player.ATTR_MEDIA_POSITION: 100,
media_player.ATTR_MEDIA_DURATION: 200,
media_player.ATTR_MEDIA_VOLUME_LEVEL: 0.5,
ATTR_SUPPORTED_FEATURES: media_player.SUPPORT_PLAY
| media_player.SUPPORT_STOP,
},
),
BASIC_CONFIG,
)
assert trt.sync_attributes() == {
"supportActivityState": True,
"supportPlaybackState": True,
}
assert trt.query_attributes() == {
"activityState": trt.activity_lookup.get(state),
"playbackState": trt.playback_lookup.get(state),
} | [
"async",
"def",
"test_media_state",
"(",
"hass",
",",
"state",
")",
":",
"assert",
"helpers",
".",
"get_google_type",
"(",
"media_player",
".",
"DOMAIN",
",",
"None",
")",
"is",
"not",
"None",
"assert",
"trait",
".",
"TransportControlTrait",
".",
"supported",
... | [
2503,
0
] | [
2534,
5
] | python | en | ['en', 'fi', 'en'] | True |
HTMLCorpusReader.__init__ | (self, root, fileids=DOC_PATTERN,
word_tokenizer=WordPunctTokenizer(),
sent_tokenizer=nltk.data.LazyLoader(
'tokenizers/punkt/english.pickle'),
encoding='latin-1', **kwargs) |
Initialize the corpus reader. Categorization arguments
(``cat_pattern``, ``cat_map``, and ``cat_file``) are passed to
the ``CategorizedCorpusReader`` constructor. The remaining
arguments are passed to the ``CorpusReader`` constructor.
|
Initialize the corpus reader. Categorization arguments
(``cat_pattern``, ``cat_map``, and ``cat_file``) are passed to
the ``CategorizedCorpusReader`` constructor. The remaining
arguments are passed to the ``CorpusReader`` constructor.
| def __init__(self, root, fileids=DOC_PATTERN,
word_tokenizer=WordPunctTokenizer(),
sent_tokenizer=nltk.data.LazyLoader(
'tokenizers/punkt/english.pickle'),
encoding='latin-1', **kwargs):
"""
Initialize the corpus reader. Categorization arguments
(``cat_pattern``, ``cat_map``, and ``cat_file``) are passed to
the ``CategorizedCorpusReader`` constructor. The remaining
arguments are passed to the ``CorpusReader`` constructor.
"""
# Add the default category pattern if not passed into the class.
if not any(key.startswith('cat_') for key in kwargs.keys()):
kwargs['cat_pattern'] = CAT_PATTERN
CategorizedCorpusReader.__init__(self, kwargs)
CorpusReader.__init__(self, root, fileids, encoding)
self._word_tokenizer = word_tokenizer
self._sent_tokenizer = sent_tokenizer
self._tags = TAGS | [
"def",
"__init__",
"(",
"self",
",",
"root",
",",
"fileids",
"=",
"DOC_PATTERN",
",",
"word_tokenizer",
"=",
"WordPunctTokenizer",
"(",
")",
",",
"sent_tokenizer",
"=",
"nltk",
".",
"data",
".",
"LazyLoader",
"(",
"'tokenizers/punkt/english.pickle'",
")",
",",
... | [
32,
4
] | [
52,
25
] | python | en | ['en', 'error', 'th'] | False |
HTMLCorpusReader.resolve | (self, fileids, categories) |
Returns a list of fileids or categories depending on what is passed
to each internal corpus reader function. Implemented similarly to
the NLTK ``CategorizedPlaintextCorpusReader``.
|
Returns a list of fileids or categories depending on what is passed
to each internal corpus reader function. Implemented similarly to
the NLTK ``CategorizedPlaintextCorpusReader``.
| def resolve(self, fileids, categories):
"""
Returns a list of fileids or categories depending on what is passed
to each internal corpus reader function. Implemented similarly to
the NLTK ``CategorizedPlaintextCorpusReader``.
"""
if fileids is not None and categories is not None:
raise ValueError("Specify fileids or categories, not both")
if categories is not None:
return self.fileids(categories)
return fileids | [
"def",
"resolve",
"(",
"self",
",",
"fileids",
",",
"categories",
")",
":",
"if",
"fileids",
"is",
"not",
"None",
"and",
"categories",
"is",
"not",
"None",
":",
"raise",
"ValueError",
"(",
"\"Specify fileids or categories, not both\"",
")",
"if",
"categories",
... | [
54,
4
] | [
65,
22
] | python | en | ['en', 'error', 'th'] | False |
HTMLCorpusReader.docs | (self, fileids=None, categories=None) |
Returns the complete text of an HTML document, closing the document
after we are done reading it and yielding it in a memory safe fashion.
|
Returns the complete text of an HTML document, closing the document
after we are done reading it and yielding it in a memory safe fashion.
| def docs(self, fileids=None, categories=None):
"""
Returns the complete text of an HTML document, closing the document
after we are done reading it and yielding it in a memory safe fashion.
"""
# Resolve the fileids and the categories
fileids = self.resolve(fileids, categories)
# Create a generator, loading one document into memory at a time.
for path, encoding in self.abspaths(fileids, include_encoding=True):
with codecs.open(path, 'r', encoding=encoding) as f:
yield f.read() | [
"def",
"docs",
"(",
"self",
",",
"fileids",
"=",
"None",
",",
"categories",
"=",
"None",
")",
":",
"# Resolve the fileids and the categories",
"fileids",
"=",
"self",
".",
"resolve",
"(",
"fileids",
",",
"categories",
")",
"# Create a generator, loading one document... | [
67,
4
] | [
78,
30
] | python | en | ['en', 'error', 'th'] | False |
HTMLCorpusReader.html | (self, fileids=None, categories=None) |
Returns the HTML content of each document, cleaning it using
the readability-lxml library.
|
Returns the HTML content of each document, cleaning it using
the readability-lxml library.
| def html(self, fileids=None, categories=None):
"""
Returns the HTML content of each document, cleaning it using
the readability-lxml library.
"""
for doc in self.docs(fileids, categories):
try:
yield Paper(doc).summary()
except Unparseable as e:
print("Could not parse HTML: {}".format(e))
continue | [
"def",
"html",
"(",
"self",
",",
"fileids",
"=",
"None",
",",
"categories",
"=",
"None",
")",
":",
"for",
"doc",
"in",
"self",
".",
"docs",
"(",
"fileids",
",",
"categories",
")",
":",
"try",
":",
"yield",
"Paper",
"(",
"doc",
")",
".",
"summary",
... | [
80,
4
] | [
90,
24
] | python | en | ['en', 'error', 'th'] | False |
HTMLCorpusReader.paras | (self, fileids=None, categories=None) |
Uses BeautifulSoup to parse the paragraphs from the HTML.
|
Uses BeautifulSoup to parse the paragraphs from the HTML.
| def paras(self, fileids=None, categories=None):
"""
Uses BeautifulSoup to parse the paragraphs from the HTML.
"""
for html in self.html(fileids, categories):
soup = bs4.BeautifulSoup(html, 'lxml')
for element in soup.find_all(self._tags):
yield element.text
soup.decompose() | [
"def",
"paras",
"(",
"self",
",",
"fileids",
"=",
"None",
",",
"categories",
"=",
"None",
")",
":",
"for",
"html",
"in",
"self",
".",
"html",
"(",
"fileids",
",",
"categories",
")",
":",
"soup",
"=",
"bs4",
".",
"BeautifulSoup",
"(",
"html",
",",
"... | [
92,
4
] | [
100,
28
] | python | en | ['en', 'error', 'th'] | False |
HTMLCorpusReader.titles | (self, fileids=None, categories=None) |
Uses BeautifulSoup to identify titles from the
head tags within the HTML
|
Uses BeautifulSoup to identify titles from the
head tags within the HTML
| def titles(self, fileids=None, categories=None):
"""
Uses BeautifulSoup to identify titles from the
head tags within the HTML
"""
for doc in self.docs(fileids, categories):
soup = bs4.BeautifulSoup(doc, 'lxml')
try:
yield soup.title.text
soup.decompose()
except AttributeError as e:
continue | [
"def",
"titles",
"(",
"self",
",",
"fileids",
"=",
"None",
",",
"categories",
"=",
"None",
")",
":",
"for",
"doc",
"in",
"self",
".",
"docs",
"(",
"fileids",
",",
"categories",
")",
":",
"soup",
"=",
"bs4",
".",
"BeautifulSoup",
"(",
"doc",
",",
"'... | [
102,
4
] | [
113,
24
] | python | en | ['en', 'error', 'th'] | False |
HTMLCorpusReader.sents | (self, fileids=None, categories=None) |
Uses the built in sentence tokenizer to extract sentences from the
paragraphs. Note that this method uses BeautifulSoup to parse HTML.
|
Uses the built in sentence tokenizer to extract sentences from the
paragraphs. Note that this method uses BeautifulSoup to parse HTML.
| def sents(self, fileids=None, categories=None):
"""
Uses the built in sentence tokenizer to extract sentences from the
paragraphs. Note that this method uses BeautifulSoup to parse HTML.
"""
for paragraph in self.paras(fileids, categories):
for sentence in sent_tokenize(paragraph):
yield sentence | [
"def",
"sents",
"(",
"self",
",",
"fileids",
"=",
"None",
",",
"categories",
"=",
"None",
")",
":",
"for",
"paragraph",
"in",
"self",
".",
"paras",
"(",
"fileids",
",",
"categories",
")",
":",
"for",
"sentence",
"in",
"sent_tokenize",
"(",
"paragraph",
... | [
115,
4
] | [
122,
30
] | python | en | ['en', 'error', 'th'] | False |
HTMLCorpusReader.words | (self, fileids=None, categories=None) |
Uses the built in word tokenizer to extract tokens from sentences.
Note that this method uses BeautifulSoup to parse HTML content.
|
Uses the built in word tokenizer to extract tokens from sentences.
Note that this method uses BeautifulSoup to parse HTML content.
| def words(self, fileids=None, categories=None):
"""
Uses the built in word tokenizer to extract tokens from sentences.
Note that this method uses BeautifulSoup to parse HTML content.
"""
for sentence in self.sents(fileids, categories):
for token in wordpunct_tokenize(sentence):
yield token | [
"def",
"words",
"(",
"self",
",",
"fileids",
"=",
"None",
",",
"categories",
"=",
"None",
")",
":",
"for",
"sentence",
"in",
"self",
".",
"sents",
"(",
"fileids",
",",
"categories",
")",
":",
"for",
"token",
"in",
"wordpunct_tokenize",
"(",
"sentence",
... | [
124,
4
] | [
131,
27
] | python | en | ['en', 'error', 'th'] | False |
HTMLCorpusReader.tokenize | (self, fileids=None, categories=None) |
Segments, tokenizes, and tags a document in the corpus.
|
Segments, tokenizes, and tags a document in the corpus.
| def tokenize(self, fileids=None, categories=None):
"""
Segments, tokenizes, and tags a document in the corpus.
"""
for paragraph in self.corpus.paras(fileids=fileid):
yield [
pos_tag(nltk.wordpunct_tokenize(sent))
for sent in nltk.sent_tokenize(paragraph)
] | [
"def",
"tokenize",
"(",
"self",
",",
"fileids",
"=",
"None",
",",
"categories",
"=",
"None",
")",
":",
"for",
"paragraph",
"in",
"self",
".",
"corpus",
".",
"paras",
"(",
"fileids",
"=",
"fileid",
")",
":",
"yield",
"[",
"pos_tag",
"(",
"nltk",
".",
... | [
133,
4
] | [
141,
13
] | python | en | ['en', 'error', 'th'] | False |
HTMLCorpusReader.sizes | (self, fileids=None, categories=None) |
Returns a list of tuples, the fileid and the size on disk of the file.
This function is used to detect oddly large files in the corpus.
|
Returns a list of tuples, the fileid and the size on disk of the file.
This function is used to detect oddly large files in the corpus.
| def sizes(self, fileids=None, categories=None):
"""
Returns a list of tuples, the fileid and the size on disk of the file.
This function is used to detect oddly large files in the corpus.
"""
# Resolve the fileids and the categories
fileids = self.resolve(fileids, categories)
# Create a generator, getting every path and computing filesize
for path, enc, fileid in self.abspaths(fileids, True, True):
yield os.path.getsize(path) | [
"def",
"sizes",
"(",
"self",
",",
"fileids",
"=",
"None",
",",
"categories",
"=",
"None",
")",
":",
"# Resolve the fileids and the categories",
"fileids",
"=",
"self",
".",
"resolve",
"(",
"fileids",
",",
"categories",
")",
"# Create a generator, getting every path ... | [
143,
4
] | [
153,
39
] | python | en | ['en', 'error', 'th'] | False |
HTMLCorpusReader.describe | (self, fileids=None, categories=None) |
Performs a single pass of the corpus and returns a dictionary with a
variety of metrics concerning the state of the corpus.
|
Performs a single pass of the corpus and returns a dictionary with a
variety of metrics concerning the state of the corpus.
| def describe(self, fileids=None, categories=None):
"""
Performs a single pass of the corpus and returns a dictionary with a
variety of metrics concerning the state of the corpus.
"""
# Structures to perform counting.
counts = nltk.FreqDist()
tokens = nltk.FreqDist()
started = time.time()
# Perform single pass over paragraphs, tokenize and count
for para in self.paras(fileids, categories):
counts['paras'] += 1
for sent in self._sent_tokenizer.tokenize(para):
counts['sents'] += 1
for word in self._word_tokenizer.tokenize(sent):
counts['words'] += 1
tokens[word] += 1
# Compute the number of files and categories in the corpus
n_fileids = len(self.resolve(fileids, categories) or self.fileids())
n_topics = len(self.categories(self.resolve(fileids, categories)))
# Return data structure with information
return {
'files': n_fileids,
'topics': n_topics,
'paras': counts['paras'],
'sents': counts['sents'],
'words': counts['words'],
'vocab': len(tokens),
'lexdiv': float(counts['words']) / float(len(tokens)),
'ppdoc': float(counts['paras']) / float(n_fileids),
'sppar': float(counts['sents']) / float(counts['paras']),
'secs': time.time() - started,
} | [
"def",
"describe",
"(",
"self",
",",
"fileids",
"=",
"None",
",",
"categories",
"=",
"None",
")",
":",
"# Structures to perform counting.",
"counts",
"=",
"nltk",
".",
"FreqDist",
"(",
")",
"tokens",
"=",
"nltk",
".",
"FreqDist",
"(",
")",
"started",
"=",
... | [
155,
4
] | [
192,
9
] | python | en | ['en', 'error', 'th'] | False |
HTMLCorpusReader.describes | (self, fileids=None, categories=None) |
Returns a string representation of the describe command.
|
Returns a string representation of the describe command.
| def describes(self, fileids=None, categories=None):
"""
Returns a string representation of the describe command.
"""
return (
"HTML corpus contains {files} files in {topics} categories.\n"
"Structured as:\n"
" {paras} paragraphs ({ppdoc:0.3f} mean paragraphs per file)\n"
" {sents} sentences ({sppar:0.3f} mean sentences per paragraph).\n"
"Word count of {words} with a vocabulary of {vocab} "
"({lexdiv:0.3f} lexical diversity).\n"
"Corpus scan took {secs:0.3f} seconds."
).format(**self.describe(fileids, categories)) | [
"def",
"describes",
"(",
"self",
",",
"fileids",
"=",
"None",
",",
"categories",
"=",
"None",
")",
":",
"return",
"(",
"\"HTML corpus contains {files} files in {topics} categories.\\n\"",
"\"Structured as:\\n\"",
"\" {paras} paragraphs ({ppdoc:0.3f} mean paragraphs per file)\\... | [
194,
4
] | [
206,
54
] | python | en | ['en', 'error', 'th'] | False |
HTMLPickledCorpusReader.__init__ | (self, root, fileids=PKL_PATTERN, **kwargs) |
Initialize the corpus reader. Categorization arguments
(``cat_pattern``, ``cat_map``, and ``cat_file``) are passed to
the ``CategorizedCorpusReader`` constructor. The remaining arguments
are passed to the ``CorpusReader`` constructor.
|
Initialize the corpus reader. Categorization arguments
(``cat_pattern``, ``cat_map``, and ``cat_file``) are passed to
the ``CategorizedCorpusReader`` constructor. The remaining arguments
are passed to the ``CorpusReader`` constructor.
| def __init__(self, root, fileids=PKL_PATTERN, **kwargs):
"""
Initialize the corpus reader. Categorization arguments
(``cat_pattern``, ``cat_map``, and ``cat_file``) are passed to
the ``CategorizedCorpusReader`` constructor. The remaining arguments
are passed to the ``CorpusReader`` constructor.
"""
# Add the default category pattern if not passed into the class.
if not any(key.startswith('cat_') for key in kwargs.keys()):
kwargs['cat_pattern'] = CAT_PATTERN
CategorizedCorpusReader.__init__(self, kwargs)
CorpusReader.__init__(self, root, fileids) | [
"def",
"__init__",
"(",
"self",
",",
"root",
",",
"fileids",
"=",
"PKL_PATTERN",
",",
"*",
"*",
"kwargs",
")",
":",
"# Add the default category pattern if not passed into the class.",
"if",
"not",
"any",
"(",
"key",
".",
"startswith",
"(",
"'cat_'",
")",
"for",
... | [
210,
4
] | [
222,
50
] | python | en | ['en', 'error', 'th'] | False |
HTMLPickledCorpusReader.resolve | (self, fileids, categories) |
Returns a list of fileids or categories depending on what is passed
to each internal corpus reader function. This primarily bubbles up to
the high level ``docs`` method, but is implemented here similar to
the nltk ``CategorizedPlaintextCorpusReader``.
|
Returns a list of fileids or categories depending on what is passed
to each internal corpus reader function. This primarily bubbles up to
the high level ``docs`` method, but is implemented here similar to
the nltk ``CategorizedPlaintextCorpusReader``.
| def resolve(self, fileids, categories):
"""
Returns a list of fileids or categories depending on what is passed
to each internal corpus reader function. This primarily bubbles up to
the high level ``docs`` method, but is implemented here similar to
the nltk ``CategorizedPlaintextCorpusReader``.
"""
if fileids is not None and categories is not None:
raise ValueError("Specify fileids or categories, not both")
if categories is not None:
return self.fileids(categories)
return fileids | [
"def",
"resolve",
"(",
"self",
",",
"fileids",
",",
"categories",
")",
":",
"if",
"fileids",
"is",
"not",
"None",
"and",
"categories",
"is",
"not",
"None",
":",
"raise",
"ValueError",
"(",
"\"Specify fileids or categories, not both\"",
")",
"if",
"categories",
... | [
224,
4
] | [
236,
22
] | python | en | ['en', 'error', 'th'] | False |
HTMLPickledCorpusReader.text | (self, fileids=None, categories=None) |
Returns the document loaded from a pickled object for every file in
the corpus. Similar to the BaleenCorpusReader, this uses a generator
to acheive memory safe iteration.
|
Returns the document loaded from a pickled object for every file in
the corpus. Similar to the BaleenCorpusReader, this uses a generator
to acheive memory safe iteration.
| def text(self, fileids=None, categories=None):
"""
Returns the document loaded from a pickled object for every file in
the corpus. Similar to the BaleenCorpusReader, this uses a generator
to acheive memory safe iteration.
"""
# Resolve the fileids and the categories
fileids = self.resolve(fileids, categories)
# Create a generator, loading one document into memory at a time.
for path, enc, fileid in self.abspaths(fileids, True, True):
with open(path, 'rb') as f:
yield pickle.load(f) | [
"def",
"text",
"(",
"self",
",",
"fileids",
"=",
"None",
",",
"categories",
"=",
"None",
")",
":",
"# Resolve the fileids and the categories",
"fileids",
"=",
"self",
".",
"resolve",
"(",
"fileids",
",",
"categories",
")",
"# Create a generator, loading one document... | [
238,
4
] | [
250,
36
] | python | en | ['en', 'error', 'th'] | False |
HTMLPickledCorpusReader.docs | (self, fileids=None, categories=None) |
Returns a generator of paragraphs where each paragraph is a list of
sentences, which is in turn a list of (token, tag) tuples.
|
Returns a generator of paragraphs where each paragraph is a list of
sentences, which is in turn a list of (token, tag) tuples.
| def docs(self, fileids=None, categories=None):
"""
Returns a generator of paragraphs where each paragraph is a list of
sentences, which is in turn a list of (token, tag) tuples.
"""
for doc in self.text(fileids, categories):
yield doc['document'] | [
"def",
"docs",
"(",
"self",
",",
"fileids",
"=",
"None",
",",
"categories",
"=",
"None",
")",
":",
"for",
"doc",
"in",
"self",
".",
"text",
"(",
"fileids",
",",
"categories",
")",
":",
"yield",
"doc",
"[",
"'document'",
"]"
] | [
252,
4
] | [
258,
33
] | python | en | ['en', 'error', 'th'] | False |
HTMLPickledCorpusReader.titles | (self, fileids=None, categories=None) |
Uses BeautifulSoup to identify titles from the
head tags within the HTML
|
Uses BeautifulSoup to identify titles from the
head tags within the HTML
| def titles(self, fileids=None, categories=None):
"""
Uses BeautifulSoup to identify titles from the
head tags within the HTML
"""
for doc in self.text(fileids, categories):
yield doc['title'] | [
"def",
"titles",
"(",
"self",
",",
"fileids",
"=",
"None",
",",
"categories",
"=",
"None",
")",
":",
"for",
"doc",
"in",
"self",
".",
"text",
"(",
"fileids",
",",
"categories",
")",
":",
"yield",
"doc",
"[",
"'title'",
"]"
] | [
260,
4
] | [
266,
30
] | python | en | ['en', 'error', 'th'] | False |
HTMLPickledCorpusReader.paras | (self, fileids=None, categories=None) |
Returns a generator of paragraphs where each paragraph is a list of
sentences, which is in turn a list of (token, tag) tuples.
|
Returns a generator of paragraphs where each paragraph is a list of
sentences, which is in turn a list of (token, tag) tuples.
| def paras(self, fileids=None, categories=None):
"""
Returns a generator of paragraphs where each paragraph is a list of
sentences, which is in turn a list of (token, tag) tuples.
"""
for doc in self.docs(fileids, categories):
for paragraph in doc:
yield paragraph | [
"def",
"paras",
"(",
"self",
",",
"fileids",
"=",
"None",
",",
"categories",
"=",
"None",
")",
":",
"for",
"doc",
"in",
"self",
".",
"docs",
"(",
"fileids",
",",
"categories",
")",
":",
"for",
"paragraph",
"in",
"doc",
":",
"yield",
"paragraph"
] | [
268,
4
] | [
275,
31
] | python | en | ['en', 'error', 'th'] | False |
HTMLPickledCorpusReader.sents | (self, fileids=None, categories=None) |
Returns a generator of sentences where each sentence is a list of
(token, tag) tuples.
|
Returns a generator of sentences where each sentence is a list of
(token, tag) tuples.
| def sents(self, fileids=None, categories=None):
"""
Returns a generator of sentences where each sentence is a list of
(token, tag) tuples.
"""
for paragraph in self.paras(fileids, categories):
for sentence in paragraph:
yield sentence | [
"def",
"sents",
"(",
"self",
",",
"fileids",
"=",
"None",
",",
"categories",
"=",
"None",
")",
":",
"for",
"paragraph",
"in",
"self",
".",
"paras",
"(",
"fileids",
",",
"categories",
")",
":",
"for",
"sentence",
"in",
"paragraph",
":",
"yield",
"senten... | [
277,
4
] | [
284,
30
] | python | en | ['en', 'error', 'th'] | False |
HTMLPickledCorpusReader.words | (self, fileids=None, categories=None) |
Returns a generator of (token, tag) tuples.
|
Returns a generator of (token, tag) tuples.
| def words(self, fileids=None, categories=None):
"""
Returns a generator of (token, tag) tuples.
"""
for token in self.tagged(fileids, categories):
yield token[0] | [
"def",
"words",
"(",
"self",
",",
"fileids",
"=",
"None",
",",
"categories",
"=",
"None",
")",
":",
"for",
"token",
"in",
"self",
".",
"tagged",
"(",
"fileids",
",",
"categories",
")",
":",
"yield",
"token",
"[",
"0",
"]"
] | [
291,
4
] | [
296,
26
] | python | en | ['en', 'error', 'th'] | False |
calls | (hass) | Track calls to a mock service. | Track calls to a mock service. | def calls(hass):
"""Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") | [
"def",
"calls",
"(",
"hass",
")",
":",
"return",
"async_mock_service",
"(",
"hass",
",",
"\"test\"",
",",
"\"automation\"",
")"
] | [
25,
0
] | [
27,
57
] | python | en | ['en', 'en', 'en'] | True |
setup_comp | (hass) | Initialize components. | Initialize components. | def setup_comp(hass):
"""Initialize components."""
mock_component(hass, "group")
dt_util.set_default_time_zone(hass.config.time_zone)
hass.loop.run_until_complete(
async_setup_component(hass, sun.DOMAIN, {sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
) | [
"def",
"setup_comp",
"(",
"hass",
")",
":",
"mock_component",
"(",
"hass",
",",
"\"group\"",
")",
"dt_util",
".",
"set_default_time_zone",
"(",
"hass",
".",
"config",
".",
"time_zone",
")",
"hass",
".",
"loop",
".",
"run_until_complete",
"(",
"async_setup_comp... | [
31,
0
] | [
37,
5
] | python | en | ['de', 'en', 'en'] | False |
test_sunset_trigger | (hass, calls, legacy_patchable_time) | Test the sunset trigger. | Test the sunset trigger. | async def test_sunset_trigger(hass, calls, legacy_patchable_time):
"""Test the sunset trigger."""
now = datetime(2015, 9, 15, 23, tzinfo=dt_util.UTC)
trigger_time = datetime(2015, 9, 16, 2, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {"platform": "sun", "event": SUN_EVENT_SUNSET},
"action": {"service": "test.automation"},
}
},
)
await hass.services.async_call(
automation.DOMAIN,
SERVICE_TURN_OFF,
{ATTR_ENTITY_ID: ENTITY_MATCH_ALL},
blocking=True,
)
async_fire_time_changed(hass, trigger_time)
await hass.async_block_till_done()
assert len(calls) == 0
with patch("homeassistant.util.dt.utcnow", return_value=now):
await hass.services.async_call(
automation.DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: ENTITY_MATCH_ALL},
blocking=True,
)
async_fire_time_changed(hass, trigger_time)
await hass.async_block_till_done()
assert len(calls) == 1 | [
"async",
"def",
"test_sunset_trigger",
"(",
"hass",
",",
"calls",
",",
"legacy_patchable_time",
")",
":",
"now",
"=",
"datetime",
"(",
"2015",
",",
"9",
",",
"15",
",",
"23",
",",
"tzinfo",
"=",
"dt_util",
".",
"UTC",
")",
"trigger_time",
"=",
"datetime"... | [
45,
0
] | [
83,
26
] | python | en | ['en', 'en', 'en'] | True |
test_sunrise_trigger | (hass, calls, legacy_patchable_time) | Test the sunrise trigger. | Test the sunrise trigger. | async def test_sunrise_trigger(hass, calls, legacy_patchable_time):
"""Test the sunrise trigger."""
now = datetime(2015, 9, 13, 23, tzinfo=dt_util.UTC)
trigger_time = datetime(2015, 9, 16, 14, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {"platform": "sun", "event": SUN_EVENT_SUNRISE},
"action": {"service": "test.automation"},
}
},
)
async_fire_time_changed(hass, trigger_time)
await hass.async_block_till_done()
assert len(calls) == 1 | [
"async",
"def",
"test_sunrise_trigger",
"(",
"hass",
",",
"calls",
",",
"legacy_patchable_time",
")",
":",
"now",
"=",
"datetime",
"(",
"2015",
",",
"9",
",",
"13",
",",
"23",
",",
"tzinfo",
"=",
"dt_util",
".",
"UTC",
")",
"trigger_time",
"=",
"datetime... | [
86,
0
] | [
105,
26
] | python | en | ['en', 'no', 'en'] | True |
test_sunset_trigger_with_offset | (hass, calls, legacy_patchable_time) | Test the sunset trigger with offset. | Test the sunset trigger with offset. | async def test_sunset_trigger_with_offset(hass, calls, legacy_patchable_time):
"""Test the sunset trigger with offset."""
now = datetime(2015, 9, 15, 23, tzinfo=dt_util.UTC)
trigger_time = datetime(2015, 9, 16, 2, 30, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "sun",
"event": SUN_EVENT_SUNSET,
"offset": "0:30:00",
},
"action": {
"service": "test.automation",
"data_template": {
"some": "{{ trigger.%s }}"
% "}} - {{ trigger.".join(("platform", "event", "offset"))
},
},
}
},
)
async_fire_time_changed(hass, trigger_time)
await hass.async_block_till_done()
assert len(calls) == 1
assert calls[0].data["some"] == "sun - sunset - 0:30:00" | [
"async",
"def",
"test_sunset_trigger_with_offset",
"(",
"hass",
",",
"calls",
",",
"legacy_patchable_time",
")",
":",
"now",
"=",
"datetime",
"(",
"2015",
",",
"9",
",",
"15",
",",
"23",
",",
"tzinfo",
"=",
"dt_util",
".",
"UTC",
")",
"trigger_time",
"=",
... | [
108,
0
] | [
138,
60
] | python | en | ['en', 'en', 'en'] | True |
test_sunrise_trigger_with_offset | (hass, calls, legacy_patchable_time) | Test the sunrise trigger with offset. | Test the sunrise trigger with offset. | async def test_sunrise_trigger_with_offset(hass, calls, legacy_patchable_time):
"""Test the sunrise trigger with offset."""
now = datetime(2015, 9, 13, 23, tzinfo=dt_util.UTC)
trigger_time = datetime(2015, 9, 16, 13, 30, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "sun",
"event": SUN_EVENT_SUNRISE,
"offset": "-0:30:00",
},
"action": {"service": "test.automation"},
}
},
)
async_fire_time_changed(hass, trigger_time)
await hass.async_block_till_done()
assert len(calls) == 1 | [
"async",
"def",
"test_sunrise_trigger_with_offset",
"(",
"hass",
",",
"calls",
",",
"legacy_patchable_time",
")",
":",
"now",
"=",
"datetime",
"(",
"2015",
",",
"9",
",",
"13",
",",
"23",
",",
"tzinfo",
"=",
"dt_util",
".",
"UTC",
")",
"trigger_time",
"=",... | [
141,
0
] | [
164,
26
] | python | en | ['en', 'en', 'en'] | True |
test_if_action_before_sunrise_no_offset | (hass, calls) |
Test if action was before sunrise.
Before sunrise is true from midnight until sunset, local time.
|
Test if action was before sunrise. | async def test_if_action_before_sunrise_no_offset(hass, calls):
"""
Test if action was before sunrise.
Before sunrise is true from midnight until sunset, local time.
"""
await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {"platform": "event", "event_type": "test_event"},
"condition": {"condition": "sun", "before": SUN_EVENT_SUNRISE},
"action": {"service": "test.automation"},
}
},
)
# sunrise: 2015-09-16 06:32:43 local, sunset: 2015-09-16 18:55:24 local
# sunrise: 2015-09-16 13:32:43 UTC, sunset: 2015-09-17 01:55:24 UTC
# now = sunrise + 1s -> 'before sunrise' not true
now = datetime(2015, 9, 16, 13, 32, 44, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 0
# now = sunrise -> 'before sunrise' true
now = datetime(2015, 9, 16, 13, 32, 43, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
# now = local midnight -> 'before sunrise' true
now = datetime(2015, 9, 16, 7, 0, 0, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 2
# now = local midnight - 1s -> 'before sunrise' not true
now = datetime(2015, 9, 17, 6, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 2 | [
"async",
"def",
"test_if_action_before_sunrise_no_offset",
"(",
"hass",
",",
"calls",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform... | [
167,
0
] | [
213,
30
] | python | en | ['en', 'error', 'th'] | False |
test_if_action_after_sunrise_no_offset | (hass, calls) |
Test if action was after sunrise.
After sunrise is true from sunrise until midnight, local time.
|
Test if action was after sunrise. | async def test_if_action_after_sunrise_no_offset(hass, calls):
"""
Test if action was after sunrise.
After sunrise is true from sunrise until midnight, local time.
"""
await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {"platform": "event", "event_type": "test_event"},
"condition": {"condition": "sun", "after": SUN_EVENT_SUNRISE},
"action": {"service": "test.automation"},
}
},
)
# sunrise: 2015-09-16 06:32:43 local, sunset: 2015-09-16 18:55:24 local
# sunrise: 2015-09-16 13:32:43 UTC, sunset: 2015-09-17 01:55:24 UTC
# now = sunrise - 1s -> 'after sunrise' not true
now = datetime(2015, 9, 16, 13, 32, 42, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 0
# now = sunrise + 1s -> 'after sunrise' true
now = datetime(2015, 9, 16, 13, 32, 43, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
# now = local midnight -> 'after sunrise' not true
now = datetime(2015, 9, 16, 7, 0, 0, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
# now = local midnight - 1s -> 'after sunrise' true
now = datetime(2015, 9, 17, 6, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 2 | [
"async",
"def",
"test_if_action_after_sunrise_no_offset",
"(",
"hass",
",",
"calls",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\... | [
216,
0
] | [
262,
30
] | python | en | ['en', 'error', 'th'] | False |
test_if_action_before_sunrise_with_offset | (hass, calls) |
Test if action was before sunrise with offset.
Before sunrise is true from midnight until sunset, local time.
|
Test if action was before sunrise with offset. | async def test_if_action_before_sunrise_with_offset(hass, calls):
"""
Test if action was before sunrise with offset.
Before sunrise is true from midnight until sunset, local time.
"""
await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {"platform": "event", "event_type": "test_event"},
"condition": {
"condition": "sun",
"before": SUN_EVENT_SUNRISE,
"before_offset": "+1:00:00",
},
"action": {"service": "test.automation"},
}
},
)
# sunrise: 2015-09-16 06:32:43 local, sunset: 2015-09-16 18:55:24 local
# sunrise: 2015-09-16 13:32:43 UTC, sunset: 2015-09-17 01:55:24 UTC
# now = sunrise + 1s + 1h -> 'before sunrise' with offset +1h not true
now = datetime(2015, 9, 16, 14, 32, 44, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 0
# now = sunrise + 1h -> 'before sunrise' with offset +1h true
now = datetime(2015, 9, 16, 14, 32, 43, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
# now = UTC midnight -> 'before sunrise' with offset +1h not true
now = datetime(2015, 9, 17, 0, 0, 0, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
# now = UTC midnight - 1s -> 'before sunrise' with offset +1h not true
now = datetime(2015, 9, 16, 23, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
# now = local midnight -> 'before sunrise' with offset +1h true
now = datetime(2015, 9, 16, 7, 0, 0, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 2
# now = local midnight - 1s -> 'before sunrise' with offset +1h not true
now = datetime(2015, 9, 17, 6, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 2
# now = sunset -> 'before sunrise' with offset +1h not true
now = datetime(2015, 9, 17, 1, 56, 48, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 2
# now = sunset -1s -> 'before sunrise' with offset +1h not true
now = datetime(2015, 9, 17, 1, 56, 45, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 2 | [
"async",
"def",
"test_if_action_before_sunrise_with_offset",
"(",
"hass",
",",
"calls",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platfo... | [
265,
0
] | [
343,
30
] | python | en | ['en', 'error', 'th'] | False |
test_if_action_before_sunset_with_offset | (hass, calls) |
Test if action was before sunset with offset.
Before sunset is true from midnight until sunset, local time.
|
Test if action was before sunset with offset. | async def test_if_action_before_sunset_with_offset(hass, calls):
"""
Test if action was before sunset with offset.
Before sunset is true from midnight until sunset, local time.
"""
await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {"platform": "event", "event_type": "test_event"},
"condition": {
"condition": "sun",
"before": "sunset",
"before_offset": "+1:00:00",
},
"action": {"service": "test.automation"},
}
},
)
# sunrise: 2015-09-16 06:32:43 local, sunset: 2015-09-16 18:55:24 local
# sunrise: 2015-09-16 13:32:43 UTC, sunset: 2015-09-17 01:55:24 UTC
# now = local midnight -> 'before sunset' with offset +1h true
now = datetime(2015, 9, 16, 7, 0, 0, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
# now = sunset + 1s + 1h -> 'before sunset' with offset +1h not true
now = datetime(2015, 9, 17, 2, 55, 25, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
# now = sunset + 1h -> 'before sunset' with offset +1h true
now = datetime(2015, 9, 17, 2, 55, 24, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 2
# now = UTC midnight -> 'before sunset' with offset +1h true
now = datetime(2015, 9, 17, 0, 0, 0, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 3
# now = UTC midnight - 1s -> 'before sunset' with offset +1h true
now = datetime(2015, 9, 16, 23, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 4
# now = sunrise -> 'before sunset' with offset +1h true
now = datetime(2015, 9, 16, 13, 32, 43, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 5
# now = sunrise -1s -> 'before sunset' with offset +1h true
now = datetime(2015, 9, 16, 13, 32, 42, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 6
# now = local midnight-1s -> 'after sunrise' with offset +1h not true
now = datetime(2015, 9, 17, 6, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 6 | [
"async",
"def",
"test_if_action_before_sunset_with_offset",
"(",
"hass",
",",
"calls",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platfor... | [
346,
0
] | [
424,
30
] | python | en | ['en', 'error', 'th'] | False |
test_if_action_after_sunrise_with_offset | (hass, calls) |
Test if action was after sunrise with offset.
After sunrise is true from sunrise until midnight, local time.
|
Test if action was after sunrise with offset. | async def test_if_action_after_sunrise_with_offset(hass, calls):
"""
Test if action was after sunrise with offset.
After sunrise is true from sunrise until midnight, local time.
"""
await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {"platform": "event", "event_type": "test_event"},
"condition": {
"condition": "sun",
"after": SUN_EVENT_SUNRISE,
"after_offset": "+1:00:00",
},
"action": {"service": "test.automation"},
}
},
)
# sunrise: 2015-09-16 06:32:43 local, sunset: 2015-09-16 18:55:24 local
# sunrise: 2015-09-16 13:32:43 UTC, sunset: 2015-09-17 01:55:24 UTC
# now = sunrise - 1s + 1h -> 'after sunrise' with offset +1h not true
now = datetime(2015, 9, 16, 14, 32, 42, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 0
# now = sunrise + 1h -> 'after sunrise' with offset +1h true
now = datetime(2015, 9, 16, 14, 32, 43, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
# now = UTC noon -> 'after sunrise' with offset +1h not true
now = datetime(2015, 9, 16, 12, 0, 0, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
# now = UTC noon - 1s -> 'after sunrise' with offset +1h not true
now = datetime(2015, 9, 16, 11, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
# now = local noon -> 'after sunrise' with offset +1h true
now = datetime(2015, 9, 16, 19, 1, 0, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 2
# now = local noon - 1s -> 'after sunrise' with offset +1h true
now = datetime(2015, 9, 16, 18, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 3
# now = sunset -> 'after sunrise' with offset +1h true
now = datetime(2015, 9, 17, 1, 55, 24, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 4
# now = sunset + 1s -> 'after sunrise' with offset +1h true
now = datetime(2015, 9, 17, 1, 55, 25, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 5
# now = local midnight-1s -> 'after sunrise' with offset +1h true
now = datetime(2015, 9, 17, 6, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 6
# now = local midnight -> 'after sunrise' with offset +1h not true
now = datetime(2015, 9, 17, 7, 0, 0, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 6 | [
"async",
"def",
"test_if_action_after_sunrise_with_offset",
"(",
"hass",
",",
"calls",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platfor... | [
427,
0
] | [
519,
30
] | python | en | ['en', 'error', 'th'] | False |
test_if_action_after_sunset_with_offset | (hass, calls) |
Test if action was after sunset with offset.
After sunset is true from sunset until midnight, local time.
|
Test if action was after sunset with offset. | async def test_if_action_after_sunset_with_offset(hass, calls):
"""
Test if action was after sunset with offset.
After sunset is true from sunset until midnight, local time.
"""
await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {"platform": "event", "event_type": "test_event"},
"condition": {
"condition": "sun",
"after": "sunset",
"after_offset": "+1:00:00",
},
"action": {"service": "test.automation"},
}
},
)
# sunrise: 2015-09-15 06:32:05 local, sunset: 2015-09-15 18:56:46 local
# sunrise: 2015-09-15 13:32:05 UTC, sunset: 2015-09-16 01:56:46 UTC
# now = sunset - 1s + 1h -> 'after sunset' with offset +1h not true
now = datetime(2015, 9, 16, 2, 56, 45, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 0
# now = sunset + 1h -> 'after sunset' with offset +1h true
now = datetime(2015, 9, 16, 2, 56, 46, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
# now = midnight-1s -> 'after sunset' with offset +1h true
now = datetime(2015, 9, 16, 6, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 2
# now = midnight -> 'after sunset' with offset +1h not true
now = datetime(2015, 9, 16, 7, 0, 0, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 2 | [
"async",
"def",
"test_if_action_after_sunset_with_offset",
"(",
"hass",
",",
"calls",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform... | [
522,
0
] | [
572,
30
] | python | en | ['en', 'error', 'th'] | False |
test_if_action_before_and_after_during | (hass, calls) |
Test if action was after sunset and before sunrise.
This is true from sunrise until sunset.
|
Test if action was after sunset and before sunrise. | async def test_if_action_before_and_after_during(hass, calls):
"""
Test if action was after sunset and before sunrise.
This is true from sunrise until sunset.
"""
await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {"platform": "event", "event_type": "test_event"},
"condition": {
"condition": "sun",
"after": SUN_EVENT_SUNRISE,
"before": SUN_EVENT_SUNSET,
},
"action": {"service": "test.automation"},
}
},
)
# sunrise: 2015-09-16 06:32:43 local, sunset: 2015-09-16 18:55:24 local
# sunrise: 2015-09-16 13:32:43 UTC, sunset: 2015-09-17 01:55:24 UTC
# now = sunrise - 1s -> 'after sunrise' + 'before sunset' not true
now = datetime(2015, 9, 16, 13, 32, 42, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 0
# now = sunset + 1s -> 'after sunrise' + 'before sunset' not true
now = datetime(2015, 9, 17, 1, 55, 25, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 0
# now = sunrise -> 'after sunrise' + 'before sunset' true
now = datetime(2015, 9, 16, 13, 32, 43, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
# now = sunset -> 'after sunrise' + 'before sunset' true
now = datetime(2015, 9, 17, 1, 55, 24, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 2
# now = 9AM local -> 'after sunrise' + 'before sunset' true
now = datetime(2015, 9, 16, 16, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 3 | [
"async",
"def",
"test_if_action_before_and_after_during",
"(",
"hass",
",",
"calls",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\... | [
575,
0
] | [
632,
30
] | python | en | ['en', 'error', 'th'] | False |
test_if_action_before_sunrise_no_offset_kotzebue | (hass, calls) |
Test if action was before sunrise.
Local timezone: Alaska time
Location: Kotzebue, which has a very skewed local timezone with sunrise
at 7 AM and sunset at 3AM during summer
After sunrise is true from sunrise until midnight, local time.
|
Test if action was before sunrise. | async def test_if_action_before_sunrise_no_offset_kotzebue(hass, calls):
"""
Test if action was before sunrise.
Local timezone: Alaska time
Location: Kotzebue, which has a very skewed local timezone with sunrise
at 7 AM and sunset at 3AM during summer
After sunrise is true from sunrise until midnight, local time.
"""
tz = dt_util.get_time_zone("America/Anchorage")
dt_util.set_default_time_zone(tz)
hass.config.latitude = 66.5
hass.config.longitude = 162.4
await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {"platform": "event", "event_type": "test_event"},
"condition": {"condition": "sun", "before": SUN_EVENT_SUNRISE},
"action": {"service": "test.automation"},
}
},
)
# sunrise: 2015-07-24 07:17:24 local, sunset: 2015-07-25 03:16:27 local
# sunrise: 2015-07-24 15:17:24 UTC, sunset: 2015-07-25 11:16:27 UTC
# now = sunrise + 1s -> 'before sunrise' not true
now = datetime(2015, 7, 24, 15, 17, 25, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 0
# now = sunrise -> 'before sunrise' true
now = datetime(2015, 7, 24, 15, 17, 24, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
# now = local midnight -> 'before sunrise' true
now = datetime(2015, 7, 24, 8, 0, 0, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 2
# now = local midnight - 1s -> 'before sunrise' not true
now = datetime(2015, 7, 24, 7, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 2 | [
"async",
"def",
"test_if_action_before_sunrise_no_offset_kotzebue",
"(",
"hass",
",",
"calls",
")",
":",
"tz",
"=",
"dt_util",
".",
"get_time_zone",
"(",
"\"America/Anchorage\"",
")",
"dt_util",
".",
"set_default_time_zone",
"(",
"tz",
")",
"hass",
".",
"config",
... | [
635,
0
] | [
688,
30
] | python | en | ['en', 'error', 'th'] | False |
test_if_action_after_sunrise_no_offset_kotzebue | (hass, calls) |
Test if action was after sunrise.
Local timezone: Alaska time
Location: Kotzebue, which has a very skewed local timezone with sunrise
at 7 AM and sunset at 3AM during summer
Before sunrise is true from midnight until sunrise, local time.
|
Test if action was after sunrise. | async def test_if_action_after_sunrise_no_offset_kotzebue(hass, calls):
"""
Test if action was after sunrise.
Local timezone: Alaska time
Location: Kotzebue, which has a very skewed local timezone with sunrise
at 7 AM and sunset at 3AM during summer
Before sunrise is true from midnight until sunrise, local time.
"""
tz = dt_util.get_time_zone("America/Anchorage")
dt_util.set_default_time_zone(tz)
hass.config.latitude = 66.5
hass.config.longitude = 162.4
await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {"platform": "event", "event_type": "test_event"},
"condition": {"condition": "sun", "after": SUN_EVENT_SUNRISE},
"action": {"service": "test.automation"},
}
},
)
# sunrise: 2015-07-24 07:17:24 local, sunset: 2015-07-25 03:16:27 local
# sunrise: 2015-07-24 15:17:24 UTC, sunset: 2015-07-25 11:16:27 UTC
# now = sunrise -> 'after sunrise' true
now = datetime(2015, 7, 24, 15, 17, 24, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
# now = sunrise - 1s -> 'after sunrise' not true
now = datetime(2015, 7, 24, 15, 17, 23, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
# now = local midnight -> 'after sunrise' not true
now = datetime(2015, 7, 24, 8, 0, 1, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
# now = local midnight - 1s -> 'after sunrise' true
now = datetime(2015, 7, 24, 7, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 2 | [
"async",
"def",
"test_if_action_after_sunrise_no_offset_kotzebue",
"(",
"hass",
",",
"calls",
")",
":",
"tz",
"=",
"dt_util",
".",
"get_time_zone",
"(",
"\"America/Anchorage\"",
")",
"dt_util",
".",
"set_default_time_zone",
"(",
"tz",
")",
"hass",
".",
"config",
"... | [
691,
0
] | [
744,
30
] | python | en | ['en', 'error', 'th'] | False |
test_if_action_before_sunset_no_offset_kotzebue | (hass, calls) |
Test if action was before sunrise.
Local timezone: Alaska time
Location: Kotzebue, which has a very skewed local timezone with sunrise
at 7 AM and sunset at 3AM during summer
Before sunset is true from midnight until sunset, local time.
|
Test if action was before sunrise. | async def test_if_action_before_sunset_no_offset_kotzebue(hass, calls):
"""
Test if action was before sunrise.
Local timezone: Alaska time
Location: Kotzebue, which has a very skewed local timezone with sunrise
at 7 AM and sunset at 3AM during summer
Before sunset is true from midnight until sunset, local time.
"""
tz = dt_util.get_time_zone("America/Anchorage")
dt_util.set_default_time_zone(tz)
hass.config.latitude = 66.5
hass.config.longitude = 162.4
await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {"platform": "event", "event_type": "test_event"},
"condition": {"condition": "sun", "before": SUN_EVENT_SUNSET},
"action": {"service": "test.automation"},
}
},
)
# sunrise: 2015-07-24 07:17:24 local, sunset: 2015-07-25 03:16:27 local
# sunrise: 2015-07-24 15:17:24 UTC, sunset: 2015-07-25 11:16:27 UTC
# now = sunrise + 1s -> 'before sunrise' not true
now = datetime(2015, 7, 25, 11, 16, 28, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 0
# now = sunrise -> 'before sunrise' true
now = datetime(2015, 7, 25, 11, 16, 27, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
# now = local midnight -> 'before sunrise' true
now = datetime(2015, 7, 24, 8, 0, 0, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 2
# now = local midnight - 1s -> 'before sunrise' not true
now = datetime(2015, 7, 24, 7, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 2 | [
"async",
"def",
"test_if_action_before_sunset_no_offset_kotzebue",
"(",
"hass",
",",
"calls",
")",
":",
"tz",
"=",
"dt_util",
".",
"get_time_zone",
"(",
"\"America/Anchorage\"",
")",
"dt_util",
".",
"set_default_time_zone",
"(",
"tz",
")",
"hass",
".",
"config",
"... | [
747,
0
] | [
800,
30
] | python | en | ['en', 'error', 'th'] | False |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.