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
sequence | start_point
sequence | end_point
sequence | language
stringclasses 1
value | docstring_language
stringlengths 2
7
| docstring_language_predictions
stringlengths 18
23
| is_langid_reliable
stringclasses 2
values |
---|---|---|---|---|---|---|---|---|---|---|---|
async_unload_entry | (hass: HomeAssistantType, entry: ConfigEntry) | Unload a config entry. | Unload a config entry. | async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry):
"""Unload a config entry."""
if hass.data[DOMAIN][entry.entry_id][COORDINATOR_ALERT]:
department = hass.data[DOMAIN][entry.entry_id][
COORDINATOR_FORECAST
].data.position.get("dept")
hass.data[DOMAIN][department] = False
_LOGGER.debug(
"Weather alert for depatment %s unloaded and released. It can be added now by another city.",
department,
)
unload_ok = all(
await asyncio.gather(
*[
hass.config_entries.async_forward_entry_unload(entry, platform)
for platform in PLATFORMS
]
)
)
if unload_ok:
hass.data[DOMAIN][entry.entry_id][UNDO_UPDATE_LISTENER]()
hass.data[DOMAIN].pop(entry.entry_id)
if not hass.data[DOMAIN]:
hass.data.pop(DOMAIN)
return unload_ok | [
"async",
"def",
"async_unload_entry",
"(",
"hass",
":",
"HomeAssistantType",
",",
"entry",
":",
"ConfigEntry",
")",
":",
"if",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"[",
"COORDINATOR_ALERT",
"]",
":",
"department",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"[",
"COORDINATOR_FORECAST",
"]",
".",
"data",
".",
"position",
".",
"get",
"(",
"\"dept\"",
")",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"department",
"]",
"=",
"False",
"_LOGGER",
".",
"debug",
"(",
"\"Weather alert for depatment %s unloaded and released. It can be added now by another city.\"",
",",
"department",
",",
")",
"unload_ok",
"=",
"all",
"(",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"[",
"hass",
".",
"config_entries",
".",
"async_forward_entry_unload",
"(",
"entry",
",",
"platform",
")",
"for",
"platform",
"in",
"PLATFORMS",
"]",
")",
")",
"if",
"unload_ok",
":",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"[",
"UNDO_UPDATE_LISTENER",
"]",
"(",
")",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
".",
"pop",
"(",
"entry",
".",
"entry_id",
")",
"if",
"not",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
":",
"hass",
".",
"data",
".",
"pop",
"(",
"DOMAIN",
")",
"return",
"unload_ok"
] | [
182,
0
] | [
209,
20
] | python | en | ['en', 'es', 'en'] | True |
_async_update_listener | (hass: HomeAssistantType, entry: ConfigEntry) | Handle options update. | Handle options update. | async def _async_update_listener(hass: HomeAssistantType, entry: ConfigEntry):
"""Handle options update."""
await hass.config_entries.async_reload(entry.entry_id) | [
"async",
"def",
"_async_update_listener",
"(",
"hass",
":",
"HomeAssistantType",
",",
"entry",
":",
"ConfigEntry",
")",
":",
"await",
"hass",
".",
"config_entries",
".",
"async_reload",
"(",
"entry",
".",
"entry_id",
")"
] | [
212,
0
] | [
214,
58
] | python | en | ['en', 'nl', 'en'] | True |
test_show_form | (hass) | Test that the form is served with no input. | Test that the form is served with no input. | async def test_show_form(hass):
"""Test that the form is served with no input."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == SOURCE_USER | [
"async",
"def",
"test_show_form",
"(",
"hass",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_USER",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"SOURCE_USER"
] | [
16,
0
] | [
23,
43
] | python | en | ['en', 'en', 'en'] | True |
test_create_entry_with_hostname | (hass) | Test that the user step works with printer hostname. | Test that the user step works with printer hostname. | async def test_create_entry_with_hostname(hass):
"""Test that the user step works with printer hostname."""
with patch(
"brother.Brother._get_data",
return_value=json.loads(load_fixture("brother_printer_data.json")),
):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=CONFIG
)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == "HL-L2340DW 0123456789"
assert result["data"][CONF_HOST] == CONFIG[CONF_HOST]
assert result["data"][CONF_TYPE] == CONFIG[CONF_TYPE] | [
"async",
"def",
"test_create_entry_with_hostname",
"(",
"hass",
")",
":",
"with",
"patch",
"(",
"\"brother.Brother._get_data\"",
",",
"return_value",
"=",
"json",
".",
"loads",
"(",
"load_fixture",
"(",
"\"brother_printer_data.json\"",
")",
")",
",",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_USER",
"}",
",",
"data",
"=",
"CONFIG",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"result",
"[",
"\"title\"",
"]",
"==",
"\"HL-L2340DW 0123456789\"",
"assert",
"result",
"[",
"\"data\"",
"]",
"[",
"CONF_HOST",
"]",
"==",
"CONFIG",
"[",
"CONF_HOST",
"]",
"assert",
"result",
"[",
"\"data\"",
"]",
"[",
"CONF_TYPE",
"]",
"==",
"CONFIG",
"[",
"CONF_TYPE",
"]"
] | [
26,
0
] | [
39,
61
] | python | en | ['en', 'en', 'en'] | True |
test_create_entry_with_ip_address | (hass) | Test that the user step works with printer IP address. | Test that the user step works with printer IP address. | async def test_create_entry_with_ip_address(hass):
"""Test that the user step works with printer IP address."""
with patch(
"brother.Brother._get_data",
return_value=json.loads(load_fixture("brother_printer_data.json")),
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_USER},
data={CONF_HOST: "127.0.0.1", CONF_TYPE: "laser"},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == "HL-L2340DW 0123456789"
assert result["data"][CONF_HOST] == "127.0.0.1"
assert result["data"][CONF_TYPE] == "laser" | [
"async",
"def",
"test_create_entry_with_ip_address",
"(",
"hass",
")",
":",
"with",
"patch",
"(",
"\"brother.Brother._get_data\"",
",",
"return_value",
"=",
"json",
".",
"loads",
"(",
"load_fixture",
"(",
"\"brother_printer_data.json\"",
")",
")",
",",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_USER",
"}",
",",
"data",
"=",
"{",
"CONF_HOST",
":",
"\"127.0.0.1\"",
",",
"CONF_TYPE",
":",
"\"laser\"",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"result",
"[",
"\"title\"",
"]",
"==",
"\"HL-L2340DW 0123456789\"",
"assert",
"result",
"[",
"\"data\"",
"]",
"[",
"CONF_HOST",
"]",
"==",
"\"127.0.0.1\"",
"assert",
"result",
"[",
"\"data\"",
"]",
"[",
"CONF_TYPE",
"]",
"==",
"\"laser\""
] | [
42,
0
] | [
57,
51
] | python | en | ['en', 'en', 'en'] | True |
test_invalid_hostname | (hass) | Test invalid hostname in user_input. | Test invalid hostname in user_input. | async def test_invalid_hostname(hass):
"""Test invalid hostname in user_input."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_USER},
data={CONF_HOST: "invalid/hostname", CONF_TYPE: "laser"},
)
assert result["errors"] == {CONF_HOST: "wrong_host"} | [
"async",
"def",
"test_invalid_hostname",
"(",
"hass",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_USER",
"}",
",",
"data",
"=",
"{",
"CONF_HOST",
":",
"\"invalid/hostname\"",
",",
"CONF_TYPE",
":",
"\"laser\"",
"}",
",",
")",
"assert",
"result",
"[",
"\"errors\"",
"]",
"==",
"{",
"CONF_HOST",
":",
"\"wrong_host\"",
"}"
] | [
60,
0
] | [
68,
56
] | python | en | ['en', 'sl', 'en'] | True |
test_connection_error | (hass) | Test connection to host error. | Test connection to host error. | async def test_connection_error(hass):
"""Test connection to host error."""
with patch("brother.Brother._get_data", side_effect=ConnectionError()):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=CONFIG
)
assert result["errors"] == {"base": "cannot_connect"} | [
"async",
"def",
"test_connection_error",
"(",
"hass",
")",
":",
"with",
"patch",
"(",
"\"brother.Brother._get_data\"",
",",
"side_effect",
"=",
"ConnectionError",
"(",
")",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_USER",
"}",
",",
"data",
"=",
"CONFIG",
")",
"assert",
"result",
"[",
"\"errors\"",
"]",
"==",
"{",
"\"base\"",
":",
"\"cannot_connect\"",
"}"
] | [
71,
0
] | [
78,
61
] | python | en | ['en', 'en', 'en'] | True |
test_snmp_error | (hass) | Test SNMP error. | Test SNMP error. | async def test_snmp_error(hass):
"""Test SNMP error."""
with patch("brother.Brother._get_data", side_effect=SnmpError("error")):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=CONFIG
)
assert result["errors"] == {"base": "snmp_error"} | [
"async",
"def",
"test_snmp_error",
"(",
"hass",
")",
":",
"with",
"patch",
"(",
"\"brother.Brother._get_data\"",
",",
"side_effect",
"=",
"SnmpError",
"(",
"\"error\"",
")",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_USER",
"}",
",",
"data",
"=",
"CONFIG",
")",
"assert",
"result",
"[",
"\"errors\"",
"]",
"==",
"{",
"\"base\"",
":",
"\"snmp_error\"",
"}"
] | [
81,
0
] | [
88,
57
] | python | de | ['de', 'de', 'it'] | True |
test_unsupported_model_error | (hass) | Test unsupported printer model error. | Test unsupported printer model error. | async def test_unsupported_model_error(hass):
"""Test unsupported printer model error."""
with patch("brother.Brother._get_data", side_effect=UnsupportedModel("error")):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=CONFIG
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "unsupported_model" | [
"async",
"def",
"test_unsupported_model_error",
"(",
"hass",
")",
":",
"with",
"patch",
"(",
"\"brother.Brother._get_data\"",
",",
"side_effect",
"=",
"UnsupportedModel",
"(",
"\"error\"",
")",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_USER",
"}",
",",
"data",
"=",
"CONFIG",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_ABORT",
"assert",
"result",
"[",
"\"reason\"",
"]",
"==",
"\"unsupported_model\""
] | [
91,
0
] | [
100,
54
] | python | da | ['da', 'da', 'en'] | True |
test_device_exists_abort | (hass) | Test we abort config flow if Brother printer already configured. | Test we abort config flow if Brother printer already configured. | async def test_device_exists_abort(hass):
"""Test we abort config flow if Brother printer already configured."""
with patch(
"brother.Brother._get_data",
return_value=json.loads(load_fixture("brother_printer_data.json")),
):
MockConfigEntry(domain=DOMAIN, unique_id="0123456789", data=CONFIG).add_to_hass(
hass
)
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=CONFIG
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "already_configured" | [
"async",
"def",
"test_device_exists_abort",
"(",
"hass",
")",
":",
"with",
"patch",
"(",
"\"brother.Brother._get_data\"",
",",
"return_value",
"=",
"json",
".",
"loads",
"(",
"load_fixture",
"(",
"\"brother_printer_data.json\"",
")",
")",
",",
")",
":",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"unique_id",
"=",
"\"0123456789\"",
",",
"data",
"=",
"CONFIG",
")",
".",
"add_to_hass",
"(",
"hass",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_USER",
"}",
",",
"data",
"=",
"CONFIG",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_ABORT",
"assert",
"result",
"[",
"\"reason\"",
"]",
"==",
"\"already_configured\""
] | [
103,
0
] | [
117,
55
] | python | en | ['en', 'en', 'en'] | True |
test_zeroconf_no_data | (hass) | Test we abort if zeroconf provides no data. | Test we abort if zeroconf provides no data. | async def test_zeroconf_no_data(hass):
"""Test we abort if zeroconf provides no data."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_ZEROCONF}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "cannot_connect" | [
"async",
"def",
"test_zeroconf_no_data",
"(",
"hass",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_ZEROCONF",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_ABORT",
"assert",
"result",
"[",
"\"reason\"",
"]",
"==",
"\"cannot_connect\""
] | [
120,
0
] | [
127,
47
] | python | de | ['pt', 'de', 'en'] | False |
test_zeroconf_not_brother_printer_error | (hass) | Test we abort zeroconf flow if printer isn't Brother. | Test we abort zeroconf flow if printer isn't Brother. | async def test_zeroconf_not_brother_printer_error(hass):
"""Test we abort zeroconf flow if printer isn't Brother."""
with patch(
"brother.Brother._get_data",
return_value=json.loads(load_fixture("brother_printer_data.json")),
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data={"hostname": "example.local.", "name": "Another Printer"},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "not_brother_printer" | [
"async",
"def",
"test_zeroconf_not_brother_printer_error",
"(",
"hass",
")",
":",
"with",
"patch",
"(",
"\"brother.Brother._get_data\"",
",",
"return_value",
"=",
"json",
".",
"loads",
"(",
"load_fixture",
"(",
"\"brother_printer_data.json\"",
")",
")",
",",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_ZEROCONF",
"}",
",",
"data",
"=",
"{",
"\"hostname\"",
":",
"\"example.local.\"",
",",
"\"name\"",
":",
"\"Another Printer\"",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_ABORT",
"assert",
"result",
"[",
"\"reason\"",
"]",
"==",
"\"not_brother_printer\""
] | [
130,
0
] | [
144,
56
] | python | en | ['en', 'nl', 'en'] | True |
test_zeroconf_snmp_error | (hass) | Test we abort zeroconf flow on SNMP error. | Test we abort zeroconf flow on SNMP error. | async def test_zeroconf_snmp_error(hass):
"""Test we abort zeroconf flow on SNMP error."""
with patch("brother.Brother._get_data", side_effect=SnmpError("error")):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data={"hostname": "example.local.", "name": "Brother Printer"},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "cannot_connect" | [
"async",
"def",
"test_zeroconf_snmp_error",
"(",
"hass",
")",
":",
"with",
"patch",
"(",
"\"brother.Brother._get_data\"",
",",
"side_effect",
"=",
"SnmpError",
"(",
"\"error\"",
")",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_ZEROCONF",
"}",
",",
"data",
"=",
"{",
"\"hostname\"",
":",
"\"example.local.\"",
",",
"\"name\"",
":",
"\"Brother Printer\"",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_ABORT",
"assert",
"result",
"[",
"\"reason\"",
"]",
"==",
"\"cannot_connect\""
] | [
147,
0
] | [
158,
51
] | python | en | ['en', 'de', 'en'] | True |
test_zeroconf_device_exists_abort | (hass) | Test we abort zeroconf flow if Brother printer already configured. | Test we abort zeroconf flow if Brother printer already configured. | async def test_zeroconf_device_exists_abort(hass):
"""Test we abort zeroconf flow if Brother printer already configured."""
with patch(
"brother.Brother._get_data",
return_value=json.loads(load_fixture("brother_printer_data.json")),
):
MockConfigEntry(domain=DOMAIN, unique_id="0123456789", data=CONFIG).add_to_hass(
hass
)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data={"hostname": "example.local.", "name": "Brother Printer"},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "already_configured" | [
"async",
"def",
"test_zeroconf_device_exists_abort",
"(",
"hass",
")",
":",
"with",
"patch",
"(",
"\"brother.Brother._get_data\"",
",",
"return_value",
"=",
"json",
".",
"loads",
"(",
"load_fixture",
"(",
"\"brother_printer_data.json\"",
")",
")",
",",
")",
":",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"unique_id",
"=",
"\"0123456789\"",
",",
"data",
"=",
"CONFIG",
")",
".",
"add_to_hass",
"(",
"hass",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_ZEROCONF",
"}",
",",
"data",
"=",
"{",
"\"hostname\"",
":",
"\"example.local.\"",
",",
"\"name\"",
":",
"\"Brother Printer\"",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_ABORT",
"assert",
"result",
"[",
"\"reason\"",
"]",
"==",
"\"already_configured\""
] | [
161,
0
] | [
178,
55
] | python | en | ['en', 'de', 'en'] | True |
test_zeroconf_confirm_create_entry | (hass) | Test zeroconf confirmation and create config entry. | Test zeroconf confirmation and create config entry. | async def test_zeroconf_confirm_create_entry(hass):
"""Test zeroconf confirmation and create config entry."""
with patch(
"brother.Brother._get_data",
return_value=json.loads(load_fixture("brother_printer_data.json")),
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data={"hostname": "example.local.", "name": "Brother Printer"},
)
assert result["step_id"] == "zeroconf_confirm"
assert result["description_placeholders"]["model"] == "HL-L2340DW"
assert result["description_placeholders"]["serial_number"] == "0123456789"
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={CONF_TYPE: "laser"}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == "HL-L2340DW 0123456789"
assert result["data"][CONF_HOST] == "example.local"
assert result["data"][CONF_TYPE] == "laser" | [
"async",
"def",
"test_zeroconf_confirm_create_entry",
"(",
"hass",
")",
":",
"with",
"patch",
"(",
"\"brother.Brother._get_data\"",
",",
"return_value",
"=",
"json",
".",
"loads",
"(",
"load_fixture",
"(",
"\"brother_printer_data.json\"",
")",
")",
",",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_ZEROCONF",
"}",
",",
"data",
"=",
"{",
"\"hostname\"",
":",
"\"example.local.\"",
",",
"\"name\"",
":",
"\"Brother Printer\"",
"}",
",",
")",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"zeroconf_confirm\"",
"assert",
"result",
"[",
"\"description_placeholders\"",
"]",
"[",
"\"model\"",
"]",
"==",
"\"HL-L2340DW\"",
"assert",
"result",
"[",
"\"description_placeholders\"",
"]",
"[",
"\"serial_number\"",
"]",
"==",
"\"0123456789\"",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_FORM",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
"=",
"{",
"CONF_TYPE",
":",
"\"laser\"",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"result",
"[",
"\"title\"",
"]",
"==",
"\"HL-L2340DW 0123456789\"",
"assert",
"result",
"[",
"\"data\"",
"]",
"[",
"CONF_HOST",
"]",
"==",
"\"example.local\"",
"assert",
"result",
"[",
"\"data\"",
"]",
"[",
"CONF_TYPE",
"]",
"==",
"\"laser\""
] | [
181,
0
] | [
206,
51
] | python | en | ['en', 'en', 'en'] | True |
test_flow_ssdp | (hass) | Test working ssdp flow. | Test working ssdp flow. | async def test_flow_ssdp(hass):
"""Test working ssdp flow."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_SSDP},
data=SSDP_DATA,
)
assert result["type"] == "form"
assert result["step_id"] == "init"
assert result["description_placeholders"] == {
CONF_NAME: FRIENDLY_NAME,
CONF_HOST: HOST,
}
flow = _flow_next(hass, result["flow_id"])
assert flow["context"]["unique_id"] == UDN
with _patch_setup():
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={}
)
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
assert result["title"] == FRIENDLY_NAME
assert result["data"] == CONF_DATA | [
"async",
"def",
"test_flow_ssdp",
"(",
"hass",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_SSDP",
"}",
",",
"data",
"=",
"SSDP_DATA",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"form\"",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"init\"",
"assert",
"result",
"[",
"\"description_placeholders\"",
"]",
"==",
"{",
"CONF_NAME",
":",
"FRIENDLY_NAME",
",",
"CONF_HOST",
":",
"HOST",
",",
"}",
"flow",
"=",
"_flow_next",
"(",
"hass",
",",
"result",
"[",
"\"flow_id\"",
"]",
")",
"assert",
"flow",
"[",
"\"context\"",
"]",
"[",
"\"unique_id\"",
"]",
"==",
"UDN",
"with",
"_patch_setup",
"(",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
"=",
"{",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"result",
"[",
"\"title\"",
"]",
"==",
"FRIENDLY_NAME",
"assert",
"result",
"[",
"\"data\"",
"]",
"==",
"CONF_DATA"
] | [
56,
0
] | [
78,
42
] | python | de | ['nl', 'de', 'en'] | False |
test_flow_user | (hass) | Test working user initialized flow. | Test working user initialized flow. | async def test_flow_user(hass):
"""Test working user initialized flow."""
mocked_device = _create_mocked_device()
with _patch_config_flow_device(mocked_device), _patch_setup():
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_USER},
)
assert result["type"] == RESULT_TYPE_FORM
assert result["step_id"] == "user"
assert result["errors"] is None
_flow_next(hass, result["flow_id"])
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={CONF_ENDPOINT: ENDPOINT},
)
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
assert result["title"] == MODEL
assert result["data"] == {
CONF_NAME: MODEL,
CONF_ENDPOINT: ENDPOINT,
}
mocked_device.get_supported_methods.assert_called_once()
mocked_device.get_interface_information.assert_called_once() | [
"async",
"def",
"test_flow_user",
"(",
"hass",
")",
":",
"mocked_device",
"=",
"_create_mocked_device",
"(",
")",
"with",
"_patch_config_flow_device",
"(",
"mocked_device",
")",
",",
"_patch_setup",
"(",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_USER",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"user\"",
"assert",
"result",
"[",
"\"errors\"",
"]",
"is",
"None",
"_flow_next",
"(",
"hass",
",",
"result",
"[",
"\"flow_id\"",
"]",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
"=",
"{",
"CONF_ENDPOINT",
":",
"ENDPOINT",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"result",
"[",
"\"title\"",
"]",
"==",
"MODEL",
"assert",
"result",
"[",
"\"data\"",
"]",
"==",
"{",
"CONF_NAME",
":",
"MODEL",
",",
"CONF_ENDPOINT",
":",
"ENDPOINT",
",",
"}",
"mocked_device",
".",
"get_supported_methods",
".",
"assert_called_once",
"(",
")",
"mocked_device",
".",
"get_interface_information",
".",
"assert_called_once",
"(",
")"
] | [
81,
0
] | [
107,
64
] | python | en | ['en', 'pl', 'en'] | True |
test_flow_import | (hass) | Test working import flow. | Test working import flow. | async def test_flow_import(hass):
"""Test working import flow."""
mocked_device = _create_mocked_device()
with _patch_config_flow_device(mocked_device), _patch_setup():
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data=CONF_DATA
)
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
assert result["title"] == FRIENDLY_NAME
assert result["data"] == CONF_DATA
mocked_device.get_supported_methods.assert_called_once()
mocked_device.get_interface_information.assert_not_called() | [
"async",
"def",
"test_flow_import",
"(",
"hass",
")",
":",
"mocked_device",
"=",
"_create_mocked_device",
"(",
")",
"with",
"_patch_config_flow_device",
"(",
"mocked_device",
")",
",",
"_patch_setup",
"(",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_IMPORT",
"}",
",",
"data",
"=",
"CONF_DATA",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"result",
"[",
"\"title\"",
"]",
"==",
"FRIENDLY_NAME",
"assert",
"result",
"[",
"\"data\"",
"]",
"==",
"CONF_DATA",
"mocked_device",
".",
"get_supported_methods",
".",
"assert_called_once",
"(",
")",
"mocked_device",
".",
"get_interface_information",
".",
"assert_not_called",
"(",
")"
] | [
110,
0
] | [
123,
63
] | python | en | ['nl', 'en', 'en'] | True |
test_flow_import_without_name | (hass) | Test import flow without optional name. | Test import flow without optional name. | async def test_flow_import_without_name(hass):
"""Test import flow without optional name."""
mocked_device = _create_mocked_device()
with _patch_config_flow_device(mocked_device), _patch_setup():
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data={CONF_ENDPOINT: ENDPOINT}
)
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
assert result["title"] == MODEL
assert result["data"] == {CONF_NAME: MODEL, CONF_ENDPOINT: ENDPOINT}
mocked_device.get_supported_methods.assert_called_once()
mocked_device.get_interface_information.assert_called_once() | [
"async",
"def",
"test_flow_import_without_name",
"(",
"hass",
")",
":",
"mocked_device",
"=",
"_create_mocked_device",
"(",
")",
"with",
"_patch_config_flow_device",
"(",
"mocked_device",
")",
",",
"_patch_setup",
"(",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_IMPORT",
"}",
",",
"data",
"=",
"{",
"CONF_ENDPOINT",
":",
"ENDPOINT",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"result",
"[",
"\"title\"",
"]",
"==",
"MODEL",
"assert",
"result",
"[",
"\"data\"",
"]",
"==",
"{",
"CONF_NAME",
":",
"MODEL",
",",
"CONF_ENDPOINT",
":",
"ENDPOINT",
"}",
"mocked_device",
".",
"get_supported_methods",
".",
"assert_called_once",
"(",
")",
"mocked_device",
".",
"get_interface_information",
".",
"assert_called_once",
"(",
")"
] | [
126,
0
] | [
139,
64
] | python | en | ['en', 'en', 'en'] | True |
test_ssdp_bravia | (hass) | Test discovering a bravia TV. | Test discovering a bravia TV. | async def test_ssdp_bravia(hass):
"""Test discovering a bravia TV."""
ssdp_data = copy.deepcopy(SSDP_DATA)
ssdp_data["X_ScalarWebAPI_DeviceInfo"]["X_ScalarWebAPI_ServiceList"][
"X_ScalarWebAPI_ServiceType"
].append("videoScreen")
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_SSDP},
data=ssdp_data,
)
assert result["type"] == RESULT_TYPE_ABORT
assert result["reason"] == "not_songpal_device" | [
"async",
"def",
"test_ssdp_bravia",
"(",
"hass",
")",
":",
"ssdp_data",
"=",
"copy",
".",
"deepcopy",
"(",
"SSDP_DATA",
")",
"ssdp_data",
"[",
"\"X_ScalarWebAPI_DeviceInfo\"",
"]",
"[",
"\"X_ScalarWebAPI_ServiceList\"",
"]",
"[",
"\"X_ScalarWebAPI_ServiceType\"",
"]",
".",
"append",
"(",
"\"videoScreen\"",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_SSDP",
"}",
",",
"data",
"=",
"ssdp_data",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_ABORT",
"assert",
"result",
"[",
"\"reason\"",
"]",
"==",
"\"not_songpal_device\""
] | [
150,
0
] | [
162,
51
] | python | en | ['en', 'en', 'en'] | True |
test_sddp_exist | (hass) | Test discovering existed device. | Test discovering existed device. | async def test_sddp_exist(hass):
"""Test discovering existed device."""
_create_mock_config_entry(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_SSDP},
data=SSDP_DATA,
)
assert result["type"] == RESULT_TYPE_ABORT
assert result["reason"] == "already_configured" | [
"async",
"def",
"test_sddp_exist",
"(",
"hass",
")",
":",
"_create_mock_config_entry",
"(",
"hass",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_SSDP",
"}",
",",
"data",
"=",
"SSDP_DATA",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_ABORT",
"assert",
"result",
"[",
"\"reason\"",
"]",
"==",
"\"already_configured\""
] | [
165,
0
] | [
174,
51
] | python | en | ['nl', 'en', 'en'] | True |
test_user_exist | (hass) | Test user adding existed device. | Test user adding existed device. | async def test_user_exist(hass):
"""Test user adding existed device."""
mocked_device = _create_mocked_device()
_create_mock_config_entry(hass)
with _patch_config_flow_device(mocked_device):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=CONF_DATA
)
assert result["type"] == RESULT_TYPE_ABORT
assert result["reason"] == "already_configured"
mocked_device.get_supported_methods.assert_called_once()
mocked_device.get_interface_information.assert_called_once() | [
"async",
"def",
"test_user_exist",
"(",
"hass",
")",
":",
"mocked_device",
"=",
"_create_mocked_device",
"(",
")",
"_create_mock_config_entry",
"(",
"hass",
")",
"with",
"_patch_config_flow_device",
"(",
"mocked_device",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_USER",
"}",
",",
"data",
"=",
"CONF_DATA",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_ABORT",
"assert",
"result",
"[",
"\"reason\"",
"]",
"==",
"\"already_configured\"",
"mocked_device",
".",
"get_supported_methods",
".",
"assert_called_once",
"(",
")",
"mocked_device",
".",
"get_interface_information",
".",
"assert_called_once",
"(",
")"
] | [
177,
0
] | [
190,
64
] | python | en | ['da', 'en', 'en'] | True |
test_import_exist | (hass) | Test importing existed device. | Test importing existed device. | async def test_import_exist(hass):
"""Test importing existed device."""
mocked_device = _create_mocked_device()
_create_mock_config_entry(hass)
with _patch_config_flow_device(mocked_device):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data=CONF_DATA
)
assert result["type"] == RESULT_TYPE_ABORT
assert result["reason"] == "already_configured"
mocked_device.get_supported_methods.assert_called_once()
mocked_device.get_interface_information.assert_not_called() | [
"async",
"def",
"test_import_exist",
"(",
"hass",
")",
":",
"mocked_device",
"=",
"_create_mocked_device",
"(",
")",
"_create_mock_config_entry",
"(",
"hass",
")",
"with",
"_patch_config_flow_device",
"(",
"mocked_device",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_IMPORT",
"}",
",",
"data",
"=",
"CONF_DATA",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_ABORT",
"assert",
"result",
"[",
"\"reason\"",
"]",
"==",
"\"already_configured\"",
"mocked_device",
".",
"get_supported_methods",
".",
"assert_called_once",
"(",
")",
"mocked_device",
".",
"get_interface_information",
".",
"assert_not_called",
"(",
")"
] | [
193,
0
] | [
206,
63
] | python | en | ['de', 'en', 'en'] | True |
test_user_invalid | (hass) | Test using adding invalid config. | Test using adding invalid config. | async def test_user_invalid(hass):
"""Test using adding invalid config."""
mocked_device = _create_mocked_device(True)
_create_mock_config_entry(hass)
with _patch_config_flow_device(mocked_device):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=CONF_DATA
)
assert result["type"] == RESULT_TYPE_FORM
assert result["step_id"] == "user"
assert result["errors"] == {"base": "cannot_connect"}
mocked_device.get_supported_methods.assert_called_once()
mocked_device.get_interface_information.assert_not_called() | [
"async",
"def",
"test_user_invalid",
"(",
"hass",
")",
":",
"mocked_device",
"=",
"_create_mocked_device",
"(",
"True",
")",
"_create_mock_config_entry",
"(",
"hass",
")",
"with",
"_patch_config_flow_device",
"(",
"mocked_device",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_USER",
"}",
",",
"data",
"=",
"CONF_DATA",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"user\"",
"assert",
"result",
"[",
"\"errors\"",
"]",
"==",
"{",
"\"base\"",
":",
"\"cannot_connect\"",
"}",
"mocked_device",
".",
"get_supported_methods",
".",
"assert_called_once",
"(",
")",
"mocked_device",
".",
"get_interface_information",
".",
"assert_not_called",
"(",
")"
] | [
209,
0
] | [
223,
63
] | python | en | ['en', 'en', 'en'] | True |
test_import_invalid | (hass) | Test importing invalid config. | Test importing invalid config. | async def test_import_invalid(hass):
"""Test importing invalid config."""
mocked_device = _create_mocked_device(True)
_create_mock_config_entry(hass)
with _patch_config_flow_device(mocked_device):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data=CONF_DATA
)
assert result["type"] == RESULT_TYPE_ABORT
assert result["reason"] == "cannot_connect"
mocked_device.get_supported_methods.assert_called_once()
mocked_device.get_interface_information.assert_not_called() | [
"async",
"def",
"test_import_invalid",
"(",
"hass",
")",
":",
"mocked_device",
"=",
"_create_mocked_device",
"(",
"True",
")",
"_create_mock_config_entry",
"(",
"hass",
")",
"with",
"_patch_config_flow_device",
"(",
"mocked_device",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_IMPORT",
"}",
",",
"data",
"=",
"CONF_DATA",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_ABORT",
"assert",
"result",
"[",
"\"reason\"",
"]",
"==",
"\"cannot_connect\"",
"mocked_device",
".",
"get_supported_methods",
".",
"assert_called_once",
"(",
")",
"mocked_device",
".",
"get_interface_information",
".",
"assert_not_called",
"(",
")"
] | [
226,
0
] | [
239,
63
] | python | en | ['en', 'en', 'en'] | True |
test_device_custom_name | () | Test a device name from an Info trait. | Test a device name from an Info trait. | def test_device_custom_name():
"""Test a device name from an Info trait."""
device = Device.MakeDevice(
{
"name": "some-device-id",
"type": "sdm.devices.types.DOORBELL",
"traits": {
"sdm.devices.traits.Info": {
"customName": "My Doorbell",
},
},
},
auth=None,
)
device_info = DeviceInfo(device)
assert device_info.device_name == "My Doorbell"
assert device_info.device_model == "Doorbell"
assert device_info.device_brand == "Google Nest"
assert device_info.device_info == {
"identifiers": {("nest", "some-device-id")},
"name": "My Doorbell",
"manufacturer": "Google Nest",
"model": "Doorbell",
} | [
"def",
"test_device_custom_name",
"(",
")",
":",
"device",
"=",
"Device",
".",
"MakeDevice",
"(",
"{",
"\"name\"",
":",
"\"some-device-id\"",
",",
"\"type\"",
":",
"\"sdm.devices.types.DOORBELL\"",
",",
"\"traits\"",
":",
"{",
"\"sdm.devices.traits.Info\"",
":",
"{",
"\"customName\"",
":",
"\"My Doorbell\"",
",",
"}",
",",
"}",
",",
"}",
",",
"auth",
"=",
"None",
",",
")",
"device_info",
"=",
"DeviceInfo",
"(",
"device",
")",
"assert",
"device_info",
".",
"device_name",
"==",
"\"My Doorbell\"",
"assert",
"device_info",
".",
"device_model",
"==",
"\"Doorbell\"",
"assert",
"device_info",
".",
"device_brand",
"==",
"\"Google Nest\"",
"assert",
"device_info",
".",
"device_info",
"==",
"{",
"\"identifiers\"",
":",
"{",
"(",
"\"nest\"",
",",
"\"some-device-id\"",
")",
"}",
",",
"\"name\"",
":",
"\"My Doorbell\"",
",",
"\"manufacturer\"",
":",
"\"Google Nest\"",
",",
"\"model\"",
":",
"\"Doorbell\"",
",",
"}"
] | [
7,
0
] | [
31,
5
] | python | en | ['en', 'en', 'en'] | True |
test_device_name_room | () | Test a device name from the room name. | Test a device name from the room name. | def test_device_name_room():
"""Test a device name from the room name."""
device = Device.MakeDevice(
{
"name": "some-device-id",
"type": "sdm.devices.types.DOORBELL",
"parentRelations": [
{"parent": "some-structure-id", "displayName": "Some Room"}
],
},
auth=None,
)
device_info = DeviceInfo(device)
assert device_info.device_name == "Some Room"
assert device_info.device_model == "Doorbell"
assert device_info.device_brand == "Google Nest"
assert device_info.device_info == {
"identifiers": {("nest", "some-device-id")},
"name": "Some Room",
"manufacturer": "Google Nest",
"model": "Doorbell",
} | [
"def",
"test_device_name_room",
"(",
")",
":",
"device",
"=",
"Device",
".",
"MakeDevice",
"(",
"{",
"\"name\"",
":",
"\"some-device-id\"",
",",
"\"type\"",
":",
"\"sdm.devices.types.DOORBELL\"",
",",
"\"parentRelations\"",
":",
"[",
"{",
"\"parent\"",
":",
"\"some-structure-id\"",
",",
"\"displayName\"",
":",
"\"Some Room\"",
"}",
"]",
",",
"}",
",",
"auth",
"=",
"None",
",",
")",
"device_info",
"=",
"DeviceInfo",
"(",
"device",
")",
"assert",
"device_info",
".",
"device_name",
"==",
"\"Some Room\"",
"assert",
"device_info",
".",
"device_model",
"==",
"\"Doorbell\"",
"assert",
"device_info",
".",
"device_brand",
"==",
"\"Google Nest\"",
"assert",
"device_info",
".",
"device_info",
"==",
"{",
"\"identifiers\"",
":",
"{",
"(",
"\"nest\"",
",",
"\"some-device-id\"",
")",
"}",
",",
"\"name\"",
":",
"\"Some Room\"",
",",
"\"manufacturer\"",
":",
"\"Google Nest\"",
",",
"\"model\"",
":",
"\"Doorbell\"",
",",
"}"
] | [
34,
0
] | [
56,
5
] | python | en | ['en', 'en', 'en'] | True |
test_device_no_name | () | Test a device that has a name inferred from the type. | Test a device that has a name inferred from the type. | def test_device_no_name():
"""Test a device that has a name inferred from the type."""
device = Device.MakeDevice(
{"name": "some-device-id", "type": "sdm.devices.types.DOORBELL", "traits": {}},
auth=None,
)
device_info = DeviceInfo(device)
assert device_info.device_name == "Doorbell"
assert device_info.device_model == "Doorbell"
assert device_info.device_brand == "Google Nest"
assert device_info.device_info == {
"identifiers": {("nest", "some-device-id")},
"name": "Doorbell",
"manufacturer": "Google Nest",
"model": "Doorbell",
} | [
"def",
"test_device_no_name",
"(",
")",
":",
"device",
"=",
"Device",
".",
"MakeDevice",
"(",
"{",
"\"name\"",
":",
"\"some-device-id\"",
",",
"\"type\"",
":",
"\"sdm.devices.types.DOORBELL\"",
",",
"\"traits\"",
":",
"{",
"}",
"}",
",",
"auth",
"=",
"None",
",",
")",
"device_info",
"=",
"DeviceInfo",
"(",
"device",
")",
"assert",
"device_info",
".",
"device_name",
"==",
"\"Doorbell\"",
"assert",
"device_info",
".",
"device_model",
"==",
"\"Doorbell\"",
"assert",
"device_info",
".",
"device_brand",
"==",
"\"Google Nest\"",
"assert",
"device_info",
".",
"device_info",
"==",
"{",
"\"identifiers\"",
":",
"{",
"(",
"\"nest\"",
",",
"\"some-device-id\"",
")",
"}",
",",
"\"name\"",
":",
"\"Doorbell\"",
",",
"\"manufacturer\"",
":",
"\"Google Nest\"",
",",
"\"model\"",
":",
"\"Doorbell\"",
",",
"}"
] | [
59,
0
] | [
75,
5
] | python | en | ['en', 'en', 'en'] | True |
test_device_invalid_type | () | Test a device with a type name that is not recognized. | Test a device with a type name that is not recognized. | def test_device_invalid_type():
"""Test a device with a type name that is not recognized."""
device = Device.MakeDevice(
{
"name": "some-device-id",
"type": "sdm.devices.types.INVALID_TYPE",
"traits": {
"sdm.devices.traits.Info": {
"customName": "My Doorbell",
},
},
},
auth=None,
)
device_info = DeviceInfo(device)
assert device_info.device_name == "My Doorbell"
assert device_info.device_model is None
assert device_info.device_brand == "Google Nest"
assert device_info.device_info == {
"identifiers": {("nest", "some-device-id")},
"name": "My Doorbell",
"manufacturer": "Google Nest",
"model": None,
} | [
"def",
"test_device_invalid_type",
"(",
")",
":",
"device",
"=",
"Device",
".",
"MakeDevice",
"(",
"{",
"\"name\"",
":",
"\"some-device-id\"",
",",
"\"type\"",
":",
"\"sdm.devices.types.INVALID_TYPE\"",
",",
"\"traits\"",
":",
"{",
"\"sdm.devices.traits.Info\"",
":",
"{",
"\"customName\"",
":",
"\"My Doorbell\"",
",",
"}",
",",
"}",
",",
"}",
",",
"auth",
"=",
"None",
",",
")",
"device_info",
"=",
"DeviceInfo",
"(",
"device",
")",
"assert",
"device_info",
".",
"device_name",
"==",
"\"My Doorbell\"",
"assert",
"device_info",
".",
"device_model",
"is",
"None",
"assert",
"device_info",
".",
"device_brand",
"==",
"\"Google Nest\"",
"assert",
"device_info",
".",
"device_info",
"==",
"{",
"\"identifiers\"",
":",
"{",
"(",
"\"nest\"",
",",
"\"some-device-id\"",
")",
"}",
",",
"\"name\"",
":",
"\"My Doorbell\"",
",",
"\"manufacturer\"",
":",
"\"Google Nest\"",
",",
"\"model\"",
":",
"None",
",",
"}"
] | [
78,
0
] | [
102,
5
] | python | en | ['en', 'en', 'en'] | True |
test_async_setup_entry | (hass, aioclient_mock) | Test a successful setup entry and unload. | Test a successful setup entry and unload. | async def test_async_setup_entry(hass, aioclient_mock):
"""Test a successful setup entry and unload."""
aioclient_mock.get(
TEST_SYSTEM_URL,
text=TEST_SYSTEM_DATA,
)
entry = await add_mock_config(hass)
assert entry.state == ENTRY_STATE_LOADED
assert await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_done()
assert entry.state == ENTRY_STATE_NOT_LOADED | [
"async",
"def",
"test_async_setup_entry",
"(",
"hass",
",",
"aioclient_mock",
")",
":",
"aioclient_mock",
".",
"get",
"(",
"TEST_SYSTEM_URL",
",",
"text",
"=",
"TEST_SYSTEM_DATA",
",",
")",
"entry",
"=",
"await",
"add_mock_config",
"(",
"hass",
")",
"assert",
"entry",
".",
"state",
"==",
"ENTRY_STATE_LOADED",
"assert",
"await",
"hass",
".",
"config_entries",
".",
"async_unload",
"(",
"entry",
".",
"entry_id",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"entry",
".",
"state",
"==",
"ENTRY_STATE_NOT_LOADED"
] | [
15,
0
] | [
28,
48
] | python | en | ['en', 'en', 'en'] | True |
test_async_setup_entry_failure | (hass, aioclient_mock) | Test a unsuccessful setup entry. | Test a unsuccessful setup entry. | async def test_async_setup_entry_failure(hass, aioclient_mock):
"""Test a unsuccessful setup entry."""
aioclient_mock.get(
TEST_SYSTEM_URL,
exc=SyntaxError,
)
entry = await add_mock_config(hass)
assert entry.state == ENTRY_STATE_SETUP_RETRY | [
"async",
"def",
"test_async_setup_entry_failure",
"(",
"hass",
",",
"aioclient_mock",
")",
":",
"aioclient_mock",
".",
"get",
"(",
"TEST_SYSTEM_URL",
",",
"exc",
"=",
"SyntaxError",
",",
")",
"entry",
"=",
"await",
"add_mock_config",
"(",
"hass",
")",
"assert",
"entry",
".",
"state",
"==",
"ENTRY_STATE_SETUP_RETRY"
] | [
31,
0
] | [
40,
49
] | python | ca | ['ca', 'fr', 'en'] | False |
SummarizationModule.save_readable_batch | (self, batch: Dict[str, torch.Tensor]) | A debugging utility | A debugging utility | def save_readable_batch(self, batch: Dict[str, torch.Tensor]) -> Dict[str, List[str]]:
"""A debugging utility"""
readable_batch = {
k: self.tokenizer.batch_decode(v.tolist()) if "mask" not in k else v.shape for k, v in batch.items()
}
save_json(readable_batch, Path(self.output_dir) / "text_batch.json")
save_json({k: v.tolist() for k, v in batch.items()}, Path(self.output_dir) / "tok_batch.json")
self.already_saved_batch = True
return readable_batch | [
"def",
"save_readable_batch",
"(",
"self",
",",
"batch",
":",
"Dict",
"[",
"str",
",",
"torch",
".",
"Tensor",
"]",
")",
"->",
"Dict",
"[",
"str",
",",
"List",
"[",
"str",
"]",
"]",
":",
"readable_batch",
"=",
"{",
"k",
":",
"self",
".",
"tokenizer",
".",
"batch_decode",
"(",
"v",
".",
"tolist",
"(",
")",
")",
"if",
"\"mask\"",
"not",
"in",
"k",
"else",
"v",
".",
"shape",
"for",
"k",
",",
"v",
"in",
"batch",
".",
"items",
"(",
")",
"}",
"save_json",
"(",
"readable_batch",
",",
"Path",
"(",
"self",
".",
"output_dir",
")",
"/",
"\"text_batch.json\"",
")",
"save_json",
"(",
"{",
"k",
":",
"v",
".",
"tolist",
"(",
")",
"for",
"k",
",",
"v",
"in",
"batch",
".",
"items",
"(",
")",
"}",
",",
"Path",
"(",
"self",
".",
"output_dir",
")",
"/",
"\"tok_batch.json\"",
")",
"self",
".",
"already_saved_batch",
"=",
"True",
"return",
"readable_batch"
] | [
117,
4
] | [
126,
29
] | python | es | ['it', 'es', 'pt'] | False |
config_entry_fixture | () | Create hass config_entry fixture. | Create hass config_entry fixture. | def config_entry_fixture():
"""Create hass config_entry fixture."""
data = {
CONF_HOST: "192.168.1.1",
CONF_PORT: "2345",
CONF_PASSWORD: "",
}
return MockConfigEntry(
version=1,
domain=DOMAIN,
title="",
data=data,
options={CONF_TTS_PAUSE_TIME: 0},
system_options={},
source=SOURCE_USER,
connection_class=CONN_CLASS_LOCAL_PUSH,
entry_id=1,
) | [
"def",
"config_entry_fixture",
"(",
")",
":",
"data",
"=",
"{",
"CONF_HOST",
":",
"\"192.168.1.1\"",
",",
"CONF_PORT",
":",
"\"2345\"",
",",
"CONF_PASSWORD",
":",
"\"\"",
",",
"}",
"return",
"MockConfigEntry",
"(",
"version",
"=",
"1",
",",
"domain",
"=",
"DOMAIN",
",",
"title",
"=",
"\"\"",
",",
"data",
"=",
"data",
",",
"options",
"=",
"{",
"CONF_TTS_PAUSE_TIME",
":",
"0",
"}",
",",
"system_options",
"=",
"{",
"}",
",",
"source",
"=",
"SOURCE_USER",
",",
"connection_class",
"=",
"CONN_CLASS_LOCAL_PUSH",
",",
"entry_id",
"=",
"1",
",",
")"
] | [
270,
0
] | [
287,
5
] | python | en | ['en', 'en', 'en'] | True |
get_request_return_values_fixture | () | Get request return values we can change later. | Get request return values we can change later. | async def get_request_return_values_fixture():
"""Get request return values we can change later."""
return {
"config": SAMPLE_CONFIG,
"outputs": SAMPLE_OUTPUTS_ON,
"player": SAMPLE_PLAYER_PAUSED,
"queue": SAMPLE_QUEUE_TTS,
} | [
"async",
"def",
"get_request_return_values_fixture",
"(",
")",
":",
"return",
"{",
"\"config\"",
":",
"SAMPLE_CONFIG",
",",
"\"outputs\"",
":",
"SAMPLE_OUTPUTS_ON",
",",
"\"player\"",
":",
"SAMPLE_PLAYER_PAUSED",
",",
"\"queue\"",
":",
"SAMPLE_QUEUE_TTS",
",",
"}"
] | [
291,
0
] | [
298,
5
] | python | en | ['en', 'en', 'en'] | True |
mock_api_object_fixture | (hass, config_entry, get_request_return_values) | Create mock api fixture. | Create mock api fixture. | async def mock_api_object_fixture(hass, config_entry, get_request_return_values):
"""Create mock api fixture."""
async def get_request_side_effect(update_type):
if update_type == "outputs":
return {"outputs": get_request_return_values["outputs"]}
return get_request_return_values[update_type]
with patch(
"homeassistant.components.forked_daapd.media_player.ForkedDaapdAPI",
autospec=True,
) as mock_api:
mock_api.return_value.get_request.side_effect = get_request_side_effect
mock_api.return_value.full_url.return_value = ""
mock_api.return_value.get_pipes.return_value = SAMPLE_PIPES
mock_api.return_value.get_playlists.return_value = SAMPLE_PLAYLISTS
config_entry.add_to_hass(hass)
await config_entry.async_setup(hass)
await hass.async_block_till_done()
mock_api.return_value.start_websocket_handler.assert_called_once()
mock_api.return_value.get_request.assert_called_once()
updater_update = mock_api.return_value.start_websocket_handler.call_args[0][2]
await updater_update(["player", "outputs", "queue"])
await hass.async_block_till_done()
async def add_to_queue_side_effect(
uris, playback=None, playback_from_position=None, clear=None
):
await updater_update(["queue", "player"])
mock_api.return_value.add_to_queue.side_effect = (
add_to_queue_side_effect # for play_media testing
)
async def pause_side_effect():
await updater_update(["player"])
mock_api.return_value.pause_playback.side_effect = pause_side_effect
return mock_api.return_value | [
"async",
"def",
"mock_api_object_fixture",
"(",
"hass",
",",
"config_entry",
",",
"get_request_return_values",
")",
":",
"async",
"def",
"get_request_side_effect",
"(",
"update_type",
")",
":",
"if",
"update_type",
"==",
"\"outputs\"",
":",
"return",
"{",
"\"outputs\"",
":",
"get_request_return_values",
"[",
"\"outputs\"",
"]",
"}",
"return",
"get_request_return_values",
"[",
"update_type",
"]",
"with",
"patch",
"(",
"\"homeassistant.components.forked_daapd.media_player.ForkedDaapdAPI\"",
",",
"autospec",
"=",
"True",
",",
")",
"as",
"mock_api",
":",
"mock_api",
".",
"return_value",
".",
"get_request",
".",
"side_effect",
"=",
"get_request_side_effect",
"mock_api",
".",
"return_value",
".",
"full_url",
".",
"return_value",
"=",
"\"\"",
"mock_api",
".",
"return_value",
".",
"get_pipes",
".",
"return_value",
"=",
"SAMPLE_PIPES",
"mock_api",
".",
"return_value",
".",
"get_playlists",
".",
"return_value",
"=",
"SAMPLE_PLAYLISTS",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"await",
"config_entry",
".",
"async_setup",
"(",
"hass",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"mock_api",
".",
"return_value",
".",
"start_websocket_handler",
".",
"assert_called_once",
"(",
")",
"mock_api",
".",
"return_value",
".",
"get_request",
".",
"assert_called_once",
"(",
")",
"updater_update",
"=",
"mock_api",
".",
"return_value",
".",
"start_websocket_handler",
".",
"call_args",
"[",
"0",
"]",
"[",
"2",
"]",
"await",
"updater_update",
"(",
"[",
"\"player\"",
",",
"\"outputs\"",
",",
"\"queue\"",
"]",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"async",
"def",
"add_to_queue_side_effect",
"(",
"uris",
",",
"playback",
"=",
"None",
",",
"playback_from_position",
"=",
"None",
",",
"clear",
"=",
"None",
")",
":",
"await",
"updater_update",
"(",
"[",
"\"queue\"",
",",
"\"player\"",
"]",
")",
"mock_api",
".",
"return_value",
".",
"add_to_queue",
".",
"side_effect",
"=",
"(",
"add_to_queue_side_effect",
"# for play_media testing",
")",
"async",
"def",
"pause_side_effect",
"(",
")",
":",
"await",
"updater_update",
"(",
"[",
"\"player\"",
"]",
")",
"mock_api",
".",
"return_value",
".",
"pause_playback",
".",
"side_effect",
"=",
"pause_side_effect",
"return",
"mock_api",
".",
"return_value"
] | [
302,
0
] | [
342,
32
] | python | en | ['pl', 'ro', 'en'] | False |
test_unload_config_entry | (hass, config_entry, mock_api_object) | Test the player is removed when the config entry is unloaded. | Test the player is removed when the config entry is unloaded. | async def test_unload_config_entry(hass, config_entry, mock_api_object):
"""Test the player is removed when the config entry is unloaded."""
assert hass.states.get(TEST_MASTER_ENTITY_NAME)
assert hass.states.get(TEST_ZONE_ENTITY_NAMES[0])
await config_entry.async_unload(hass)
assert not hass.states.get(TEST_MASTER_ENTITY_NAME)
assert not hass.states.get(TEST_ZONE_ENTITY_NAMES[0]) | [
"async",
"def",
"test_unload_config_entry",
"(",
"hass",
",",
"config_entry",
",",
"mock_api_object",
")",
":",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_ZONE_ENTITY_NAMES",
"[",
"0",
"]",
")",
"await",
"config_entry",
".",
"async_unload",
"(",
"hass",
")",
"assert",
"not",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
"assert",
"not",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_ZONE_ENTITY_NAMES",
"[",
"0",
"]",
")"
] | [
345,
0
] | [
351,
57
] | python | en | ['en', 'en', 'en'] | True |
test_master_state | (hass, mock_api_object) | Test master state attributes. | Test master state attributes. | def test_master_state(hass, mock_api_object):
"""Test master state attributes."""
state = hass.states.get(TEST_MASTER_ENTITY_NAME)
assert state.state == STATE_PAUSED
assert state.attributes[ATTR_FRIENDLY_NAME] == "forked-daapd server"
assert state.attributes[ATTR_SUPPORTED_FEATURES] == SUPPORTED_FEATURES
assert not state.attributes[ATTR_MEDIA_VOLUME_MUTED]
assert state.attributes[ATTR_MEDIA_VOLUME_LEVEL] == 0.2
assert state.attributes[ATTR_MEDIA_CONTENT_ID] == 12322
assert state.attributes[ATTR_MEDIA_CONTENT_TYPE] == MEDIA_TYPE_MUSIC
assert state.attributes[ATTR_MEDIA_DURATION] == 0.05
assert state.attributes[ATTR_MEDIA_POSITION] == 0.005
assert state.attributes[ATTR_MEDIA_TITLE] == "No album" # reversed for url
assert state.attributes[ATTR_MEDIA_ARTIST] == "Google"
assert state.attributes[ATTR_MEDIA_ALBUM_NAME] == "Short TTS file" # reversed
assert state.attributes[ATTR_MEDIA_ALBUM_ARTIST] == "The xx"
assert state.attributes[ATTR_MEDIA_TRACK] == 1
assert not state.attributes[ATTR_MEDIA_SHUFFLE] | [
"def",
"test_master_state",
"(",
"hass",
",",
"mock_api_object",
")",
":",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_PAUSED",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_FRIENDLY_NAME",
"]",
"==",
"\"forked-daapd server\"",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_SUPPORTED_FEATURES",
"]",
"==",
"SUPPORTED_FEATURES",
"assert",
"not",
"state",
".",
"attributes",
"[",
"ATTR_MEDIA_VOLUME_MUTED",
"]",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_MEDIA_VOLUME_LEVEL",
"]",
"==",
"0.2",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_MEDIA_CONTENT_ID",
"]",
"==",
"12322",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_MEDIA_CONTENT_TYPE",
"]",
"==",
"MEDIA_TYPE_MUSIC",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_MEDIA_DURATION",
"]",
"==",
"0.05",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_MEDIA_POSITION",
"]",
"==",
"0.005",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_MEDIA_TITLE",
"]",
"==",
"\"No album\"",
"# reversed for url",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_MEDIA_ARTIST",
"]",
"==",
"\"Google\"",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_MEDIA_ALBUM_NAME",
"]",
"==",
"\"Short TTS file\"",
"# reversed",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_MEDIA_ALBUM_ARTIST",
"]",
"==",
"\"The xx\"",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_MEDIA_TRACK",
"]",
"==",
"1",
"assert",
"not",
"state",
".",
"attributes",
"[",
"ATTR_MEDIA_SHUFFLE",
"]"
] | [
354,
0
] | [
371,
51
] | python | en | ['en', 'en', 'en'] | True |
test_no_update_when_get_request_returns_none | (
hass, config_entry, mock_api_object
) | Test when get request returns None. | Test when get request returns None. | async def test_no_update_when_get_request_returns_none(
hass, config_entry, mock_api_object
):
"""Test when get request returns None."""
async def get_request_side_effect(update_type):
return None
mock_api_object.get_request.side_effect = get_request_side_effect
updater_update = mock_api_object.start_websocket_handler.call_args[0][2]
signal_output_call = async_mock_signal(
hass, SIGNAL_UPDATE_OUTPUTS.format(config_entry.entry_id)
)
signal_player_call = async_mock_signal(
hass, SIGNAL_UPDATE_PLAYER.format(config_entry.entry_id)
)
signal_queue_call = async_mock_signal(
hass, SIGNAL_UPDATE_QUEUE.format(config_entry.entry_id)
)
await updater_update(["outputs", "player", "queue"])
await hass.async_block_till_done()
assert len(signal_output_call) == 0
assert len(signal_player_call) == 0
assert len(signal_queue_call) == 0 | [
"async",
"def",
"test_no_update_when_get_request_returns_none",
"(",
"hass",
",",
"config_entry",
",",
"mock_api_object",
")",
":",
"async",
"def",
"get_request_side_effect",
"(",
"update_type",
")",
":",
"return",
"None",
"mock_api_object",
".",
"get_request",
".",
"side_effect",
"=",
"get_request_side_effect",
"updater_update",
"=",
"mock_api_object",
".",
"start_websocket_handler",
".",
"call_args",
"[",
"0",
"]",
"[",
"2",
"]",
"signal_output_call",
"=",
"async_mock_signal",
"(",
"hass",
",",
"SIGNAL_UPDATE_OUTPUTS",
".",
"format",
"(",
"config_entry",
".",
"entry_id",
")",
")",
"signal_player_call",
"=",
"async_mock_signal",
"(",
"hass",
",",
"SIGNAL_UPDATE_PLAYER",
".",
"format",
"(",
"config_entry",
".",
"entry_id",
")",
")",
"signal_queue_call",
"=",
"async_mock_signal",
"(",
"hass",
",",
"SIGNAL_UPDATE_QUEUE",
".",
"format",
"(",
"config_entry",
".",
"entry_id",
")",
")",
"await",
"updater_update",
"(",
"[",
"\"outputs\"",
",",
"\"player\"",
",",
"\"queue\"",
"]",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"signal_output_call",
")",
"==",
"0",
"assert",
"len",
"(",
"signal_player_call",
")",
"==",
"0",
"assert",
"len",
"(",
"signal_queue_call",
")",
"==",
"0"
] | [
374,
0
] | [
397,
38
] | python | en | ['en', 'de', 'en'] | True |
test_zone | (hass, mock_api_object) | Test zone attributes and methods. | Test zone attributes and methods. | async def test_zone(hass, mock_api_object):
"""Test zone attributes and methods."""
zone_entity_name = TEST_ZONE_ENTITY_NAMES[0]
state = hass.states.get(zone_entity_name)
assert state.attributes[ATTR_FRIENDLY_NAME] == "forked-daapd output (kitchen)"
assert state.attributes[ATTR_SUPPORTED_FEATURES] == SUPPORTED_FEATURES_ZONE
assert state.state == STATE_ON
assert state.attributes[ATTR_MEDIA_VOLUME_LEVEL] == 0.5
assert not state.attributes[ATTR_MEDIA_VOLUME_MUTED]
await _service_call(hass, zone_entity_name, SERVICE_TURN_ON)
await _service_call(hass, zone_entity_name, SERVICE_TURN_OFF)
await _service_call(hass, zone_entity_name, SERVICE_TOGGLE)
await _service_call(
hass, zone_entity_name, SERVICE_VOLUME_SET, {ATTR_MEDIA_VOLUME_LEVEL: 0.3}
)
await _service_call(
hass, zone_entity_name, SERVICE_VOLUME_MUTE, {ATTR_MEDIA_VOLUME_MUTED: True}
)
await _service_call(
hass, zone_entity_name, SERVICE_VOLUME_MUTE, {ATTR_MEDIA_VOLUME_MUTED: False}
)
zone_entity_name = TEST_ZONE_ENTITY_NAMES[2]
await _service_call(hass, zone_entity_name, SERVICE_TOGGLE)
await _service_call(
hass, zone_entity_name, SERVICE_VOLUME_MUTE, {ATTR_MEDIA_VOLUME_MUTED: True}
)
output_id = SAMPLE_OUTPUTS_ON[0]["id"]
initial_volume = SAMPLE_OUTPUTS_ON[0]["volume"]
mock_api_object.change_output.assert_any_call(output_id, selected=True)
mock_api_object.change_output.assert_any_call(output_id, selected=False)
mock_api_object.set_volume.assert_any_call(output_id=output_id, volume=30)
mock_api_object.set_volume.assert_any_call(output_id=output_id, volume=0)
mock_api_object.set_volume.assert_any_call(
output_id=output_id, volume=initial_volume
)
output_id = SAMPLE_OUTPUTS_ON[2]["id"]
mock_api_object.change_output.assert_any_call(output_id, selected=True) | [
"async",
"def",
"test_zone",
"(",
"hass",
",",
"mock_api_object",
")",
":",
"zone_entity_name",
"=",
"TEST_ZONE_ENTITY_NAMES",
"[",
"0",
"]",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"zone_entity_name",
")",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_FRIENDLY_NAME",
"]",
"==",
"\"forked-daapd output (kitchen)\"",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_SUPPORTED_FEATURES",
"]",
"==",
"SUPPORTED_FEATURES_ZONE",
"assert",
"state",
".",
"state",
"==",
"STATE_ON",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_MEDIA_VOLUME_LEVEL",
"]",
"==",
"0.5",
"assert",
"not",
"state",
".",
"attributes",
"[",
"ATTR_MEDIA_VOLUME_MUTED",
"]",
"await",
"_service_call",
"(",
"hass",
",",
"zone_entity_name",
",",
"SERVICE_TURN_ON",
")",
"await",
"_service_call",
"(",
"hass",
",",
"zone_entity_name",
",",
"SERVICE_TURN_OFF",
")",
"await",
"_service_call",
"(",
"hass",
",",
"zone_entity_name",
",",
"SERVICE_TOGGLE",
")",
"await",
"_service_call",
"(",
"hass",
",",
"zone_entity_name",
",",
"SERVICE_VOLUME_SET",
",",
"{",
"ATTR_MEDIA_VOLUME_LEVEL",
":",
"0.3",
"}",
")",
"await",
"_service_call",
"(",
"hass",
",",
"zone_entity_name",
",",
"SERVICE_VOLUME_MUTE",
",",
"{",
"ATTR_MEDIA_VOLUME_MUTED",
":",
"True",
"}",
")",
"await",
"_service_call",
"(",
"hass",
",",
"zone_entity_name",
",",
"SERVICE_VOLUME_MUTE",
",",
"{",
"ATTR_MEDIA_VOLUME_MUTED",
":",
"False",
"}",
")",
"zone_entity_name",
"=",
"TEST_ZONE_ENTITY_NAMES",
"[",
"2",
"]",
"await",
"_service_call",
"(",
"hass",
",",
"zone_entity_name",
",",
"SERVICE_TOGGLE",
")",
"await",
"_service_call",
"(",
"hass",
",",
"zone_entity_name",
",",
"SERVICE_VOLUME_MUTE",
",",
"{",
"ATTR_MEDIA_VOLUME_MUTED",
":",
"True",
"}",
")",
"output_id",
"=",
"SAMPLE_OUTPUTS_ON",
"[",
"0",
"]",
"[",
"\"id\"",
"]",
"initial_volume",
"=",
"SAMPLE_OUTPUTS_ON",
"[",
"0",
"]",
"[",
"\"volume\"",
"]",
"mock_api_object",
".",
"change_output",
".",
"assert_any_call",
"(",
"output_id",
",",
"selected",
"=",
"True",
")",
"mock_api_object",
".",
"change_output",
".",
"assert_any_call",
"(",
"output_id",
",",
"selected",
"=",
"False",
")",
"mock_api_object",
".",
"set_volume",
".",
"assert_any_call",
"(",
"output_id",
"=",
"output_id",
",",
"volume",
"=",
"30",
")",
"mock_api_object",
".",
"set_volume",
".",
"assert_any_call",
"(",
"output_id",
"=",
"output_id",
",",
"volume",
"=",
"0",
")",
"mock_api_object",
".",
"set_volume",
".",
"assert_any_call",
"(",
"output_id",
"=",
"output_id",
",",
"volume",
"=",
"initial_volume",
")",
"output_id",
"=",
"SAMPLE_OUTPUTS_ON",
"[",
"2",
"]",
"[",
"\"id\"",
"]",
"mock_api_object",
".",
"change_output",
".",
"assert_any_call",
"(",
"output_id",
",",
"selected",
"=",
"True",
")"
] | [
413,
0
] | [
449,
75
] | python | en | ['en', 'en', 'en'] | True |
test_last_outputs_master | (hass, mock_api_object) | Test restoration of _last_outputs. | Test restoration of _last_outputs. | async def test_last_outputs_master(hass, mock_api_object):
"""Test restoration of _last_outputs."""
# Test turning on sends API call
await _service_call(hass, TEST_MASTER_ENTITY_NAME, SERVICE_TURN_ON)
assert mock_api_object.change_output.call_count == 0
assert mock_api_object.set_enabled_outputs.call_count == 1
await _service_call(
hass, TEST_MASTER_ENTITY_NAME, SERVICE_TURN_OFF
) # should have stored last outputs
assert mock_api_object.change_output.call_count == 0
assert mock_api_object.set_enabled_outputs.call_count == 2
await _service_call(hass, TEST_MASTER_ENTITY_NAME, SERVICE_TURN_ON)
assert mock_api_object.change_output.call_count == 3
assert mock_api_object.set_enabled_outputs.call_count == 2 | [
"async",
"def",
"test_last_outputs_master",
"(",
"hass",
",",
"mock_api_object",
")",
":",
"# Test turning on sends API call",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_TURN_ON",
")",
"assert",
"mock_api_object",
".",
"change_output",
".",
"call_count",
"==",
"0",
"assert",
"mock_api_object",
".",
"set_enabled_outputs",
".",
"call_count",
"==",
"1",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_TURN_OFF",
")",
"# should have stored last outputs",
"assert",
"mock_api_object",
".",
"change_output",
".",
"call_count",
"==",
"0",
"assert",
"mock_api_object",
".",
"set_enabled_outputs",
".",
"call_count",
"==",
"2",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_TURN_ON",
")",
"assert",
"mock_api_object",
".",
"change_output",
".",
"call_count",
"==",
"3",
"assert",
"mock_api_object",
".",
"set_enabled_outputs",
".",
"call_count",
"==",
"2"
] | [
452,
0
] | [
465,
62
] | python | en | ['en', 'da', 'en'] | True |
test_bunch_of_stuff_master | (hass, get_request_return_values, mock_api_object) | Run bunch of stuff. | Run bunch of stuff. | async def test_bunch_of_stuff_master(hass, get_request_return_values, mock_api_object):
"""Run bunch of stuff."""
await _service_call(hass, TEST_MASTER_ENTITY_NAME, SERVICE_TURN_ON)
await _service_call(hass, TEST_MASTER_ENTITY_NAME, SERVICE_TURN_OFF)
await _service_call(hass, TEST_MASTER_ENTITY_NAME, SERVICE_TOGGLE)
await _service_call(
hass,
TEST_MASTER_ENTITY_NAME,
SERVICE_VOLUME_MUTE,
{ATTR_MEDIA_VOLUME_MUTED: True},
)
await _service_call(
hass,
TEST_MASTER_ENTITY_NAME,
SERVICE_VOLUME_MUTE,
{ATTR_MEDIA_VOLUME_MUTED: False},
)
await _service_call(
hass,
TEST_MASTER_ENTITY_NAME,
SERVICE_VOLUME_SET,
{ATTR_MEDIA_VOLUME_LEVEL: 0.5},
)
await _service_call(hass, TEST_MASTER_ENTITY_NAME, SERVICE_MEDIA_PAUSE)
await _service_call(hass, TEST_MASTER_ENTITY_NAME, SERVICE_MEDIA_PLAY)
await _service_call(hass, TEST_MASTER_ENTITY_NAME, SERVICE_MEDIA_STOP)
await _service_call(hass, TEST_MASTER_ENTITY_NAME, SERVICE_MEDIA_PREVIOUS_TRACK)
await _service_call(hass, TEST_MASTER_ENTITY_NAME, SERVICE_MEDIA_NEXT_TRACK)
await _service_call(
hass,
TEST_MASTER_ENTITY_NAME,
SERVICE_MEDIA_SEEK,
{ATTR_MEDIA_SEEK_POSITION: 35},
)
await _service_call(hass, TEST_MASTER_ENTITY_NAME, SERVICE_CLEAR_PLAYLIST)
await _service_call(
hass, TEST_MASTER_ENTITY_NAME, SERVICE_SHUFFLE_SET, {ATTR_MEDIA_SHUFFLE: False}
)
# stop player and run more stuff
state = hass.states.get(TEST_MASTER_ENTITY_NAME)
assert state.attributes[ATTR_MEDIA_VOLUME_LEVEL] == 0.2
get_request_return_values["player"] = SAMPLE_PLAYER_STOPPED
updater_update = mock_api_object.start_websocket_handler.call_args[0][2]
await updater_update(["player"])
await hass.async_block_till_done()
# mute from volume==0
state = hass.states.get(TEST_MASTER_ENTITY_NAME)
assert state.attributes[ATTR_MEDIA_VOLUME_LEVEL] == 0
await _service_call(
hass,
TEST_MASTER_ENTITY_NAME,
SERVICE_VOLUME_MUTE,
{ATTR_MEDIA_VOLUME_MUTED: True},
)
# now turn off (stopped and all outputs unselected)
get_request_return_values["outputs"] = SAMPLE_OUTPUTS_UNSELECTED
await updater_update(["outputs"])
await hass.async_block_till_done()
# toggle from off
await _service_call(hass, TEST_MASTER_ENTITY_NAME, SERVICE_TOGGLE)
for output in SAMPLE_OUTPUTS_ON:
mock_api_object.change_output.assert_any_call(
output["id"],
selected=output["selected"],
volume=output["volume"],
)
mock_api_object.set_volume.assert_any_call(volume=0)
mock_api_object.set_volume.assert_any_call(volume=SAMPLE_PLAYER_PAUSED["volume"])
mock_api_object.set_volume.assert_any_call(volume=50)
mock_api_object.set_enabled_outputs.assert_any_call(
[output["id"] for output in SAMPLE_OUTPUTS_ON]
)
mock_api_object.set_enabled_outputs.assert_any_call([])
mock_api_object.start_playback.assert_called_once()
assert mock_api_object.pause_playback.call_count == 3
mock_api_object.stop_playback.assert_called_once()
mock_api_object.previous_track.assert_called_once()
mock_api_object.next_track.assert_called_once()
mock_api_object.seek.assert_called_once()
mock_api_object.shuffle.assert_called_once()
mock_api_object.clear_queue.assert_called_once() | [
"async",
"def",
"test_bunch_of_stuff_master",
"(",
"hass",
",",
"get_request_return_values",
",",
"mock_api_object",
")",
":",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_TURN_ON",
")",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_TURN_OFF",
")",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_TOGGLE",
")",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_VOLUME_MUTE",
",",
"{",
"ATTR_MEDIA_VOLUME_MUTED",
":",
"True",
"}",
",",
")",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_VOLUME_MUTE",
",",
"{",
"ATTR_MEDIA_VOLUME_MUTED",
":",
"False",
"}",
",",
")",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_VOLUME_SET",
",",
"{",
"ATTR_MEDIA_VOLUME_LEVEL",
":",
"0.5",
"}",
",",
")",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_MEDIA_PAUSE",
")",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_MEDIA_PLAY",
")",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_MEDIA_STOP",
")",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_MEDIA_PREVIOUS_TRACK",
")",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_MEDIA_NEXT_TRACK",
")",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_MEDIA_SEEK",
",",
"{",
"ATTR_MEDIA_SEEK_POSITION",
":",
"35",
"}",
",",
")",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_CLEAR_PLAYLIST",
")",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_SHUFFLE_SET",
",",
"{",
"ATTR_MEDIA_SHUFFLE",
":",
"False",
"}",
")",
"# stop player and run more stuff",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_MEDIA_VOLUME_LEVEL",
"]",
"==",
"0.2",
"get_request_return_values",
"[",
"\"player\"",
"]",
"=",
"SAMPLE_PLAYER_STOPPED",
"updater_update",
"=",
"mock_api_object",
".",
"start_websocket_handler",
".",
"call_args",
"[",
"0",
"]",
"[",
"2",
"]",
"await",
"updater_update",
"(",
"[",
"\"player\"",
"]",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# mute from volume==0",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_MEDIA_VOLUME_LEVEL",
"]",
"==",
"0",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_VOLUME_MUTE",
",",
"{",
"ATTR_MEDIA_VOLUME_MUTED",
":",
"True",
"}",
",",
")",
"# now turn off (stopped and all outputs unselected)",
"get_request_return_values",
"[",
"\"outputs\"",
"]",
"=",
"SAMPLE_OUTPUTS_UNSELECTED",
"await",
"updater_update",
"(",
"[",
"\"outputs\"",
"]",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# toggle from off",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_TOGGLE",
")",
"for",
"output",
"in",
"SAMPLE_OUTPUTS_ON",
":",
"mock_api_object",
".",
"change_output",
".",
"assert_any_call",
"(",
"output",
"[",
"\"id\"",
"]",
",",
"selected",
"=",
"output",
"[",
"\"selected\"",
"]",
",",
"volume",
"=",
"output",
"[",
"\"volume\"",
"]",
",",
")",
"mock_api_object",
".",
"set_volume",
".",
"assert_any_call",
"(",
"volume",
"=",
"0",
")",
"mock_api_object",
".",
"set_volume",
".",
"assert_any_call",
"(",
"volume",
"=",
"SAMPLE_PLAYER_PAUSED",
"[",
"\"volume\"",
"]",
")",
"mock_api_object",
".",
"set_volume",
".",
"assert_any_call",
"(",
"volume",
"=",
"50",
")",
"mock_api_object",
".",
"set_enabled_outputs",
".",
"assert_any_call",
"(",
"[",
"output",
"[",
"\"id\"",
"]",
"for",
"output",
"in",
"SAMPLE_OUTPUTS_ON",
"]",
")",
"mock_api_object",
".",
"set_enabled_outputs",
".",
"assert_any_call",
"(",
"[",
"]",
")",
"mock_api_object",
".",
"start_playback",
".",
"assert_called_once",
"(",
")",
"assert",
"mock_api_object",
".",
"pause_playback",
".",
"call_count",
"==",
"3",
"mock_api_object",
".",
"stop_playback",
".",
"assert_called_once",
"(",
")",
"mock_api_object",
".",
"previous_track",
".",
"assert_called_once",
"(",
")",
"mock_api_object",
".",
"next_track",
".",
"assert_called_once",
"(",
")",
"mock_api_object",
".",
"seek",
".",
"assert_called_once",
"(",
")",
"mock_api_object",
".",
"shuffle",
".",
"assert_called_once",
"(",
")",
"mock_api_object",
".",
"clear_queue",
".",
"assert_called_once",
"(",
")"
] | [
468,
0
] | [
548,
52
] | python | en | ['en', 'zh-Latn', 'en'] | True |
test_async_play_media_from_paused | (hass, mock_api_object) | Test async play media from paused. | Test async play media from paused. | async def test_async_play_media_from_paused(hass, mock_api_object):
"""Test async play media from paused."""
initial_state = hass.states.get(TEST_MASTER_ENTITY_NAME)
await _service_call(
hass,
TEST_MASTER_ENTITY_NAME,
SERVICE_PLAY_MEDIA,
{
ATTR_MEDIA_CONTENT_TYPE: MEDIA_TYPE_MUSIC,
ATTR_MEDIA_CONTENT_ID: "somefile.mp3",
},
)
state = hass.states.get(TEST_MASTER_ENTITY_NAME)
assert state.state == initial_state.state
assert state.last_updated > initial_state.last_updated | [
"async",
"def",
"test_async_play_media_from_paused",
"(",
"hass",
",",
"mock_api_object",
")",
":",
"initial_state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_PLAY_MEDIA",
",",
"{",
"ATTR_MEDIA_CONTENT_TYPE",
":",
"MEDIA_TYPE_MUSIC",
",",
"ATTR_MEDIA_CONTENT_ID",
":",
"\"somefile.mp3\"",
",",
"}",
",",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
"assert",
"state",
".",
"state",
"==",
"initial_state",
".",
"state",
"assert",
"state",
".",
"last_updated",
">",
"initial_state",
".",
"last_updated"
] | [
551,
0
] | [
565,
58
] | python | en | ['en', 'en', 'en'] | True |
test_async_play_media_from_stopped | (
hass, get_request_return_values, mock_api_object
) | Test async play media from stopped. | Test async play media from stopped. | async def test_async_play_media_from_stopped(
hass, get_request_return_values, mock_api_object
):
"""Test async play media from stopped."""
updater_update = mock_api_object.start_websocket_handler.call_args[0][2]
get_request_return_values["player"] = SAMPLE_PLAYER_STOPPED
await updater_update(["player"])
await hass.async_block_till_done()
initial_state = hass.states.get(TEST_MASTER_ENTITY_NAME)
await _service_call(
hass,
TEST_MASTER_ENTITY_NAME,
SERVICE_PLAY_MEDIA,
{
ATTR_MEDIA_CONTENT_TYPE: MEDIA_TYPE_MUSIC,
ATTR_MEDIA_CONTENT_ID: "somefile.mp3",
},
)
state = hass.states.get(TEST_MASTER_ENTITY_NAME)
assert state.state == initial_state.state
assert state.last_updated > initial_state.last_updated | [
"async",
"def",
"test_async_play_media_from_stopped",
"(",
"hass",
",",
"get_request_return_values",
",",
"mock_api_object",
")",
":",
"updater_update",
"=",
"mock_api_object",
".",
"start_websocket_handler",
".",
"call_args",
"[",
"0",
"]",
"[",
"2",
"]",
"get_request_return_values",
"[",
"\"player\"",
"]",
"=",
"SAMPLE_PLAYER_STOPPED",
"await",
"updater_update",
"(",
"[",
"\"player\"",
"]",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"initial_state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_PLAY_MEDIA",
",",
"{",
"ATTR_MEDIA_CONTENT_TYPE",
":",
"MEDIA_TYPE_MUSIC",
",",
"ATTR_MEDIA_CONTENT_ID",
":",
"\"somefile.mp3\"",
",",
"}",
",",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
"assert",
"state",
".",
"state",
"==",
"initial_state",
".",
"state",
"assert",
"state",
".",
"last_updated",
">",
"initial_state",
".",
"last_updated"
] | [
568,
0
] | [
589,
58
] | python | en | ['en', 'en', 'en'] | True |
test_async_play_media_unsupported | (hass, mock_api_object) | Test async play media on unsupported media type. | Test async play media on unsupported media type. | async def test_async_play_media_unsupported(hass, mock_api_object):
"""Test async play media on unsupported media type."""
initial_state = hass.states.get(TEST_MASTER_ENTITY_NAME)
await _service_call(
hass,
TEST_MASTER_ENTITY_NAME,
SERVICE_PLAY_MEDIA,
{
ATTR_MEDIA_CONTENT_TYPE: MEDIA_TYPE_TVSHOW,
ATTR_MEDIA_CONTENT_ID: "wontwork.mp4",
},
)
state = hass.states.get(TEST_MASTER_ENTITY_NAME)
assert state.last_updated == initial_state.last_updated | [
"async",
"def",
"test_async_play_media_unsupported",
"(",
"hass",
",",
"mock_api_object",
")",
":",
"initial_state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_PLAY_MEDIA",
",",
"{",
"ATTR_MEDIA_CONTENT_TYPE",
":",
"MEDIA_TYPE_TVSHOW",
",",
"ATTR_MEDIA_CONTENT_ID",
":",
"\"wontwork.mp4\"",
",",
"}",
",",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
"assert",
"state",
".",
"last_updated",
"==",
"initial_state",
".",
"last_updated"
] | [
592,
0
] | [
605,
59
] | python | en | ['en', 'en', 'en'] | True |
test_async_play_media_tts_timeout | (hass, mock_api_object) | Test async play media with TTS timeout. | Test async play media with TTS timeout. | async def test_async_play_media_tts_timeout(hass, mock_api_object):
"""Test async play media with TTS timeout."""
mock_api_object.add_to_queue.side_effect = None
with patch("homeassistant.components.forked_daapd.media_player.TTS_TIMEOUT", 0):
initial_state = hass.states.get(TEST_MASTER_ENTITY_NAME)
await _service_call(
hass,
TEST_MASTER_ENTITY_NAME,
SERVICE_PLAY_MEDIA,
{
ATTR_MEDIA_CONTENT_TYPE: MEDIA_TYPE_MUSIC,
ATTR_MEDIA_CONTENT_ID: "somefile.mp3",
},
)
state = hass.states.get(TEST_MASTER_ENTITY_NAME)
assert state.state == initial_state.state
assert state.last_updated > initial_state.last_updated | [
"async",
"def",
"test_async_play_media_tts_timeout",
"(",
"hass",
",",
"mock_api_object",
")",
":",
"mock_api_object",
".",
"add_to_queue",
".",
"side_effect",
"=",
"None",
"with",
"patch",
"(",
"\"homeassistant.components.forked_daapd.media_player.TTS_TIMEOUT\"",
",",
"0",
")",
":",
"initial_state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_PLAY_MEDIA",
",",
"{",
"ATTR_MEDIA_CONTENT_TYPE",
":",
"MEDIA_TYPE_MUSIC",
",",
"ATTR_MEDIA_CONTENT_ID",
":",
"\"somefile.mp3\"",
",",
"}",
",",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
"assert",
"state",
".",
"state",
"==",
"initial_state",
".",
"state",
"assert",
"state",
".",
"last_updated",
">",
"initial_state",
".",
"last_updated"
] | [
608,
0
] | [
624,
62
] | python | en | ['en', 'en', 'en'] | True |
test_use_pipe_control_with_no_api | (hass, mock_api_object) | Test using pipe control with no api set. | Test using pipe control with no api set. | async def test_use_pipe_control_with_no_api(hass, mock_api_object):
"""Test using pipe control with no api set."""
await _service_call(
hass,
TEST_MASTER_ENTITY_NAME,
SERVICE_SELECT_SOURCE,
{ATTR_INPUT_SOURCE: "librespot-java (pipe)"},
)
await _service_call(hass, TEST_MASTER_ENTITY_NAME, SERVICE_MEDIA_PLAY)
assert mock_api_object.start_playback.call_count == 0 | [
"async",
"def",
"test_use_pipe_control_with_no_api",
"(",
"hass",
",",
"mock_api_object",
")",
":",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_SELECT_SOURCE",
",",
"{",
"ATTR_INPUT_SOURCE",
":",
"\"librespot-java (pipe)\"",
"}",
",",
")",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_MEDIA_PLAY",
")",
"assert",
"mock_api_object",
".",
"start_playback",
".",
"call_count",
"==",
"0"
] | [
627,
0
] | [
636,
57
] | python | en | ['en', 'en', 'en'] | True |
test_clear_source | (hass, mock_api_object) | Test changing source to clear. | Test changing source to clear. | async def test_clear_source(hass, mock_api_object):
"""Test changing source to clear."""
await _service_call(
hass,
TEST_MASTER_ENTITY_NAME,
SERVICE_SELECT_SOURCE,
{ATTR_INPUT_SOURCE: SOURCE_NAME_CLEAR},
)
state = hass.states.get(TEST_MASTER_ENTITY_NAME)
assert state.attributes[ATTR_INPUT_SOURCE] == SOURCE_NAME_DEFAULT | [
"async",
"def",
"test_clear_source",
"(",
"hass",
",",
"mock_api_object",
")",
":",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_SELECT_SOURCE",
",",
"{",
"ATTR_INPUT_SOURCE",
":",
"SOURCE_NAME_CLEAR",
"}",
",",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_INPUT_SOURCE",
"]",
"==",
"SOURCE_NAME_DEFAULT"
] | [
639,
0
] | [
648,
69
] | python | en | ['en', 'en', 'en'] | True |
pipe_control_api_object_fixture | (
hass, config_entry, get_request_return_values, mock_api_object
) | Fixture for mock librespot_java api. | Fixture for mock librespot_java api. | async def pipe_control_api_object_fixture(
hass, config_entry, get_request_return_values, mock_api_object
):
"""Fixture for mock librespot_java api."""
with patch(
"homeassistant.components.forked_daapd.media_player.LibrespotJavaAPI",
autospec=True,
) as pipe_control_api:
hass.config_entries.async_update_entry(config_entry, options=OPTIONS_DATA)
await hass.async_block_till_done()
get_request_return_values["player"] = SAMPLE_PLAYER_PLAYING
updater_update = mock_api_object.start_websocket_handler.call_args[0][2]
await updater_update(["player"])
await hass.async_block_till_done()
async def pause_side_effect():
await updater_update(["player"])
pipe_control_api.return_value.player_pause.side_effect = pause_side_effect
await updater_update(["database"]) # load in sources
await _service_call(
hass,
TEST_MASTER_ENTITY_NAME,
SERVICE_SELECT_SOURCE,
{ATTR_INPUT_SOURCE: "librespot-java (pipe)"},
)
return pipe_control_api.return_value | [
"async",
"def",
"pipe_control_api_object_fixture",
"(",
"hass",
",",
"config_entry",
",",
"get_request_return_values",
",",
"mock_api_object",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.forked_daapd.media_player.LibrespotJavaAPI\"",
",",
"autospec",
"=",
"True",
",",
")",
"as",
"pipe_control_api",
":",
"hass",
".",
"config_entries",
".",
"async_update_entry",
"(",
"config_entry",
",",
"options",
"=",
"OPTIONS_DATA",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"get_request_return_values",
"[",
"\"player\"",
"]",
"=",
"SAMPLE_PLAYER_PLAYING",
"updater_update",
"=",
"mock_api_object",
".",
"start_websocket_handler",
".",
"call_args",
"[",
"0",
"]",
"[",
"2",
"]",
"await",
"updater_update",
"(",
"[",
"\"player\"",
"]",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"async",
"def",
"pause_side_effect",
"(",
")",
":",
"await",
"updater_update",
"(",
"[",
"\"player\"",
"]",
")",
"pipe_control_api",
".",
"return_value",
".",
"player_pause",
".",
"side_effect",
"=",
"pause_side_effect",
"await",
"updater_update",
"(",
"[",
"\"database\"",
"]",
")",
"# load in sources",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_SELECT_SOURCE",
",",
"{",
"ATTR_INPUT_SOURCE",
":",
"\"librespot-java (pipe)\"",
"}",
",",
")",
"return",
"pipe_control_api",
".",
"return_value"
] | [
652,
0
] | [
680,
40
] | python | en | ['en', 'ca', 'en'] | True |
test_librespot_java_stuff | (
hass, get_request_return_values, mock_api_object, pipe_control_api_object
) | Test options update and librespot-java stuff. | Test options update and librespot-java stuff. | async def test_librespot_java_stuff(
hass, get_request_return_values, mock_api_object, pipe_control_api_object
):
"""Test options update and librespot-java stuff."""
state = hass.states.get(TEST_MASTER_ENTITY_NAME)
assert state.attributes[ATTR_INPUT_SOURCE] == "librespot-java (pipe)"
# call some basic services
await _service_call(hass, TEST_MASTER_ENTITY_NAME, SERVICE_MEDIA_STOP)
await _service_call(hass, TEST_MASTER_ENTITY_NAME, SERVICE_MEDIA_PREVIOUS_TRACK)
await _service_call(hass, TEST_MASTER_ENTITY_NAME, SERVICE_MEDIA_NEXT_TRACK)
await _service_call(hass, TEST_MASTER_ENTITY_NAME, SERVICE_MEDIA_PLAY)
pipe_control_api_object.player_pause.assert_called_once()
pipe_control_api_object.player_prev.assert_called_once()
pipe_control_api_object.player_next.assert_called_once()
pipe_control_api_object.player_resume.assert_called_once()
# switch away
await _service_call(
hass,
TEST_MASTER_ENTITY_NAME,
SERVICE_SELECT_SOURCE,
{ATTR_INPUT_SOURCE: SOURCE_NAME_DEFAULT},
)
state = hass.states.get(TEST_MASTER_ENTITY_NAME)
assert state.attributes[ATTR_INPUT_SOURCE] == SOURCE_NAME_DEFAULT
# test pipe getting queued externally changes source
get_request_return_values["queue"] = SAMPLE_QUEUE_PIPE
updater_update = mock_api_object.start_websocket_handler.call_args[0][2]
await updater_update(["queue"])
await hass.async_block_till_done()
state = hass.states.get(TEST_MASTER_ENTITY_NAME)
assert state.attributes[ATTR_INPUT_SOURCE] == "librespot-java (pipe)"
# test title and album not reversed when data_kind not url
assert state.attributes[ATTR_MEDIA_TITLE] == "librespot-java"
assert state.attributes[ATTR_MEDIA_ALBUM_NAME] == "some album" | [
"async",
"def",
"test_librespot_java_stuff",
"(",
"hass",
",",
"get_request_return_values",
",",
"mock_api_object",
",",
"pipe_control_api_object",
")",
":",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_INPUT_SOURCE",
"]",
"==",
"\"librespot-java (pipe)\"",
"# call some basic services",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_MEDIA_STOP",
")",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_MEDIA_PREVIOUS_TRACK",
")",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_MEDIA_NEXT_TRACK",
")",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_MEDIA_PLAY",
")",
"pipe_control_api_object",
".",
"player_pause",
".",
"assert_called_once",
"(",
")",
"pipe_control_api_object",
".",
"player_prev",
".",
"assert_called_once",
"(",
")",
"pipe_control_api_object",
".",
"player_next",
".",
"assert_called_once",
"(",
")",
"pipe_control_api_object",
".",
"player_resume",
".",
"assert_called_once",
"(",
")",
"# switch away",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_SELECT_SOURCE",
",",
"{",
"ATTR_INPUT_SOURCE",
":",
"SOURCE_NAME_DEFAULT",
"}",
",",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_INPUT_SOURCE",
"]",
"==",
"SOURCE_NAME_DEFAULT",
"# test pipe getting queued externally changes source",
"get_request_return_values",
"[",
"\"queue\"",
"]",
"=",
"SAMPLE_QUEUE_PIPE",
"updater_update",
"=",
"mock_api_object",
".",
"start_websocket_handler",
".",
"call_args",
"[",
"0",
"]",
"[",
"2",
"]",
"await",
"updater_update",
"(",
"[",
"\"queue\"",
"]",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_INPUT_SOURCE",
"]",
"==",
"\"librespot-java (pipe)\"",
"# test title and album not reversed when data_kind not url",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_MEDIA_TITLE",
"]",
"==",
"\"librespot-java\"",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_MEDIA_ALBUM_NAME",
"]",
"==",
"\"some album\""
] | [
683,
0
] | [
716,
66
] | python | en | ['en', 'en', 'en'] | True |
test_librespot_java_play_media | (hass, pipe_control_api_object) | Test play media with librespot-java pipe. | Test play media with librespot-java pipe. | async def test_librespot_java_play_media(hass, pipe_control_api_object):
"""Test play media with librespot-java pipe."""
initial_state = hass.states.get(TEST_MASTER_ENTITY_NAME)
await _service_call(
hass,
TEST_MASTER_ENTITY_NAME,
SERVICE_PLAY_MEDIA,
{
ATTR_MEDIA_CONTENT_TYPE: MEDIA_TYPE_MUSIC,
ATTR_MEDIA_CONTENT_ID: "somefile.mp3",
},
)
state = hass.states.get(TEST_MASTER_ENTITY_NAME)
assert state.state == initial_state.state
assert state.last_updated > initial_state.last_updated | [
"async",
"def",
"test_librespot_java_play_media",
"(",
"hass",
",",
"pipe_control_api_object",
")",
":",
"initial_state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_PLAY_MEDIA",
",",
"{",
"ATTR_MEDIA_CONTENT_TYPE",
":",
"MEDIA_TYPE_MUSIC",
",",
"ATTR_MEDIA_CONTENT_ID",
":",
"\"somefile.mp3\"",
",",
"}",
",",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
"assert",
"state",
".",
"state",
"==",
"initial_state",
".",
"state",
"assert",
"state",
".",
"last_updated",
">",
"initial_state",
".",
"last_updated"
] | [
719,
0
] | [
733,
58
] | python | en | ['en', 'en', 'en'] | True |
test_librespot_java_play_media_pause_timeout | (hass, pipe_control_api_object) | Test play media with librespot-java pipe. | Test play media with librespot-java pipe. | async def test_librespot_java_play_media_pause_timeout(hass, pipe_control_api_object):
"""Test play media with librespot-java pipe."""
# test media play with pause timeout
pipe_control_api_object.player_pause.side_effect = None
with patch(
"homeassistant.components.forked_daapd.media_player.CALLBACK_TIMEOUT", 0
):
initial_state = hass.states.get(TEST_MASTER_ENTITY_NAME)
await _service_call(
hass,
TEST_MASTER_ENTITY_NAME,
SERVICE_PLAY_MEDIA,
{
ATTR_MEDIA_CONTENT_TYPE: MEDIA_TYPE_MUSIC,
ATTR_MEDIA_CONTENT_ID: "somefile.mp3",
},
)
state = hass.states.get(TEST_MASTER_ENTITY_NAME)
assert state.state == initial_state.state
assert state.last_updated > initial_state.last_updated | [
"async",
"def",
"test_librespot_java_play_media_pause_timeout",
"(",
"hass",
",",
"pipe_control_api_object",
")",
":",
"# test media play with pause timeout",
"pipe_control_api_object",
".",
"player_pause",
".",
"side_effect",
"=",
"None",
"with",
"patch",
"(",
"\"homeassistant.components.forked_daapd.media_player.CALLBACK_TIMEOUT\"",
",",
"0",
")",
":",
"initial_state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
"await",
"_service_call",
"(",
"hass",
",",
"TEST_MASTER_ENTITY_NAME",
",",
"SERVICE_PLAY_MEDIA",
",",
"{",
"ATTR_MEDIA_CONTENT_TYPE",
":",
"MEDIA_TYPE_MUSIC",
",",
"ATTR_MEDIA_CONTENT_ID",
":",
"\"somefile.mp3\"",
",",
"}",
",",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
"assert",
"state",
".",
"state",
"==",
"initial_state",
".",
"state",
"assert",
"state",
".",
"last_updated",
">",
"initial_state",
".",
"last_updated"
] | [
736,
0
] | [
755,
62
] | python | en | ['en', 'en', 'en'] | True |
test_unsupported_update | (hass, mock_api_object) | Test unsupported update type. | Test unsupported update type. | async def test_unsupported_update(hass, mock_api_object):
"""Test unsupported update type."""
last_updated = hass.states.get(TEST_MASTER_ENTITY_NAME).last_updated
updater_update = mock_api_object.start_websocket_handler.call_args[0][2]
await updater_update(["config"])
await hass.async_block_till_done()
assert hass.states.get(TEST_MASTER_ENTITY_NAME).last_updated == last_updated | [
"async",
"def",
"test_unsupported_update",
"(",
"hass",
",",
"mock_api_object",
")",
":",
"last_updated",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
".",
"last_updated",
"updater_update",
"=",
"mock_api_object",
".",
"start_websocket_handler",
".",
"call_args",
"[",
"0",
"]",
"[",
"2",
"]",
"await",
"updater_update",
"(",
"[",
"\"config\"",
"]",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
".",
"last_updated",
"==",
"last_updated"
] | [
758,
0
] | [
764,
80
] | python | en | ['de', 'en', 'en'] | True |
test_invalid_websocket_port | (hass, config_entry) | Test invalid websocket port on async_init. | Test invalid websocket port on async_init. | async def test_invalid_websocket_port(hass, config_entry):
"""Test invalid websocket port on async_init."""
with patch(
"homeassistant.components.forked_daapd.media_player.ForkedDaapdAPI",
autospec=True,
) as mock_api:
mock_api.return_value.get_request.return_value = SAMPLE_CONFIG_NO_WEBSOCKET
config_entry.add_to_hass(hass)
await config_entry.async_setup(hass)
await hass.async_block_till_done()
assert hass.states.get(TEST_MASTER_ENTITY_NAME).state == STATE_UNAVAILABLE | [
"async",
"def",
"test_invalid_websocket_port",
"(",
"hass",
",",
"config_entry",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.forked_daapd.media_player.ForkedDaapdAPI\"",
",",
"autospec",
"=",
"True",
",",
")",
"as",
"mock_api",
":",
"mock_api",
".",
"return_value",
".",
"get_request",
".",
"return_value",
"=",
"SAMPLE_CONFIG_NO_WEBSOCKET",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"await",
"config_entry",
".",
"async_setup",
"(",
"hass",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
".",
"state",
"==",
"STATE_UNAVAILABLE"
] | [
767,
0
] | [
777,
82
] | python | en | ['en', 'et', 'en'] | True |
test_websocket_disconnect | (hass, mock_api_object) | Test websocket disconnection. | Test websocket disconnection. | async def test_websocket_disconnect(hass, mock_api_object):
"""Test websocket disconnection."""
assert hass.states.get(TEST_MASTER_ENTITY_NAME).state != STATE_UNAVAILABLE
assert hass.states.get(TEST_ZONE_ENTITY_NAMES[0]).state != STATE_UNAVAILABLE
updater_disconnected = mock_api_object.start_websocket_handler.call_args[0][4]
updater_disconnected()
await hass.async_block_till_done()
assert hass.states.get(TEST_MASTER_ENTITY_NAME).state == STATE_UNAVAILABLE
assert hass.states.get(TEST_ZONE_ENTITY_NAMES[0]).state == STATE_UNAVAILABLE | [
"async",
"def",
"test_websocket_disconnect",
"(",
"hass",
",",
"mock_api_object",
")",
":",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
".",
"state",
"!=",
"STATE_UNAVAILABLE",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_ZONE_ENTITY_NAMES",
"[",
"0",
"]",
")",
".",
"state",
"!=",
"STATE_UNAVAILABLE",
"updater_disconnected",
"=",
"mock_api_object",
".",
"start_websocket_handler",
".",
"call_args",
"[",
"0",
"]",
"[",
"4",
"]",
"updater_disconnected",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_MASTER_ENTITY_NAME",
")",
".",
"state",
"==",
"STATE_UNAVAILABLE",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"TEST_ZONE_ENTITY_NAMES",
"[",
"0",
"]",
")",
".",
"state",
"==",
"STATE_UNAVAILABLE"
] | [
780,
0
] | [
788,
80
] | python | da | ['nl', 'da', 'en'] | False |
setup_platform | (hass, platform) | Set up the Abode platform. | Set up the Abode platform. | async def setup_platform(hass, platform):
"""Set up the Abode platform."""
mock_entry = MockConfigEntry(
domain=ABODE_DOMAIN,
data={CONF_USERNAME: "[email protected]", CONF_PASSWORD: "password"},
)
mock_entry.add_to_hass(hass)
with patch("homeassistant.components.abode.ABODE_PLATFORMS", [platform]), patch(
"abodepy.event_controller.sio"
), patch("abodepy.utils.save_cache"):
assert await async_setup_component(hass, ABODE_DOMAIN, {})
await hass.async_block_till_done()
return mock_entry | [
"async",
"def",
"setup_platform",
"(",
"hass",
",",
"platform",
")",
":",
"mock_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"ABODE_DOMAIN",
",",
"data",
"=",
"{",
"CONF_USERNAME",
":",
"\"[email protected]\"",
",",
"CONF_PASSWORD",
":",
"\"password\"",
"}",
",",
")",
"mock_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"with",
"patch",
"(",
"\"homeassistant.components.abode.ABODE_PLATFORMS\"",
",",
"[",
"platform",
"]",
")",
",",
"patch",
"(",
"\"abodepy.event_controller.sio\"",
")",
",",
"patch",
"(",
"\"abodepy.utils.save_cache\"",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"ABODE_DOMAIN",
",",
"{",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"return",
"mock_entry"
] | [
9,
0
] | [
23,
21
] | python | en | ['en', 'da', 'en'] | True |
test_change_settings | (hass) | Test change_setting service. | Test change_setting service. | async def test_change_settings(hass):
"""Test change_setting service."""
await setup_platform(hass, ALARM_DOMAIN)
with patch("abodepy.Abode.set_setting") as mock_set_setting:
await hass.services.async_call(
ABODE_DOMAIN,
SERVICE_SETTINGS,
{"setting": "confirm_snd", "value": "loud"},
blocking=True,
)
await hass.async_block_till_done()
mock_set_setting.assert_called_once() | [
"async",
"def",
"test_change_settings",
"(",
"hass",
")",
":",
"await",
"setup_platform",
"(",
"hass",
",",
"ALARM_DOMAIN",
")",
"with",
"patch",
"(",
"\"abodepy.Abode.set_setting\"",
")",
"as",
"mock_set_setting",
":",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"ABODE_DOMAIN",
",",
"SERVICE_SETTINGS",
",",
"{",
"\"setting\"",
":",
"\"confirm_snd\"",
",",
"\"value\"",
":",
"\"loud\"",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"mock_set_setting",
".",
"assert_called_once",
"(",
")"
] | [
14,
0
] | [
26,
45
] | python | en | ['en', 'en', 'en'] | True |
test_unload_entry | (hass) | Test unloading the Abode entry. | Test unloading the Abode entry. | async def test_unload_entry(hass):
"""Test unloading the Abode entry."""
mock_entry = await setup_platform(hass, ALARM_DOMAIN)
with patch("abodepy.Abode.logout") as mock_logout, patch(
"abodepy.event_controller.AbodeEventController.stop"
) as mock_events_stop:
assert await hass.config_entries.async_unload(mock_entry.entry_id)
mock_logout.assert_called_once()
mock_events_stop.assert_called_once()
assert not hass.services.has_service(ABODE_DOMAIN, SERVICE_SETTINGS)
assert not hass.services.has_service(ABODE_DOMAIN, SERVICE_CAPTURE_IMAGE)
assert not hass.services.has_service(ABODE_DOMAIN, SERVICE_TRIGGER_AUTOMATION) | [
"async",
"def",
"test_unload_entry",
"(",
"hass",
")",
":",
"mock_entry",
"=",
"await",
"setup_platform",
"(",
"hass",
",",
"ALARM_DOMAIN",
")",
"with",
"patch",
"(",
"\"abodepy.Abode.logout\"",
")",
"as",
"mock_logout",
",",
"patch",
"(",
"\"abodepy.event_controller.AbodeEventController.stop\"",
")",
"as",
"mock_events_stop",
":",
"assert",
"await",
"hass",
".",
"config_entries",
".",
"async_unload",
"(",
"mock_entry",
".",
"entry_id",
")",
"mock_logout",
".",
"assert_called_once",
"(",
")",
"mock_events_stop",
".",
"assert_called_once",
"(",
")",
"assert",
"not",
"hass",
".",
"services",
".",
"has_service",
"(",
"ABODE_DOMAIN",
",",
"SERVICE_SETTINGS",
")",
"assert",
"not",
"hass",
".",
"services",
".",
"has_service",
"(",
"ABODE_DOMAIN",
",",
"SERVICE_CAPTURE_IMAGE",
")",
"assert",
"not",
"hass",
".",
"services",
".",
"has_service",
"(",
"ABODE_DOMAIN",
",",
"SERVICE_TRIGGER_AUTOMATION",
")"
] | [
29,
0
] | [
42,
86
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Tellstick lights. | Set up the Tellstick lights. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Tellstick lights."""
if discovery_info is None or discovery_info[ATTR_DISCOVER_DEVICES] is None:
return
signal_repetitions = discovery_info.get(
ATTR_DISCOVER_CONFIG, DEFAULT_SIGNAL_REPETITIONS
)
add_entities(
[
TellstickLight(hass.data[DATA_TELLSTICK][tellcore_id], signal_repetitions)
for tellcore_id in discovery_info[ATTR_DISCOVER_DEVICES]
],
True,
) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"if",
"discovery_info",
"is",
"None",
"or",
"discovery_info",
"[",
"ATTR_DISCOVER_DEVICES",
"]",
"is",
"None",
":",
"return",
"signal_repetitions",
"=",
"discovery_info",
".",
"get",
"(",
"ATTR_DISCOVER_CONFIG",
",",
"DEFAULT_SIGNAL_REPETITIONS",
")",
"add_entities",
"(",
"[",
"TellstickLight",
"(",
"hass",
".",
"data",
"[",
"DATA_TELLSTICK",
"]",
"[",
"tellcore_id",
"]",
",",
"signal_repetitions",
")",
"for",
"tellcore_id",
"in",
"discovery_info",
"[",
"ATTR_DISCOVER_DEVICES",
"]",
"]",
",",
"True",
",",
")"
] | [
18,
0
] | [
33,
5
] | python | en | ['en', 'lb', 'en'] | True |
TellstickLight.__init__ | (self, tellcore_device, signal_repetitions) | Initialize the Tellstick light. | Initialize the Tellstick light. | def __init__(self, tellcore_device, signal_repetitions):
"""Initialize the Tellstick light."""
super().__init__(tellcore_device, signal_repetitions)
self._brightness = 255 | [
"def",
"__init__",
"(",
"self",
",",
"tellcore_device",
",",
"signal_repetitions",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"tellcore_device",
",",
"signal_repetitions",
")",
"self",
".",
"_brightness",
"=",
"255"
] | [
39,
4
] | [
43,
30
] | python | en | ['en', 'en', 'en'] | True |
TellstickLight.brightness | (self) | Return the brightness of this light between 0..255. | Return the brightness of this light between 0..255. | def brightness(self):
"""Return the brightness of this light between 0..255."""
return self._brightness | [
"def",
"brightness",
"(",
"self",
")",
":",
"return",
"self",
".",
"_brightness"
] | [
46,
4
] | [
48,
31
] | python | en | ['en', 'en', 'en'] | True |
TellstickLight.supported_features | (self) | Flag supported features. | Flag supported features. | def supported_features(self):
"""Flag supported features."""
return SUPPORT_TELLSTICK | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORT_TELLSTICK"
] | [
51,
4
] | [
53,
32
] | python | en | ['da', 'en', 'en'] | True |
TellstickLight._parse_ha_data | (self, kwargs) | Turn the value from HA into something useful. | Turn the value from HA into something useful. | def _parse_ha_data(self, kwargs):
"""Turn the value from HA into something useful."""
return kwargs.get(ATTR_BRIGHTNESS) | [
"def",
"_parse_ha_data",
"(",
"self",
",",
"kwargs",
")",
":",
"return",
"kwargs",
".",
"get",
"(",
"ATTR_BRIGHTNESS",
")"
] | [
55,
4
] | [
57,
42
] | python | en | ['en', 'en', 'en'] | True |
TellstickLight._parse_tellcore_data | (self, tellcore_data) | Turn the value received from tellcore into something useful. | Turn the value received from tellcore into something useful. | def _parse_tellcore_data(self, tellcore_data):
"""Turn the value received from tellcore into something useful."""
if tellcore_data:
return int(tellcore_data) # brightness
return None | [
"def",
"_parse_tellcore_data",
"(",
"self",
",",
"tellcore_data",
")",
":",
"if",
"tellcore_data",
":",
"return",
"int",
"(",
"tellcore_data",
")",
"# brightness",
"return",
"None"
] | [
59,
4
] | [
63,
19
] | python | en | ['en', 'en', 'en'] | True |
TellstickLight._update_model | (self, new_state, data) | Update the device entity state to match the arguments. | Update the device entity state to match the arguments. | def _update_model(self, new_state, data):
"""Update the device entity state to match the arguments."""
if new_state:
brightness = data
if brightness is not None:
self._brightness = brightness
# _brightness is not defined when called from super
try:
self._state = self._brightness > 0
except AttributeError:
self._state = True
else:
self._state = False | [
"def",
"_update_model",
"(",
"self",
",",
"new_state",
",",
"data",
")",
":",
"if",
"new_state",
":",
"brightness",
"=",
"data",
"if",
"brightness",
"is",
"not",
"None",
":",
"self",
".",
"_brightness",
"=",
"brightness",
"# _brightness is not defined when called from super",
"try",
":",
"self",
".",
"_state",
"=",
"self",
".",
"_brightness",
">",
"0",
"except",
"AttributeError",
":",
"self",
".",
"_state",
"=",
"True",
"else",
":",
"self",
".",
"_state",
"=",
"False"
] | [
65,
4
] | [
78,
31
] | python | en | ['en', 'en', 'en'] | True |
TellstickLight._send_device_command | (self, requested_state, requested_data) | Let tellcore update the actual device to the requested state. | Let tellcore update the actual device to the requested state. | def _send_device_command(self, requested_state, requested_data):
"""Let tellcore update the actual device to the requested state."""
if requested_state:
if requested_data is not None:
self._brightness = int(requested_data)
self._tellcore_device.dim(self._brightness)
else:
self._tellcore_device.turn_off() | [
"def",
"_send_device_command",
"(",
"self",
",",
"requested_state",
",",
"requested_data",
")",
":",
"if",
"requested_state",
":",
"if",
"requested_data",
"is",
"not",
"None",
":",
"self",
".",
"_brightness",
"=",
"int",
"(",
"requested_data",
")",
"self",
".",
"_tellcore_device",
".",
"dim",
"(",
"self",
".",
"_brightness",
")",
"else",
":",
"self",
".",
"_tellcore_device",
".",
"turn_off",
"(",
")"
] | [
80,
4
] | [
88,
44
] | python | en | ['en', 'en', 'en'] | True |
async_validate_password | (hass: HomeAssistant, password: str) | Return a user if password is valid. None if not. | Return a user if password is valid. None if not. | async def async_validate_password(hass: HomeAssistant, password: str) -> Optional[User]:
"""Return a user if password is valid. None if not."""
auth = cast(AuthManager, hass.auth) # type: ignore
providers = auth.get_auth_providers(AUTH_PROVIDER_TYPE)
if not providers:
raise ValueError("Legacy API password provider not found")
try:
provider = cast(LegacyApiPasswordAuthProvider, providers[0])
provider.async_validate_login(password)
return await auth.async_get_or_create_user(
await provider.async_get_or_create_credentials({})
)
except InvalidAuthError:
return None | [
"async",
"def",
"async_validate_password",
"(",
"hass",
":",
"HomeAssistant",
",",
"password",
":",
"str",
")",
"->",
"Optional",
"[",
"User",
"]",
":",
"auth",
"=",
"cast",
"(",
"AuthManager",
",",
"hass",
".",
"auth",
")",
"# type: ignore",
"providers",
"=",
"auth",
".",
"get_auth_providers",
"(",
"AUTH_PROVIDER_TYPE",
")",
"if",
"not",
"providers",
":",
"raise",
"ValueError",
"(",
"\"Legacy API password provider not found\"",
")",
"try",
":",
"provider",
"=",
"cast",
"(",
"LegacyApiPasswordAuthProvider",
",",
"providers",
"[",
"0",
"]",
")",
"provider",
".",
"async_validate_login",
"(",
"password",
")",
"return",
"await",
"auth",
".",
"async_get_or_create_user",
"(",
"await",
"provider",
".",
"async_get_or_create_credentials",
"(",
"{",
"}",
")",
")",
"except",
"InvalidAuthError",
":",
"return",
"None"
] | [
32,
0
] | [
46,
19
] | python | en | ['en', 'en', 'en'] | True |
LegacyLoginFlow.async_step_init | (
self, user_input: Optional[Dict[str, str]] = None
) | Handle the step of the form. | Handle the step of the form. | async def async_step_init(
self, user_input: Optional[Dict[str, str]] = None
) -> Dict[str, Any]:
"""Handle the step of the form."""
errors = {}
if user_input is not None:
try:
cast(
LegacyApiPasswordAuthProvider, self._auth_provider
).async_validate_login(user_input["password"])
except InvalidAuthError:
errors["base"] = "invalid_auth"
if not errors:
return await self.async_finish({})
return self.async_show_form(
step_id="init", data_schema=vol.Schema({"password": str}), errors=errors
) | [
"async",
"def",
"async_step_init",
"(",
"self",
",",
"user_input",
":",
"Optional",
"[",
"Dict",
"[",
"str",
",",
"str",
"]",
"]",
"=",
"None",
")",
"->",
"Dict",
"[",
"str",
",",
"Any",
"]",
":",
"errors",
"=",
"{",
"}",
"if",
"user_input",
"is",
"not",
"None",
":",
"try",
":",
"cast",
"(",
"LegacyApiPasswordAuthProvider",
",",
"self",
".",
"_auth_provider",
")",
".",
"async_validate_login",
"(",
"user_input",
"[",
"\"password\"",
"]",
")",
"except",
"InvalidAuthError",
":",
"errors",
"[",
"\"base\"",
"]",
"=",
"\"invalid_auth\"",
"if",
"not",
"errors",
":",
"return",
"await",
"self",
".",
"async_finish",
"(",
"{",
"}",
")",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"init\"",
",",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"{",
"\"password\"",
":",
"str",
"}",
")",
",",
"errors",
"=",
"errors",
")"
] | [
98,
4
] | [
117,
9
] | python | en | ['en', 'en', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up the KEBA charging station platform. | Set up the KEBA charging station platform. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the KEBA charging station platform."""
if discovery_info is None:
return
keba = hass.data[DOMAIN]
sensors = [KebaLock(keba, "Authentication", "authentication")]
async_add_entities(sensors) | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"if",
"discovery_info",
"is",
"None",
":",
"return",
"keba",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"sensors",
"=",
"[",
"KebaLock",
"(",
"keba",
",",
"\"Authentication\"",
",",
"\"authentication\"",
")",
"]",
"async_add_entities",
"(",
"sensors",
")"
] | [
6,
0
] | [
14,
31
] | python | en | ['en', 'da', 'en'] | True |
KebaLock.__init__ | (self, keba, name, entity_type) | Initialize the KEBA switch. | Initialize the KEBA switch. | def __init__(self, keba, name, entity_type):
"""Initialize the KEBA switch."""
self._keba = keba
self._name = name
self._entity_type = entity_type
self._state = True | [
"def",
"__init__",
"(",
"self",
",",
"keba",
",",
"name",
",",
"entity_type",
")",
":",
"self",
".",
"_keba",
"=",
"keba",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_entity_type",
"=",
"entity_type",
"self",
".",
"_state",
"=",
"True"
] | [
20,
4
] | [
25,
26
] | python | en | ['en', 'en', 'en'] | True |
KebaLock.should_poll | (self) | Deactivate polling. Data updated by KebaHandler. | Deactivate polling. Data updated by KebaHandler. | def should_poll(self):
"""Deactivate polling. Data updated by KebaHandler."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
28,
4
] | [
30,
20
] | python | en | ['en', 'en', 'en'] | True |
KebaLock.unique_id | (self) | Return the unique ID of the lock. | Return the unique ID of the lock. | def unique_id(self):
"""Return the unique ID of the lock."""
return f"{self._keba.device_id}_{self._entity_type}" | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"f\"{self._keba.device_id}_{self._entity_type}\""
] | [
33,
4
] | [
35,
60
] | python | en | ['en', 'la', 'en'] | True |
KebaLock.name | (self) | Return the name of the device. | Return the name of the device. | def name(self):
"""Return the name of the device."""
return f"{self._keba.device_name} {self._name}" | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"f\"{self._keba.device_name} {self._name}\""
] | [
38,
4
] | [
40,
55
] | python | en | ['en', 'en', 'en'] | True |
KebaLock.is_locked | (self) | Return true if lock is locked. | Return true if lock is locked. | def is_locked(self):
"""Return true if lock is locked."""
return self._state | [
"def",
"is_locked",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
43,
4
] | [
45,
26
] | python | en | ['en', 'mt', 'en'] | True |
KebaLock.async_lock | (self, **kwargs) | Lock wallbox. | Lock wallbox. | async def async_lock(self, **kwargs):
"""Lock wallbox."""
await self._keba.async_stop() | [
"async",
"def",
"async_lock",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"await",
"self",
".",
"_keba",
".",
"async_stop",
"(",
")"
] | [
47,
4
] | [
49,
37
] | python | en | ['en', 'mt', 'en'] | False |
KebaLock.async_unlock | (self, **kwargs) | Unlock wallbox. | Unlock wallbox. | async def async_unlock(self, **kwargs):
"""Unlock wallbox."""
await self._keba.async_start() | [
"async",
"def",
"async_unlock",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"await",
"self",
".",
"_keba",
".",
"async_start",
"(",
")"
] | [
51,
4
] | [
53,
38
] | python | en | ['en', 'mt', 'en'] | False |
KebaLock.async_update | (self) | Attempt to retrieve on off state from the switch. | Attempt to retrieve on off state from the switch. | async def async_update(self):
"""Attempt to retrieve on off state from the switch."""
self._state = self._keba.get_value("Authreq") == 1 | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"self",
".",
"_state",
"=",
"self",
".",
"_keba",
".",
"get_value",
"(",
"\"Authreq\"",
")",
"==",
"1"
] | [
55,
4
] | [
57,
58
] | python | en | ['en', 'en', 'en'] | True |
KebaLock.update_callback | (self) | Schedule a state update. | Schedule a state update. | def update_callback(self):
"""Schedule a state update."""
self.async_schedule_update_ha_state(True) | [
"def",
"update_callback",
"(",
"self",
")",
":",
"self",
".",
"async_schedule_update_ha_state",
"(",
"True",
")"
] | [
59,
4
] | [
61,
49
] | python | en | ['en', 'co', 'en'] | True |
KebaLock.async_added_to_hass | (self) | Add update callback after being added to hass. | Add update callback after being added to hass. | async def async_added_to_hass(self):
"""Add update callback after being added to hass."""
self._keba.add_update_listener(self.update_callback) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"self",
".",
"_keba",
".",
"add_update_listener",
"(",
"self",
".",
"update_callback",
")"
] | [
63,
4
] | [
65,
60
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities
) | Add media players for a config entry. | Add media players for a config entry. | async def async_setup_entry(
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities
):
"""Add media players for a config entry."""
players = hass.data[HEOS_DOMAIN][DOMAIN]
devices = [HeosMediaPlayer(player) for player in players.values()]
async_add_entities(devices, True) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
":",
"HomeAssistantType",
",",
"entry",
":",
"ConfigEntry",
",",
"async_add_entities",
")",
":",
"players",
"=",
"hass",
".",
"data",
"[",
"HEOS_DOMAIN",
"]",
"[",
"DOMAIN",
"]",
"devices",
"=",
"[",
"HeosMediaPlayer",
"(",
"player",
")",
"for",
"player",
"in",
"players",
".",
"values",
"(",
")",
"]",
"async_add_entities",
"(",
"devices",
",",
"True",
")"
] | [
62,
0
] | [
68,
37
] | python | en | ['en', 'en', 'en'] | True |
log_command_error | (command: str) | Return decorator that logs command failure. | Return decorator that logs command failure. | def log_command_error(command: str):
"""Return decorator that logs command failure."""
def decorator(func):
@wraps(func)
async def wrapper(*args, **kwargs):
try:
await func(*args, **kwargs)
except (HeosError, ValueError) as ex:
_LOGGER.error("Unable to %s: %s", command, ex)
return wrapper
return decorator | [
"def",
"log_command_error",
"(",
"command",
":",
"str",
")",
":",
"def",
"decorator",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"async",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"await",
"func",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"except",
"(",
"HeosError",
",",
"ValueError",
")",
"as",
"ex",
":",
"_LOGGER",
".",
"error",
"(",
"\"Unable to %s: %s\"",
",",
"command",
",",
"ex",
")",
"return",
"wrapper",
"return",
"decorator"
] | [
71,
0
] | [
84,
20
] | python | en | ['en', 'fr', 'en'] | True |
HeosMediaPlayer.__init__ | (self, player) | Initialize. | Initialize. | def __init__(self, player):
"""Initialize."""
self._media_position_updated_at = None
self._player = player
self._signals = []
self._supported_features = BASE_SUPPORTED_FEATURES
self._source_manager = None | [
"def",
"__init__",
"(",
"self",
",",
"player",
")",
":",
"self",
".",
"_media_position_updated_at",
"=",
"None",
"self",
".",
"_player",
"=",
"player",
"self",
".",
"_signals",
"=",
"[",
"]",
"self",
".",
"_supported_features",
"=",
"BASE_SUPPORTED_FEATURES",
"self",
".",
"_source_manager",
"=",
"None"
] | [
90,
4
] | [
96,
35
] | python | en | ['en', 'en', 'it'] | False |
HeosMediaPlayer._player_update | (self, player_id, event) | Handle player attribute updated. | Handle player attribute updated. | async def _player_update(self, player_id, event):
"""Handle player attribute updated."""
if self._player.player_id != player_id:
return
if event == heos_const.EVENT_PLAYER_NOW_PLAYING_PROGRESS:
self._media_position_updated_at = utcnow()
await self.async_update_ha_state(True) | [
"async",
"def",
"_player_update",
"(",
"self",
",",
"player_id",
",",
"event",
")",
":",
"if",
"self",
".",
"_player",
".",
"player_id",
"!=",
"player_id",
":",
"return",
"if",
"event",
"==",
"heos_const",
".",
"EVENT_PLAYER_NOW_PLAYING_PROGRESS",
":",
"self",
".",
"_media_position_updated_at",
"=",
"utcnow",
"(",
")",
"await",
"self",
".",
"async_update_ha_state",
"(",
"True",
")"
] | [
98,
4
] | [
104,
46
] | python | en | ['en', 'en', 'en'] | True |
HeosMediaPlayer._heos_updated | (self) | Handle sources changed. | Handle sources changed. | async def _heos_updated(self):
"""Handle sources changed."""
await self.async_update_ha_state(True) | [
"async",
"def",
"_heos_updated",
"(",
"self",
")",
":",
"await",
"self",
".",
"async_update_ha_state",
"(",
"True",
")"
] | [
106,
4
] | [
108,
46
] | python | en | ['fr', 'en', 'en'] | True |
HeosMediaPlayer.async_added_to_hass | (self) | Device added to hass. | Device added to hass. | async def async_added_to_hass(self):
"""Device added to hass."""
# Update state when attributes of the player change
self._signals.append(
self._player.heos.dispatcher.connect(
heos_const.SIGNAL_PLAYER_EVENT, self._player_update
)
)
# Update state when heos changes
self._signals.append(
self.hass.helpers.dispatcher.async_dispatcher_connect(
SIGNAL_HEOS_UPDATED, self._heos_updated
)
) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"# Update state when attributes of the player change",
"self",
".",
"_signals",
".",
"append",
"(",
"self",
".",
"_player",
".",
"heos",
".",
"dispatcher",
".",
"connect",
"(",
"heos_const",
".",
"SIGNAL_PLAYER_EVENT",
",",
"self",
".",
"_player_update",
")",
")",
"# Update state when heos changes",
"self",
".",
"_signals",
".",
"append",
"(",
"self",
".",
"hass",
".",
"helpers",
".",
"dispatcher",
".",
"async_dispatcher_connect",
"(",
"SIGNAL_HEOS_UPDATED",
",",
"self",
".",
"_heos_updated",
")",
")"
] | [
110,
4
] | [
123,
9
] | python | en | ['en', 'en', 'en'] | True |
HeosMediaPlayer.async_clear_playlist | (self) | Clear players playlist. | Clear players playlist. | async def async_clear_playlist(self):
"""Clear players playlist."""
await self._player.clear_queue() | [
"async",
"def",
"async_clear_playlist",
"(",
"self",
")",
":",
"await",
"self",
".",
"_player",
".",
"clear_queue",
"(",
")"
] | [
126,
4
] | [
128,
40
] | python | en | ['fr', 'en', 'en'] | True |
HeosMediaPlayer.async_media_pause | (self) | Send pause command. | Send pause command. | async def async_media_pause(self):
"""Send pause command."""
await self._player.pause() | [
"async",
"def",
"async_media_pause",
"(",
"self",
")",
":",
"await",
"self",
".",
"_player",
".",
"pause",
"(",
")"
] | [
131,
4
] | [
133,
34
] | python | en | ['en', 'en', 'en'] | True |
HeosMediaPlayer.async_media_play | (self) | Send play command. | Send play command. | async def async_media_play(self):
"""Send play command."""
await self._player.play() | [
"async",
"def",
"async_media_play",
"(",
"self",
")",
":",
"await",
"self",
".",
"_player",
".",
"play",
"(",
")"
] | [
136,
4
] | [
138,
33
] | python | en | ['en', 'en', 'en'] | True |
HeosMediaPlayer.async_media_previous_track | (self) | Send previous track command. | Send previous track command. | async def async_media_previous_track(self):
"""Send previous track command."""
await self._player.play_previous() | [
"async",
"def",
"async_media_previous_track",
"(",
"self",
")",
":",
"await",
"self",
".",
"_player",
".",
"play_previous",
"(",
")"
] | [
141,
4
] | [
143,
42
] | python | en | ['en', 'it', 'en'] | True |
HeosMediaPlayer.async_media_next_track | (self) | Send next track command. | Send next track command. | async def async_media_next_track(self):
"""Send next track command."""
await self._player.play_next() | [
"async",
"def",
"async_media_next_track",
"(",
"self",
")",
":",
"await",
"self",
".",
"_player",
".",
"play_next",
"(",
")"
] | [
146,
4
] | [
148,
38
] | python | en | ['en', 'pt', 'en'] | True |
HeosMediaPlayer.async_media_stop | (self) | Send stop command. | Send stop command. | async def async_media_stop(self):
"""Send stop command."""
await self._player.stop() | [
"async",
"def",
"async_media_stop",
"(",
"self",
")",
":",
"await",
"self",
".",
"_player",
".",
"stop",
"(",
")"
] | [
151,
4
] | [
153,
33
] | python | en | ['en', 'en', 'en'] | True |
HeosMediaPlayer.async_mute_volume | (self, mute) | Mute the volume. | Mute the volume. | async def async_mute_volume(self, mute):
"""Mute the volume."""
await self._player.set_mute(mute) | [
"async",
"def",
"async_mute_volume",
"(",
"self",
",",
"mute",
")",
":",
"await",
"self",
".",
"_player",
".",
"set_mute",
"(",
"mute",
")"
] | [
156,
4
] | [
158,
41
] | python | en | ['en', 'sn', 'en'] | True |
HeosMediaPlayer.async_play_media | (self, media_type, media_id, **kwargs) | Play a piece of media. | Play a piece of media. | async def async_play_media(self, media_type, media_id, **kwargs):
"""Play a piece of media."""
if media_type in (MEDIA_TYPE_URL, MEDIA_TYPE_MUSIC):
await self._player.play_url(media_id)
return
if media_type == "quick_select":
# media_id may be an int or a str
selects = await self._player.get_quick_selects()
try:
index = int(media_id)
except ValueError:
# Try finding index by name
index = next(
(index for index, select in selects.items() if select == media_id),
None,
)
if index is None:
raise ValueError(f"Invalid quick select '{media_id}'")
await self._player.play_quick_select(index)
return
if media_type == MEDIA_TYPE_PLAYLIST:
playlists = await self._player.heos.get_playlists()
playlist = next((p for p in playlists if p.name == media_id), None)
if not playlist:
raise ValueError(f"Invalid playlist '{media_id}'")
add_queue_option = (
heos_const.ADD_QUEUE_ADD_TO_END
if kwargs.get(ATTR_MEDIA_ENQUEUE)
else heos_const.ADD_QUEUE_REPLACE_AND_PLAY
)
await self._player.add_to_queue(playlist, add_queue_option)
return
if media_type == "favorite":
# media_id may be an int or str
try:
index = int(media_id)
except ValueError:
# Try finding index by name
index = next(
(
index
for index, favorite in self._source_manager.favorites.items()
if favorite.name == media_id
),
None,
)
if index is None:
raise ValueError(f"Invalid favorite '{media_id}'")
await self._player.play_favorite(index)
return
raise ValueError(f"Unsupported media type '{media_type}'") | [
"async",
"def",
"async_play_media",
"(",
"self",
",",
"media_type",
",",
"media_id",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"media_type",
"in",
"(",
"MEDIA_TYPE_URL",
",",
"MEDIA_TYPE_MUSIC",
")",
":",
"await",
"self",
".",
"_player",
".",
"play_url",
"(",
"media_id",
")",
"return",
"if",
"media_type",
"==",
"\"quick_select\"",
":",
"# media_id may be an int or a str",
"selects",
"=",
"await",
"self",
".",
"_player",
".",
"get_quick_selects",
"(",
")",
"try",
":",
"index",
"=",
"int",
"(",
"media_id",
")",
"except",
"ValueError",
":",
"# Try finding index by name",
"index",
"=",
"next",
"(",
"(",
"index",
"for",
"index",
",",
"select",
"in",
"selects",
".",
"items",
"(",
")",
"if",
"select",
"==",
"media_id",
")",
",",
"None",
",",
")",
"if",
"index",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"f\"Invalid quick select '{media_id}'\"",
")",
"await",
"self",
".",
"_player",
".",
"play_quick_select",
"(",
"index",
")",
"return",
"if",
"media_type",
"==",
"MEDIA_TYPE_PLAYLIST",
":",
"playlists",
"=",
"await",
"self",
".",
"_player",
".",
"heos",
".",
"get_playlists",
"(",
")",
"playlist",
"=",
"next",
"(",
"(",
"p",
"for",
"p",
"in",
"playlists",
"if",
"p",
".",
"name",
"==",
"media_id",
")",
",",
"None",
")",
"if",
"not",
"playlist",
":",
"raise",
"ValueError",
"(",
"f\"Invalid playlist '{media_id}'\"",
")",
"add_queue_option",
"=",
"(",
"heos_const",
".",
"ADD_QUEUE_ADD_TO_END",
"if",
"kwargs",
".",
"get",
"(",
"ATTR_MEDIA_ENQUEUE",
")",
"else",
"heos_const",
".",
"ADD_QUEUE_REPLACE_AND_PLAY",
")",
"await",
"self",
".",
"_player",
".",
"add_to_queue",
"(",
"playlist",
",",
"add_queue_option",
")",
"return",
"if",
"media_type",
"==",
"\"favorite\"",
":",
"# media_id may be an int or str",
"try",
":",
"index",
"=",
"int",
"(",
"media_id",
")",
"except",
"ValueError",
":",
"# Try finding index by name",
"index",
"=",
"next",
"(",
"(",
"index",
"for",
"index",
",",
"favorite",
"in",
"self",
".",
"_source_manager",
".",
"favorites",
".",
"items",
"(",
")",
"if",
"favorite",
".",
"name",
"==",
"media_id",
")",
",",
"None",
",",
")",
"if",
"index",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"f\"Invalid favorite '{media_id}'\"",
")",
"await",
"self",
".",
"_player",
".",
"play_favorite",
"(",
"index",
")",
"return",
"raise",
"ValueError",
"(",
"f\"Unsupported media type '{media_type}'\"",
")"
] | [
161,
4
] | [
215,
66
] | python | en | ['en', 'en', 'en'] | True |
HeosMediaPlayer.async_select_source | (self, source) | Select input source. | Select input source. | async def async_select_source(self, source):
"""Select input source."""
await self._source_manager.play_source(source, self._player) | [
"async",
"def",
"async_select_source",
"(",
"self",
",",
"source",
")",
":",
"await",
"self",
".",
"_source_manager",
".",
"play_source",
"(",
"source",
",",
"self",
".",
"_player",
")"
] | [
218,
4
] | [
220,
68
] | python | en | ['fr', 'su', 'en'] | False |
HeosMediaPlayer.async_set_shuffle | (self, shuffle) | Enable/disable shuffle mode. | Enable/disable shuffle mode. | async def async_set_shuffle(self, shuffle):
"""Enable/disable shuffle mode."""
await self._player.set_play_mode(self._player.repeat, shuffle) | [
"async",
"def",
"async_set_shuffle",
"(",
"self",
",",
"shuffle",
")",
":",
"await",
"self",
".",
"_player",
".",
"set_play_mode",
"(",
"self",
".",
"_player",
".",
"repeat",
",",
"shuffle",
")"
] | [
223,
4
] | [
225,
70
] | python | en | ['en', 'st', 'en'] | True |
HeosMediaPlayer.async_set_volume_level | (self, volume) | Set volume level, range 0..1. | Set volume level, range 0..1. | async def async_set_volume_level(self, volume):
"""Set volume level, range 0..1."""
await self._player.set_volume(int(volume * 100)) | [
"async",
"def",
"async_set_volume_level",
"(",
"self",
",",
"volume",
")",
":",
"await",
"self",
".",
"_player",
".",
"set_volume",
"(",
"int",
"(",
"volume",
"*",
"100",
")",
")"
] | [
228,
4
] | [
230,
56
] | python | en | ['fr', 'zu', 'en'] | False |
HeosMediaPlayer.async_update | (self) | Update supported features of the player. | Update supported features of the player. | async def async_update(self):
"""Update supported features of the player."""
controls = self._player.now_playing_media.supported_controls
current_support = [CONTROL_TO_SUPPORT[control] for control in controls]
self._supported_features = reduce(ior, current_support, BASE_SUPPORTED_FEATURES)
if self._source_manager is None:
self._source_manager = self.hass.data[HEOS_DOMAIN][DATA_SOURCE_MANAGER] | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"controls",
"=",
"self",
".",
"_player",
".",
"now_playing_media",
".",
"supported_controls",
"current_support",
"=",
"[",
"CONTROL_TO_SUPPORT",
"[",
"control",
"]",
"for",
"control",
"in",
"controls",
"]",
"self",
".",
"_supported_features",
"=",
"reduce",
"(",
"ior",
",",
"current_support",
",",
"BASE_SUPPORTED_FEATURES",
")",
"if",
"self",
".",
"_source_manager",
"is",
"None",
":",
"self",
".",
"_source_manager",
"=",
"self",
".",
"hass",
".",
"data",
"[",
"HEOS_DOMAIN",
"]",
"[",
"DATA_SOURCE_MANAGER",
"]"
] | [
232,
4
] | [
239,
83
] | python | en | ['en', 'en', 'en'] | True |
HeosMediaPlayer.async_will_remove_from_hass | (self) | Disconnect the device when removed. | Disconnect the device when removed. | async def async_will_remove_from_hass(self):
"""Disconnect the device when removed."""
for signal_remove in self._signals:
signal_remove()
self._signals.clear() | [
"async",
"def",
"async_will_remove_from_hass",
"(",
"self",
")",
":",
"for",
"signal_remove",
"in",
"self",
".",
"_signals",
":",
"signal_remove",
"(",
")",
"self",
".",
"_signals",
".",
"clear",
"(",
")"
] | [
241,
4
] | [
245,
29
] | python | en | ['en', 'en', 'en'] | True |
HeosMediaPlayer.available | (self) | Return True if the device is available. | Return True if the device is available. | def available(self) -> bool:
"""Return True if the device is available."""
return self._player.available | [
"def",
"available",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_player",
".",
"available"
] | [
248,
4
] | [
250,
37
] | python | en | ['en', 'en', 'en'] | True |
HeosMediaPlayer.device_info | (self) | Get attributes about the device. | Get attributes about the device. | def device_info(self) -> dict:
"""Get attributes about the device."""
return {
"identifiers": {(HEOS_DOMAIN, self._player.player_id)},
"name": self._player.name,
"model": self._player.model,
"manufacturer": "HEOS",
"sw_version": self._player.version,
} | [
"def",
"device_info",
"(",
"self",
")",
"->",
"dict",
":",
"return",
"{",
"\"identifiers\"",
":",
"{",
"(",
"HEOS_DOMAIN",
",",
"self",
".",
"_player",
".",
"player_id",
")",
"}",
",",
"\"name\"",
":",
"self",
".",
"_player",
".",
"name",
",",
"\"model\"",
":",
"self",
".",
"_player",
".",
"model",
",",
"\"manufacturer\"",
":",
"\"HEOS\"",
",",
"\"sw_version\"",
":",
"self",
".",
"_player",
".",
"version",
",",
"}"
] | [
253,
4
] | [
261,
9
] | python | en | ['en', 'en', 'en'] | True |
HeosMediaPlayer.device_state_attributes | (self) | Get additional attribute about the state. | Get additional attribute about the state. | def device_state_attributes(self) -> dict:
"""Get additional attribute about the state."""
return {
"media_album_id": self._player.now_playing_media.album_id,
"media_queue_id": self._player.now_playing_media.queue_id,
"media_source_id": self._player.now_playing_media.source_id,
"media_station": self._player.now_playing_media.station,
"media_type": self._player.now_playing_media.type,
} | [
"def",
"device_state_attributes",
"(",
"self",
")",
"->",
"dict",
":",
"return",
"{",
"\"media_album_id\"",
":",
"self",
".",
"_player",
".",
"now_playing_media",
".",
"album_id",
",",
"\"media_queue_id\"",
":",
"self",
".",
"_player",
".",
"now_playing_media",
".",
"queue_id",
",",
"\"media_source_id\"",
":",
"self",
".",
"_player",
".",
"now_playing_media",
".",
"source_id",
",",
"\"media_station\"",
":",
"self",
".",
"_player",
".",
"now_playing_media",
".",
"station",
",",
"\"media_type\"",
":",
"self",
".",
"_player",
".",
"now_playing_media",
".",
"type",
",",
"}"
] | [
264,
4
] | [
272,
9
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.