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 |
---|---|---|---|---|---|---|---|---|---|---|---|
test_form_select_hub_v2 | (hass: HomeAssistantType) | Test we set up the Hub v2 correctly. | Test we set up the Hub v2 correctly. | async def test_form_select_hub_v2(hass: HomeAssistantType):
"""Test we set up the Hub v2 correctly."""
await setup.async_setup_component(hass, "persistent_notification", {})
result = await _init_form(hass, HUB2)
result2, mock_setup, mock_setup_entry = await _device_form(
hass, result["flow_id"], mock_successful_connection, MOCK_USER_INPUT_HUB_V2
)
assert result2["type"] == "create_entry"
assert result2["data"] == {
**MOCK_USER_INPUT_HUB_V2,
CONF_HUB_VERSION: 2,
}
assert len(mock_setup.mock_calls) == 1
assert len(mock_setup_entry.mock_calls) == 1 | [
"async",
"def",
"test_form_select_hub_v2",
"(",
"hass",
":",
"HomeAssistantType",
")",
":",
"await",
"setup",
".",
"async_setup_component",
"(",
"hass",
",",
"\"persistent_notification\"",
",",
"{",
"}",
")",
"result",
"=",
"await",
"_init_form",
"(",
"hass",
",",
"HUB2",
")",
"result2",
",",
"mock_setup",
",",
"mock_setup_entry",
"=",
"await",
"_device_form",
"(",
"hass",
",",
"result",
"[",
"\"flow_id\"",
"]",
",",
"mock_successful_connection",
",",
"MOCK_USER_INPUT_HUB_V2",
")",
"assert",
"result2",
"[",
"\"type\"",
"]",
"==",
"\"create_entry\"",
"assert",
"result2",
"[",
"\"data\"",
"]",
"==",
"{",
"*",
"*",
"MOCK_USER_INPUT_HUB_V2",
",",
"CONF_HUB_VERSION",
":",
"2",
",",
"}",
"assert",
"len",
"(",
"mock_setup",
".",
"mock_calls",
")",
"==",
"1",
"assert",
"len",
"(",
"mock_setup_entry",
".",
"mock_calls",
")",
"==",
"1"
] | [
155,
0
] | [
170,
48
] | python | en | ['en', 'zu', 'en'] | True |
test_failed_connection_plm | (hass: HomeAssistantType) | Test a failed connection with the PLM. | Test a failed connection with the PLM. | async def test_failed_connection_plm(hass: HomeAssistantType):
"""Test a failed connection with the PLM."""
await setup.async_setup_component(hass, "persistent_notification", {})
result = await _init_form(hass, PLM)
result2, _, _ = await _device_form(
hass, result["flow_id"], mock_failed_connection, MOCK_USER_INPUT_PLM
)
assert result2["type"] == "form"
assert result2["errors"] == {"base": "cannot_connect"} | [
"async",
"def",
"test_failed_connection_plm",
"(",
"hass",
":",
"HomeAssistantType",
")",
":",
"await",
"setup",
".",
"async_setup_component",
"(",
"hass",
",",
"\"persistent_notification\"",
",",
"{",
"}",
")",
"result",
"=",
"await",
"_init_form",
"(",
"hass",
",",
"PLM",
")",
"result2",
",",
"_",
",",
"_",
"=",
"await",
"_device_form",
"(",
"hass",
",",
"result",
"[",
"\"flow_id\"",
"]",
",",
"mock_failed_connection",
",",
"MOCK_USER_INPUT_PLM",
")",
"assert",
"result2",
"[",
"\"type\"",
"]",
"==",
"\"form\"",
"assert",
"result2",
"[",
"\"errors\"",
"]",
"==",
"{",
"\"base\"",
":",
"\"cannot_connect\"",
"}"
] | [
173,
0
] | [
182,
58
] | python | en | ['en', 'en', 'en'] | True |
test_failed_connection_hub | (hass: HomeAssistantType) | Test a failed connection with a Hub. | Test a failed connection with a Hub. | async def test_failed_connection_hub(hass: HomeAssistantType):
"""Test a failed connection with a Hub."""
await setup.async_setup_component(hass, "persistent_notification", {})
result = await _init_form(hass, HUB2)
result2, _, _ = await _device_form(
hass, result["flow_id"], mock_failed_connection, MOCK_USER_INPUT_HUB_V2
)
assert result2["type"] == "form"
assert result2["errors"] == {"base": "cannot_connect"} | [
"async",
"def",
"test_failed_connection_hub",
"(",
"hass",
":",
"HomeAssistantType",
")",
":",
"await",
"setup",
".",
"async_setup_component",
"(",
"hass",
",",
"\"persistent_notification\"",
",",
"{",
"}",
")",
"result",
"=",
"await",
"_init_form",
"(",
"hass",
",",
"HUB2",
")",
"result2",
",",
"_",
",",
"_",
"=",
"await",
"_device_form",
"(",
"hass",
",",
"result",
"[",
"\"flow_id\"",
"]",
",",
"mock_failed_connection",
",",
"MOCK_USER_INPUT_HUB_V2",
")",
"assert",
"result2",
"[",
"\"type\"",
"]",
"==",
"\"form\"",
"assert",
"result2",
"[",
"\"errors\"",
"]",
"==",
"{",
"\"base\"",
":",
"\"cannot_connect\"",
"}"
] | [
185,
0
] | [
194,
58
] | python | en | ['en', 'ga', 'en'] | True |
_import_config | (hass, config) | Run the import step. | Run the import step. | async def _import_config(hass, config):
"""Run the import step."""
with patch(PATCH_CONNECTION, new=mock_successful_connection,), patch(
PATCH_ASYNC_SETUP, return_value=True
), patch(PATCH_ASYNC_SETUP_ENTRY, return_value=True):
return await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=config
) | [
"async",
"def",
"_import_config",
"(",
"hass",
",",
"config",
")",
":",
"with",
"patch",
"(",
"PATCH_CONNECTION",
",",
"new",
"=",
"mock_successful_connection",
",",
")",
",",
"patch",
"(",
"PATCH_ASYNC_SETUP",
",",
"return_value",
"=",
"True",
")",
",",
"patch",
"(",
"PATCH_ASYNC_SETUP_ENTRY",
",",
"return_value",
"=",
"True",
")",
":",
"return",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"config_entries",
".",
"SOURCE_IMPORT",
"}",
",",
"data",
"=",
"config",
")"
] | [
197,
0
] | [
204,
9
] | python | en | ['en', 'en', 'en'] | True |
test_import_plm | (hass: HomeAssistantType) | Test importing a minimum PLM config from yaml. | Test importing a minimum PLM config from yaml. | async def test_import_plm(hass: HomeAssistantType):
"""Test importing a minimum PLM config from yaml."""
await setup.async_setup_component(hass, "persistent_notification", {})
result = await _import_config(hass, MOCK_IMPORT_CONFIG_PLM)
assert result["type"] == "create_entry"
assert hass.config_entries.async_entries(DOMAIN)
for entry in hass.config_entries.async_entries(DOMAIN):
assert entry.data == MOCK_IMPORT_CONFIG_PLM | [
"async",
"def",
"test_import_plm",
"(",
"hass",
":",
"HomeAssistantType",
")",
":",
"await",
"setup",
".",
"async_setup_component",
"(",
"hass",
",",
"\"persistent_notification\"",
",",
"{",
"}",
")",
"result",
"=",
"await",
"_import_config",
"(",
"hass",
",",
"MOCK_IMPORT_CONFIG_PLM",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"create_entry\"",
"assert",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"DOMAIN",
")",
"for",
"entry",
"in",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"DOMAIN",
")",
":",
"assert",
"entry",
".",
"data",
"==",
"MOCK_IMPORT_CONFIG_PLM"
] | [
207,
0
] | [
216,
51
] | python | en | ['en', 'en', 'en'] | True |
_options_init_form | (hass, entry_id, step) | Run the init options form. | Run the init options form. | async def _options_init_form(hass, entry_id, step):
"""Run the init options form."""
with patch(PATCH_ASYNC_SETUP_ENTRY, return_value=True):
result = await hass.config_entries.options.async_init(entry_id)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "init"
result2 = await hass.config_entries.options.async_configure(
result["flow_id"],
{step: True},
)
return result2 | [
"async",
"def",
"_options_init_form",
"(",
"hass",
",",
"entry_id",
",",
"step",
")",
":",
"with",
"patch",
"(",
"PATCH_ASYNC_SETUP_ENTRY",
",",
"return_value",
"=",
"True",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_init",
"(",
"entry_id",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"init\"",
"result2",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"{",
"step",
":",
"True",
"}",
",",
")",
"return",
"result2"
] | [
219,
0
] | [
231,
18
] | python | en | ['en', 'en', 'en'] | True |
test_import_min_hub_v2 | (hass: HomeAssistantType) | Test importing a minimum Hub v2 config from yaml. | Test importing a minimum Hub v2 config from yaml. | async def test_import_min_hub_v2(hass: HomeAssistantType):
"""Test importing a minimum Hub v2 config from yaml."""
await setup.async_setup_component(hass, "persistent_notification", {})
result = await _import_config(
hass, {**MOCK_IMPORT_MINIMUM_HUB_V2, CONF_PORT: 25105, CONF_HUB_VERSION: 2}
)
assert result["type"] == "create_entry"
assert hass.config_entries.async_entries(DOMAIN)
for entry in hass.config_entries.async_entries(DOMAIN):
assert entry.data[CONF_HOST] == MOCK_HOSTNAME
assert entry.data[CONF_PORT] == 25105
assert entry.data[CONF_USERNAME] == MOCK_USERNAME
assert entry.data[CONF_PASSWORD] == MOCK_PASSWORD
assert entry.data[CONF_HUB_VERSION] == 2 | [
"async",
"def",
"test_import_min_hub_v2",
"(",
"hass",
":",
"HomeAssistantType",
")",
":",
"await",
"setup",
".",
"async_setup_component",
"(",
"hass",
",",
"\"persistent_notification\"",
",",
"{",
"}",
")",
"result",
"=",
"await",
"_import_config",
"(",
"hass",
",",
"{",
"*",
"*",
"MOCK_IMPORT_MINIMUM_HUB_V2",
",",
"CONF_PORT",
":",
"25105",
",",
"CONF_HUB_VERSION",
":",
"2",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"create_entry\"",
"assert",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"DOMAIN",
")",
"for",
"entry",
"in",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"DOMAIN",
")",
":",
"assert",
"entry",
".",
"data",
"[",
"CONF_HOST",
"]",
"==",
"MOCK_HOSTNAME",
"assert",
"entry",
".",
"data",
"[",
"CONF_PORT",
"]",
"==",
"25105",
"assert",
"entry",
".",
"data",
"[",
"CONF_USERNAME",
"]",
"==",
"MOCK_USERNAME",
"assert",
"entry",
".",
"data",
"[",
"CONF_PASSWORD",
"]",
"==",
"MOCK_PASSWORD",
"assert",
"entry",
".",
"data",
"[",
"CONF_HUB_VERSION",
"]",
"==",
"2"
] | [
234,
0
] | [
249,
48
] | python | en | ['en', 'en', 'en'] | True |
test_import_min_hub_v1 | (hass: HomeAssistantType) | Test importing a minimum Hub v1 config from yaml. | Test importing a minimum Hub v1 config from yaml. | async def test_import_min_hub_v1(hass: HomeAssistantType):
"""Test importing a minimum Hub v1 config from yaml."""
await setup.async_setup_component(hass, "persistent_notification", {})
result = await _import_config(
hass, {**MOCK_IMPORT_MINIMUM_HUB_V1, CONF_PORT: 9761, CONF_HUB_VERSION: 1}
)
assert result["type"] == "create_entry"
assert hass.config_entries.async_entries(DOMAIN)
for entry in hass.config_entries.async_entries(DOMAIN):
assert entry.data[CONF_HOST] == MOCK_HOSTNAME
assert entry.data[CONF_PORT] == 9761
assert entry.data[CONF_HUB_VERSION] == 1 | [
"async",
"def",
"test_import_min_hub_v1",
"(",
"hass",
":",
"HomeAssistantType",
")",
":",
"await",
"setup",
".",
"async_setup_component",
"(",
"hass",
",",
"\"persistent_notification\"",
",",
"{",
"}",
")",
"result",
"=",
"await",
"_import_config",
"(",
"hass",
",",
"{",
"*",
"*",
"MOCK_IMPORT_MINIMUM_HUB_V1",
",",
"CONF_PORT",
":",
"9761",
",",
"CONF_HUB_VERSION",
":",
"1",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"create_entry\"",
"assert",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"DOMAIN",
")",
"for",
"entry",
"in",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"DOMAIN",
")",
":",
"assert",
"entry",
".",
"data",
"[",
"CONF_HOST",
"]",
"==",
"MOCK_HOSTNAME",
"assert",
"entry",
".",
"data",
"[",
"CONF_PORT",
"]",
"==",
"9761",
"assert",
"entry",
".",
"data",
"[",
"CONF_HUB_VERSION",
"]",
"==",
"1"
] | [
252,
0
] | [
265,
48
] | python | en | ['en', 'en', 'en'] | True |
test_import_existing | (hass: HomeAssistantType) | Test we fail on an existing config imported. | Test we fail on an existing config imported. | async def test_import_existing(hass: HomeAssistantType):
"""Test we fail on an existing config imported."""
config_entry = MockConfigEntry(
domain=DOMAIN,
entry_id="abcde12345",
data={**MOCK_USER_INPUT_HUB_V2, CONF_HUB_VERSION: 2},
options={},
)
config_entry.add_to_hass(hass)
assert config_entry.state == config_entries.ENTRY_STATE_NOT_LOADED
result = await _import_config(
hass, {**MOCK_IMPORT_MINIMUM_HUB_V2, CONF_PORT: 25105, CONF_HUB_VERSION: 2}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "single_instance_allowed" | [
"async",
"def",
"test_import_existing",
"(",
"hass",
":",
"HomeAssistantType",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"entry_id",
"=",
"\"abcde12345\"",
",",
"data",
"=",
"{",
"*",
"*",
"MOCK_USER_INPUT_HUB_V2",
",",
"CONF_HUB_VERSION",
":",
"2",
"}",
",",
"options",
"=",
"{",
"}",
",",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"assert",
"config_entry",
".",
"state",
"==",
"config_entries",
".",
"ENTRY_STATE_NOT_LOADED",
"result",
"=",
"await",
"_import_config",
"(",
"hass",
",",
"{",
"*",
"*",
"MOCK_IMPORT_MINIMUM_HUB_V2",
",",
"CONF_PORT",
":",
"25105",
",",
"CONF_HUB_VERSION",
":",
"2",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_ABORT",
"assert",
"result",
"[",
"\"reason\"",
"]",
"==",
"\"single_instance_allowed\""
] | [
268,
0
] | [
283,
56
] | python | en | ['en', 'en', 'en'] | True |
test_import_failed_connection | (hass: HomeAssistantType) | Test a failed connection on import. | Test a failed connection on import. | async def test_import_failed_connection(hass: HomeAssistantType):
"""Test a failed connection on import."""
await setup.async_setup_component(hass, "persistent_notification", {})
with patch(PATCH_CONNECTION, new=mock_failed_connection,), patch(
PATCH_ASYNC_SETUP, return_value=True
), patch(PATCH_ASYNC_SETUP_ENTRY, return_value=True):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data={**MOCK_IMPORT_MINIMUM_HUB_V2, CONF_PORT: 25105, CONF_HUB_VERSION: 2},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "cannot_connect" | [
"async",
"def",
"test_import_failed_connection",
"(",
"hass",
":",
"HomeAssistantType",
")",
":",
"await",
"setup",
".",
"async_setup_component",
"(",
"hass",
",",
"\"persistent_notification\"",
",",
"{",
"}",
")",
"with",
"patch",
"(",
"PATCH_CONNECTION",
",",
"new",
"=",
"mock_failed_connection",
",",
")",
",",
"patch",
"(",
"PATCH_ASYNC_SETUP",
",",
"return_value",
"=",
"True",
")",
",",
"patch",
"(",
"PATCH_ASYNC_SETUP_ENTRY",
",",
"return_value",
"=",
"True",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"config_entries",
".",
"SOURCE_IMPORT",
"}",
",",
"data",
"=",
"{",
"*",
"*",
"MOCK_IMPORT_MINIMUM_HUB_V2",
",",
"CONF_PORT",
":",
"25105",
",",
"CONF_HUB_VERSION",
":",
"2",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_ABORT",
"assert",
"result",
"[",
"\"reason\"",
"]",
"==",
"\"cannot_connect\""
] | [
286,
0
] | [
300,
47
] | python | en | ['en', 'en', 'en'] | True |
_options_form | (hass, flow_id, user_input) | Test an options form. | Test an options form. | async def _options_form(hass, flow_id, user_input):
"""Test an options form."""
with patch(PATCH_ASYNC_SETUP_ENTRY, return_value=True) as mock_setup_entry:
result = await hass.config_entries.options.async_configure(flow_id, user_input)
return result, mock_setup_entry | [
"async",
"def",
"_options_form",
"(",
"hass",
",",
"flow_id",
",",
"user_input",
")",
":",
"with",
"patch",
"(",
"PATCH_ASYNC_SETUP_ENTRY",
",",
"return_value",
"=",
"True",
")",
"as",
"mock_setup_entry",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_configure",
"(",
"flow_id",
",",
"user_input",
")",
"return",
"result",
",",
"mock_setup_entry"
] | [
303,
0
] | [
308,
39
] | python | en | ['en', 'en', 'en'] | True |
test_options_change_hub_config | (hass: HomeAssistantType) | Test changing Hub v2 config. | Test changing Hub v2 config. | async def test_options_change_hub_config(hass: HomeAssistantType):
"""Test changing Hub v2 config."""
config_entry = MockConfigEntry(
domain=DOMAIN,
entry_id="abcde12345",
data={**MOCK_USER_INPUT_HUB_V2, CONF_HUB_VERSION: 2},
options={},
)
config_entry.add_to_hass(hass)
result = await _options_init_form(
hass, config_entry.entry_id, STEP_CHANGE_HUB_CONFIG
)
user_input = {
CONF_HOST: "2.3.4.5",
CONF_PORT: 9999,
CONF_USERNAME: "new username",
CONF_PASSWORD: "new password",
}
result, _ = await _options_form(hass, result["flow_id"], user_input)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert config_entry.options == {}
assert config_entry.data == {**user_input, CONF_HUB_VERSION: 2} | [
"async",
"def",
"test_options_change_hub_config",
"(",
"hass",
":",
"HomeAssistantType",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"entry_id",
"=",
"\"abcde12345\"",
",",
"data",
"=",
"{",
"*",
"*",
"MOCK_USER_INPUT_HUB_V2",
",",
"CONF_HUB_VERSION",
":",
"2",
"}",
",",
"options",
"=",
"{",
"}",
",",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"result",
"=",
"await",
"_options_init_form",
"(",
"hass",
",",
"config_entry",
".",
"entry_id",
",",
"STEP_CHANGE_HUB_CONFIG",
")",
"user_input",
"=",
"{",
"CONF_HOST",
":",
"\"2.3.4.5\"",
",",
"CONF_PORT",
":",
"9999",
",",
"CONF_USERNAME",
":",
"\"new username\"",
",",
"CONF_PASSWORD",
":",
"\"new password\"",
",",
"}",
"result",
",",
"_",
"=",
"await",
"_options_form",
"(",
"hass",
",",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"config_entry",
".",
"options",
"==",
"{",
"}",
"assert",
"config_entry",
".",
"data",
"==",
"{",
"*",
"*",
"user_input",
",",
"CONF_HUB_VERSION",
":",
"2",
"}"
] | [
311,
0
] | [
335,
67
] | python | en | ['en', 'da', 'en'] | True |
test_options_add_device_override | (hass: HomeAssistantType) | Test adding a device override. | Test adding a device override. | async def test_options_add_device_override(hass: HomeAssistantType):
"""Test adding a device override."""
config_entry = MockConfigEntry(
domain=DOMAIN,
entry_id="abcde12345",
data={**MOCK_USER_INPUT_HUB_V2, CONF_HUB_VERSION: 2},
options={},
)
config_entry.add_to_hass(hass)
result = await _options_init_form(hass, config_entry.entry_id, STEP_ADD_OVERRIDE)
user_input = {
CONF_ADDRESS: "1a2b3c",
CONF_CAT: "0x04",
CONF_SUBCAT: "0xaa",
}
result, _ = await _options_form(hass, result["flow_id"], user_input)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert len(config_entry.options[CONF_OVERRIDE]) == 1
assert config_entry.options[CONF_OVERRIDE][0][CONF_ADDRESS] == "1A.2B.3C"
assert config_entry.options[CONF_OVERRIDE][0][CONF_CAT] == 4
assert config_entry.options[CONF_OVERRIDE][0][CONF_SUBCAT] == 170
result2 = await _options_init_form(hass, config_entry.entry_id, STEP_ADD_OVERRIDE)
user_input = {
CONF_ADDRESS: "4d5e6f",
CONF_CAT: "05",
CONF_SUBCAT: "bb",
}
await _options_form(hass, result2["flow_id"], user_input)
assert len(config_entry.options[CONF_OVERRIDE]) == 2
assert config_entry.options[CONF_OVERRIDE][1][CONF_ADDRESS] == "4D.5E.6F"
assert config_entry.options[CONF_OVERRIDE][1][CONF_CAT] == 5
assert config_entry.options[CONF_OVERRIDE][1][CONF_SUBCAT] == 187 | [
"async",
"def",
"test_options_add_device_override",
"(",
"hass",
":",
"HomeAssistantType",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"entry_id",
"=",
"\"abcde12345\"",
",",
"data",
"=",
"{",
"*",
"*",
"MOCK_USER_INPUT_HUB_V2",
",",
"CONF_HUB_VERSION",
":",
"2",
"}",
",",
"options",
"=",
"{",
"}",
",",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"result",
"=",
"await",
"_options_init_form",
"(",
"hass",
",",
"config_entry",
".",
"entry_id",
",",
"STEP_ADD_OVERRIDE",
")",
"user_input",
"=",
"{",
"CONF_ADDRESS",
":",
"\"1a2b3c\"",
",",
"CONF_CAT",
":",
"\"0x04\"",
",",
"CONF_SUBCAT",
":",
"\"0xaa\"",
",",
"}",
"result",
",",
"_",
"=",
"await",
"_options_form",
"(",
"hass",
",",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"len",
"(",
"config_entry",
".",
"options",
"[",
"CONF_OVERRIDE",
"]",
")",
"==",
"1",
"assert",
"config_entry",
".",
"options",
"[",
"CONF_OVERRIDE",
"]",
"[",
"0",
"]",
"[",
"CONF_ADDRESS",
"]",
"==",
"\"1A.2B.3C\"",
"assert",
"config_entry",
".",
"options",
"[",
"CONF_OVERRIDE",
"]",
"[",
"0",
"]",
"[",
"CONF_CAT",
"]",
"==",
"4",
"assert",
"config_entry",
".",
"options",
"[",
"CONF_OVERRIDE",
"]",
"[",
"0",
"]",
"[",
"CONF_SUBCAT",
"]",
"==",
"170",
"result2",
"=",
"await",
"_options_init_form",
"(",
"hass",
",",
"config_entry",
".",
"entry_id",
",",
"STEP_ADD_OVERRIDE",
")",
"user_input",
"=",
"{",
"CONF_ADDRESS",
":",
"\"4d5e6f\"",
",",
"CONF_CAT",
":",
"\"05\"",
",",
"CONF_SUBCAT",
":",
"\"bb\"",
",",
"}",
"await",
"_options_form",
"(",
"hass",
",",
"result2",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
")",
"assert",
"len",
"(",
"config_entry",
".",
"options",
"[",
"CONF_OVERRIDE",
"]",
")",
"==",
"2",
"assert",
"config_entry",
".",
"options",
"[",
"CONF_OVERRIDE",
"]",
"[",
"1",
"]",
"[",
"CONF_ADDRESS",
"]",
"==",
"\"4D.5E.6F\"",
"assert",
"config_entry",
".",
"options",
"[",
"CONF_OVERRIDE",
"]",
"[",
"1",
"]",
"[",
"CONF_CAT",
"]",
"==",
"5",
"assert",
"config_entry",
".",
"options",
"[",
"CONF_OVERRIDE",
"]",
"[",
"1",
"]",
"[",
"CONF_SUBCAT",
"]",
"==",
"187"
] | [
338,
0
] | [
375,
69
] | python | en | ['es', 'en', 'en'] | True |
test_options_remove_device_override | (hass: HomeAssistantType) | Test removing a device override. | Test removing a device override. | async def test_options_remove_device_override(hass: HomeAssistantType):
"""Test removing a device override."""
config_entry = MockConfigEntry(
domain=DOMAIN,
entry_id="abcde12345",
data={**MOCK_USER_INPUT_HUB_V2, CONF_HUB_VERSION: 2},
options={
CONF_OVERRIDE: [
{CONF_ADDRESS: "1A.2B.3C", CONF_CAT: 6, CONF_SUBCAT: 100},
{CONF_ADDRESS: "4D.5E.6F", CONF_CAT: 7, CONF_SUBCAT: 200},
]
},
)
config_entry.add_to_hass(hass)
result = await _options_init_form(hass, config_entry.entry_id, STEP_REMOVE_OVERRIDE)
user_input = {CONF_ADDRESS: "1A.2B.3C"}
result, _ = await _options_form(hass, result["flow_id"], user_input)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert len(config_entry.options[CONF_OVERRIDE]) == 1 | [
"async",
"def",
"test_options_remove_device_override",
"(",
"hass",
":",
"HomeAssistantType",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"entry_id",
"=",
"\"abcde12345\"",
",",
"data",
"=",
"{",
"*",
"*",
"MOCK_USER_INPUT_HUB_V2",
",",
"CONF_HUB_VERSION",
":",
"2",
"}",
",",
"options",
"=",
"{",
"CONF_OVERRIDE",
":",
"[",
"{",
"CONF_ADDRESS",
":",
"\"1A.2B.3C\"",
",",
"CONF_CAT",
":",
"6",
",",
"CONF_SUBCAT",
":",
"100",
"}",
",",
"{",
"CONF_ADDRESS",
":",
"\"4D.5E.6F\"",
",",
"CONF_CAT",
":",
"7",
",",
"CONF_SUBCAT",
":",
"200",
"}",
",",
"]",
"}",
",",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"result",
"=",
"await",
"_options_init_form",
"(",
"hass",
",",
"config_entry",
".",
"entry_id",
",",
"STEP_REMOVE_OVERRIDE",
")",
"user_input",
"=",
"{",
"CONF_ADDRESS",
":",
"\"1A.2B.3C\"",
"}",
"result",
",",
"_",
"=",
"await",
"_options_form",
"(",
"hass",
",",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"len",
"(",
"config_entry",
".",
"options",
"[",
"CONF_OVERRIDE",
"]",
")",
"==",
"1"
] | [
378,
0
] | [
399,
56
] | python | en | ['en', 'en', 'en'] | True |
test_options_remove_device_override_with_x10 | (hass: HomeAssistantType) | Test removing a device override when an X10 device is configured. | Test removing a device override when an X10 device is configured. | async def test_options_remove_device_override_with_x10(hass: HomeAssistantType):
"""Test removing a device override when an X10 device is configured."""
config_entry = MockConfigEntry(
domain=DOMAIN,
entry_id="abcde12345",
data={**MOCK_USER_INPUT_HUB_V2, CONF_HUB_VERSION: 2},
options={
CONF_OVERRIDE: [
{CONF_ADDRESS: "1A.2B.3C", CONF_CAT: 6, CONF_SUBCAT: 100},
{CONF_ADDRESS: "4D.5E.6F", CONF_CAT: 7, CONF_SUBCAT: 200},
],
CONF_X10: [
{
CONF_HOUSECODE: "d",
CONF_UNITCODE: 5,
CONF_PLATFORM: "light",
CONF_DIM_STEPS: 22,
}
],
},
)
config_entry.add_to_hass(hass)
result = await _options_init_form(hass, config_entry.entry_id, STEP_REMOVE_OVERRIDE)
user_input = {CONF_ADDRESS: "1A.2B.3C"}
result, _ = await _options_form(hass, result["flow_id"], user_input)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert len(config_entry.options[CONF_OVERRIDE]) == 1
assert len(config_entry.options[CONF_X10]) == 1 | [
"async",
"def",
"test_options_remove_device_override_with_x10",
"(",
"hass",
":",
"HomeAssistantType",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"entry_id",
"=",
"\"abcde12345\"",
",",
"data",
"=",
"{",
"*",
"*",
"MOCK_USER_INPUT_HUB_V2",
",",
"CONF_HUB_VERSION",
":",
"2",
"}",
",",
"options",
"=",
"{",
"CONF_OVERRIDE",
":",
"[",
"{",
"CONF_ADDRESS",
":",
"\"1A.2B.3C\"",
",",
"CONF_CAT",
":",
"6",
",",
"CONF_SUBCAT",
":",
"100",
"}",
",",
"{",
"CONF_ADDRESS",
":",
"\"4D.5E.6F\"",
",",
"CONF_CAT",
":",
"7",
",",
"CONF_SUBCAT",
":",
"200",
"}",
",",
"]",
",",
"CONF_X10",
":",
"[",
"{",
"CONF_HOUSECODE",
":",
"\"d\"",
",",
"CONF_UNITCODE",
":",
"5",
",",
"CONF_PLATFORM",
":",
"\"light\"",
",",
"CONF_DIM_STEPS",
":",
"22",
",",
"}",
"]",
",",
"}",
",",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"result",
"=",
"await",
"_options_init_form",
"(",
"hass",
",",
"config_entry",
".",
"entry_id",
",",
"STEP_REMOVE_OVERRIDE",
")",
"user_input",
"=",
"{",
"CONF_ADDRESS",
":",
"\"1A.2B.3C\"",
"}",
"result",
",",
"_",
"=",
"await",
"_options_form",
"(",
"hass",
",",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"len",
"(",
"config_entry",
".",
"options",
"[",
"CONF_OVERRIDE",
"]",
")",
"==",
"1",
"assert",
"len",
"(",
"config_entry",
".",
"options",
"[",
"CONF_X10",
"]",
")",
"==",
"1"
] | [
402,
0
] | [
432,
51
] | python | en | ['en', 'en', 'en'] | True |
test_options_add_x10_device | (hass: HomeAssistantType) | Test adding an X10 device. | Test adding an X10 device. | async def test_options_add_x10_device(hass: HomeAssistantType):
"""Test adding an X10 device."""
config_entry = MockConfigEntry(
domain=DOMAIN,
entry_id="abcde12345",
data={**MOCK_USER_INPUT_HUB_V2, CONF_HUB_VERSION: 2},
options={},
)
config_entry.add_to_hass(hass)
result = await _options_init_form(hass, config_entry.entry_id, STEP_ADD_X10)
user_input = {
CONF_HOUSECODE: "c",
CONF_UNITCODE: 12,
CONF_PLATFORM: "light",
CONF_DIM_STEPS: 18,
}
result2, _ = await _options_form(hass, result["flow_id"], user_input)
assert result2["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert len(config_entry.options[CONF_X10]) == 1
assert config_entry.options[CONF_X10][0][CONF_HOUSECODE] == "c"
assert config_entry.options[CONF_X10][0][CONF_UNITCODE] == 12
assert config_entry.options[CONF_X10][0][CONF_PLATFORM] == "light"
assert config_entry.options[CONF_X10][0][CONF_DIM_STEPS] == 18
result = await _options_init_form(hass, config_entry.entry_id, STEP_ADD_X10)
user_input = {
CONF_HOUSECODE: "d",
CONF_UNITCODE: 10,
CONF_PLATFORM: "binary_sensor",
CONF_DIM_STEPS: 15,
}
result3, _ = await _options_form(hass, result["flow_id"], user_input)
assert result3["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert len(config_entry.options[CONF_X10]) == 2
assert config_entry.options[CONF_X10][1][CONF_HOUSECODE] == "d"
assert config_entry.options[CONF_X10][1][CONF_UNITCODE] == 10
assert config_entry.options[CONF_X10][1][CONF_PLATFORM] == "binary_sensor"
assert config_entry.options[CONF_X10][1][CONF_DIM_STEPS] == 15 | [
"async",
"def",
"test_options_add_x10_device",
"(",
"hass",
":",
"HomeAssistantType",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"entry_id",
"=",
"\"abcde12345\"",
",",
"data",
"=",
"{",
"*",
"*",
"MOCK_USER_INPUT_HUB_V2",
",",
"CONF_HUB_VERSION",
":",
"2",
"}",
",",
"options",
"=",
"{",
"}",
",",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"result",
"=",
"await",
"_options_init_form",
"(",
"hass",
",",
"config_entry",
".",
"entry_id",
",",
"STEP_ADD_X10",
")",
"user_input",
"=",
"{",
"CONF_HOUSECODE",
":",
"\"c\"",
",",
"CONF_UNITCODE",
":",
"12",
",",
"CONF_PLATFORM",
":",
"\"light\"",
",",
"CONF_DIM_STEPS",
":",
"18",
",",
"}",
"result2",
",",
"_",
"=",
"await",
"_options_form",
"(",
"hass",
",",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
")",
"assert",
"result2",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"len",
"(",
"config_entry",
".",
"options",
"[",
"CONF_X10",
"]",
")",
"==",
"1",
"assert",
"config_entry",
".",
"options",
"[",
"CONF_X10",
"]",
"[",
"0",
"]",
"[",
"CONF_HOUSECODE",
"]",
"==",
"\"c\"",
"assert",
"config_entry",
".",
"options",
"[",
"CONF_X10",
"]",
"[",
"0",
"]",
"[",
"CONF_UNITCODE",
"]",
"==",
"12",
"assert",
"config_entry",
".",
"options",
"[",
"CONF_X10",
"]",
"[",
"0",
"]",
"[",
"CONF_PLATFORM",
"]",
"==",
"\"light\"",
"assert",
"config_entry",
".",
"options",
"[",
"CONF_X10",
"]",
"[",
"0",
"]",
"[",
"CONF_DIM_STEPS",
"]",
"==",
"18",
"result",
"=",
"await",
"_options_init_form",
"(",
"hass",
",",
"config_entry",
".",
"entry_id",
",",
"STEP_ADD_X10",
")",
"user_input",
"=",
"{",
"CONF_HOUSECODE",
":",
"\"d\"",
",",
"CONF_UNITCODE",
":",
"10",
",",
"CONF_PLATFORM",
":",
"\"binary_sensor\"",
",",
"CONF_DIM_STEPS",
":",
"15",
",",
"}",
"result3",
",",
"_",
"=",
"await",
"_options_form",
"(",
"hass",
",",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
")",
"assert",
"result3",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"len",
"(",
"config_entry",
".",
"options",
"[",
"CONF_X10",
"]",
")",
"==",
"2",
"assert",
"config_entry",
".",
"options",
"[",
"CONF_X10",
"]",
"[",
"1",
"]",
"[",
"CONF_HOUSECODE",
"]",
"==",
"\"d\"",
"assert",
"config_entry",
".",
"options",
"[",
"CONF_X10",
"]",
"[",
"1",
"]",
"[",
"CONF_UNITCODE",
"]",
"==",
"10",
"assert",
"config_entry",
".",
"options",
"[",
"CONF_X10",
"]",
"[",
"1",
"]",
"[",
"CONF_PLATFORM",
"]",
"==",
"\"binary_sensor\"",
"assert",
"config_entry",
".",
"options",
"[",
"CONF_X10",
"]",
"[",
"1",
"]",
"[",
"CONF_DIM_STEPS",
"]",
"==",
"15"
] | [
435,
0
] | [
476,
66
] | python | en | ['en', 'lb', 'en'] | True |
test_options_remove_x10_device | (hass: HomeAssistantType) | Test removing an X10 device. | Test removing an X10 device. | async def test_options_remove_x10_device(hass: HomeAssistantType):
"""Test removing an X10 device."""
config_entry = MockConfigEntry(
domain=DOMAIN,
entry_id="abcde12345",
data={**MOCK_USER_INPUT_HUB_V2, CONF_HUB_VERSION: 2},
options={
CONF_X10: [
{
CONF_HOUSECODE: "C",
CONF_UNITCODE: 4,
CONF_PLATFORM: "light",
CONF_DIM_STEPS: 18,
},
{
CONF_HOUSECODE: "D",
CONF_UNITCODE: 10,
CONF_PLATFORM: "binary_sensor",
CONF_DIM_STEPS: 15,
},
]
},
)
config_entry.add_to_hass(hass)
result = await _options_init_form(hass, config_entry.entry_id, STEP_REMOVE_X10)
for device in config_entry.options[CONF_X10]:
housecode = device[CONF_HOUSECODE].upper()
unitcode = device[CONF_UNITCODE]
print(f"Housecode: {housecode}, Unitcode: {unitcode}")
user_input = {CONF_DEVICE: "Housecode: C, Unitcode: 4"}
result, _ = await _options_form(hass, result["flow_id"], user_input)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert len(config_entry.options[CONF_X10]) == 1 | [
"async",
"def",
"test_options_remove_x10_device",
"(",
"hass",
":",
"HomeAssistantType",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"entry_id",
"=",
"\"abcde12345\"",
",",
"data",
"=",
"{",
"*",
"*",
"MOCK_USER_INPUT_HUB_V2",
",",
"CONF_HUB_VERSION",
":",
"2",
"}",
",",
"options",
"=",
"{",
"CONF_X10",
":",
"[",
"{",
"CONF_HOUSECODE",
":",
"\"C\"",
",",
"CONF_UNITCODE",
":",
"4",
",",
"CONF_PLATFORM",
":",
"\"light\"",
",",
"CONF_DIM_STEPS",
":",
"18",
",",
"}",
",",
"{",
"CONF_HOUSECODE",
":",
"\"D\"",
",",
"CONF_UNITCODE",
":",
"10",
",",
"CONF_PLATFORM",
":",
"\"binary_sensor\"",
",",
"CONF_DIM_STEPS",
":",
"15",
",",
"}",
",",
"]",
"}",
",",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"result",
"=",
"await",
"_options_init_form",
"(",
"hass",
",",
"config_entry",
".",
"entry_id",
",",
"STEP_REMOVE_X10",
")",
"for",
"device",
"in",
"config_entry",
".",
"options",
"[",
"CONF_X10",
"]",
":",
"housecode",
"=",
"device",
"[",
"CONF_HOUSECODE",
"]",
".",
"upper",
"(",
")",
"unitcode",
"=",
"device",
"[",
"CONF_UNITCODE",
"]",
"print",
"(",
"f\"Housecode: {housecode}, Unitcode: {unitcode}\"",
")",
"user_input",
"=",
"{",
"CONF_DEVICE",
":",
"\"Housecode: C, Unitcode: 4\"",
"}",
"result",
",",
"_",
"=",
"await",
"_options_form",
"(",
"hass",
",",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"len",
"(",
"config_entry",
".",
"options",
"[",
"CONF_X10",
"]",
")",
"==",
"1"
] | [
479,
0
] | [
515,
51
] | python | en | ['en', 'en', 'en'] | True |
test_options_remove_x10_device_with_override | (hass: HomeAssistantType) | Test removing an X10 device when a device override is configured. | Test removing an X10 device when a device override is configured. | async def test_options_remove_x10_device_with_override(hass: HomeAssistantType):
"""Test removing an X10 device when a device override is configured."""
config_entry = MockConfigEntry(
domain=DOMAIN,
entry_id="abcde12345",
data={**MOCK_USER_INPUT_HUB_V2, CONF_HUB_VERSION: 2},
options={
CONF_X10: [
{
CONF_HOUSECODE: "C",
CONF_UNITCODE: 4,
CONF_PLATFORM: "light",
CONF_DIM_STEPS: 18,
},
{
CONF_HOUSECODE: "D",
CONF_UNITCODE: 10,
CONF_PLATFORM: "binary_sensor",
CONF_DIM_STEPS: 15,
},
],
CONF_OVERRIDE: [{CONF_ADDRESS: "1A.2B.3C", CONF_CAT: 1, CONF_SUBCAT: 18}],
},
)
config_entry.add_to_hass(hass)
result = await _options_init_form(hass, config_entry.entry_id, STEP_REMOVE_X10)
for device in config_entry.options[CONF_X10]:
housecode = device[CONF_HOUSECODE].upper()
unitcode = device[CONF_UNITCODE]
print(f"Housecode: {housecode}, Unitcode: {unitcode}")
user_input = {CONF_DEVICE: "Housecode: C, Unitcode: 4"}
result, _ = await _options_form(hass, result["flow_id"], user_input)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert len(config_entry.options[CONF_X10]) == 1
assert len(config_entry.options[CONF_OVERRIDE]) == 1 | [
"async",
"def",
"test_options_remove_x10_device_with_override",
"(",
"hass",
":",
"HomeAssistantType",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"entry_id",
"=",
"\"abcde12345\"",
",",
"data",
"=",
"{",
"*",
"*",
"MOCK_USER_INPUT_HUB_V2",
",",
"CONF_HUB_VERSION",
":",
"2",
"}",
",",
"options",
"=",
"{",
"CONF_X10",
":",
"[",
"{",
"CONF_HOUSECODE",
":",
"\"C\"",
",",
"CONF_UNITCODE",
":",
"4",
",",
"CONF_PLATFORM",
":",
"\"light\"",
",",
"CONF_DIM_STEPS",
":",
"18",
",",
"}",
",",
"{",
"CONF_HOUSECODE",
":",
"\"D\"",
",",
"CONF_UNITCODE",
":",
"10",
",",
"CONF_PLATFORM",
":",
"\"binary_sensor\"",
",",
"CONF_DIM_STEPS",
":",
"15",
",",
"}",
",",
"]",
",",
"CONF_OVERRIDE",
":",
"[",
"{",
"CONF_ADDRESS",
":",
"\"1A.2B.3C\"",
",",
"CONF_CAT",
":",
"1",
",",
"CONF_SUBCAT",
":",
"18",
"}",
"]",
",",
"}",
",",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"result",
"=",
"await",
"_options_init_form",
"(",
"hass",
",",
"config_entry",
".",
"entry_id",
",",
"STEP_REMOVE_X10",
")",
"for",
"device",
"in",
"config_entry",
".",
"options",
"[",
"CONF_X10",
"]",
":",
"housecode",
"=",
"device",
"[",
"CONF_HOUSECODE",
"]",
".",
"upper",
"(",
")",
"unitcode",
"=",
"device",
"[",
"CONF_UNITCODE",
"]",
"print",
"(",
"f\"Housecode: {housecode}, Unitcode: {unitcode}\"",
")",
"user_input",
"=",
"{",
"CONF_DEVICE",
":",
"\"Housecode: C, Unitcode: 4\"",
"}",
"result",
",",
"_",
"=",
"await",
"_options_form",
"(",
"hass",
",",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"len",
"(",
"config_entry",
".",
"options",
"[",
"CONF_X10",
"]",
")",
"==",
"1",
"assert",
"len",
"(",
"config_entry",
".",
"options",
"[",
"CONF_OVERRIDE",
"]",
")",
"==",
"1"
] | [
518,
0
] | [
556,
56
] | python | en | ['en', 'en', 'en'] | True |
test_options_dup_selection | (hass: HomeAssistantType) | Test if a duplicate selection was made in options. | Test if a duplicate selection was made in options. | async def test_options_dup_selection(hass: HomeAssistantType):
"""Test if a duplicate selection was made in options."""
config_entry = MockConfigEntry(
domain=DOMAIN,
entry_id="abcde12345",
data={**MOCK_USER_INPUT_HUB_V2, CONF_HUB_VERSION: 2},
options={},
)
config_entry.add_to_hass(hass)
result = await hass.config_entries.options.async_init(config_entry.entry_id)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "init"
result2 = await hass.config_entries.options.async_configure(
result["flow_id"],
{STEP_ADD_OVERRIDE: True, STEP_ADD_X10: True},
)
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result2["errors"] == {"base": "select_single"} | [
"async",
"def",
"test_options_dup_selection",
"(",
"hass",
":",
"HomeAssistantType",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"entry_id",
"=",
"\"abcde12345\"",
",",
"data",
"=",
"{",
"*",
"*",
"MOCK_USER_INPUT_HUB_V2",
",",
"CONF_HUB_VERSION",
":",
"2",
"}",
",",
"options",
"=",
"{",
"}",
",",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_init",
"(",
"config_entry",
".",
"entry_id",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"init\"",
"result2",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"{",
"STEP_ADD_OVERRIDE",
":",
"True",
",",
"STEP_ADD_X10",
":",
"True",
"}",
",",
")",
"assert",
"result2",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_FORM",
"assert",
"result2",
"[",
"\"errors\"",
"]",
"==",
"{",
"\"base\"",
":",
"\"select_single\"",
"}"
] | [
559,
0
] | [
578,
57
] | python | en | ['en', 'en', 'en'] | True |
test_options_override_bad_data | (hass: HomeAssistantType) | Test for bad data in a device override. | Test for bad data in a device override. | async def test_options_override_bad_data(hass: HomeAssistantType):
"""Test for bad data in a device override."""
config_entry = MockConfigEntry(
domain=DOMAIN,
entry_id="abcde12345",
data={**MOCK_USER_INPUT_HUB_V2, CONF_HUB_VERSION: 2},
options={},
)
config_entry.add_to_hass(hass)
result = await _options_init_form(hass, config_entry.entry_id, STEP_ADD_OVERRIDE)
user_input = {
CONF_ADDRESS: "zzzzzz",
CONF_CAT: "bad",
CONF_SUBCAT: "data",
}
result, _ = await _options_form(hass, result["flow_id"], user_input)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["errors"] == {"base": "input_error"} | [
"async",
"def",
"test_options_override_bad_data",
"(",
"hass",
":",
"HomeAssistantType",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"entry_id",
"=",
"\"abcde12345\"",
",",
"data",
"=",
"{",
"*",
"*",
"MOCK_USER_INPUT_HUB_V2",
",",
"CONF_HUB_VERSION",
":",
"2",
"}",
",",
"options",
"=",
"{",
"}",
",",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"result",
"=",
"await",
"_options_init_form",
"(",
"hass",
",",
"config_entry",
".",
"entry_id",
",",
"STEP_ADD_OVERRIDE",
")",
"user_input",
"=",
"{",
"CONF_ADDRESS",
":",
"\"zzzzzz\"",
",",
"CONF_CAT",
":",
"\"bad\"",
",",
"CONF_SUBCAT",
":",
"\"data\"",
",",
"}",
"result",
",",
"_",
"=",
"await",
"_options_form",
"(",
"hass",
",",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"errors\"",
"]",
"==",
"{",
"\"base\"",
":",
"\"input_error\"",
"}"
] | [
581,
0
] | [
602,
54
] | python | en | ['en', 'en', 'en'] | True |
_async_reproduce_state | (
hass: HomeAssistantType,
state: State,
*,
context: Optional[Context] = None,
reproduce_options: Optional[Dict[str, Any]] = None,
) | Reproduce a single state. | Reproduce a single state. | async def _async_reproduce_state(
hass: HomeAssistantType,
state: State,
*,
context: Optional[Context] = None,
reproduce_options: Optional[Dict[str, Any]] = None,
) -> None:
"""Reproduce a single state."""
cur_state = hass.states.get(state.entity_id)
if cur_state is None:
_LOGGER.warning("Unable to find entity %s", state.entity_id)
return
if state.state not in VALID_STATES:
_LOGGER.warning(
"Invalid state specified for %s: %s", state.entity_id, state.state
)
return
# Return if we are already at the right state.
if cur_state.state == state.state:
return
service_data = {ATTR_ENTITY_ID: state.entity_id}
if state.state == STATE_ON:
service = SERVICE_TURN_ON
elif state.state == STATE_OFF:
service = SERVICE_TURN_OFF
await hass.services.async_call(
DOMAIN, service, service_data, context=context, blocking=True
) | [
"async",
"def",
"_async_reproduce_state",
"(",
"hass",
":",
"HomeAssistantType",
",",
"state",
":",
"State",
",",
"*",
",",
"context",
":",
"Optional",
"[",
"Context",
"]",
"=",
"None",
",",
"reproduce_options",
":",
"Optional",
"[",
"Dict",
"[",
"str",
",",
"Any",
"]",
"]",
"=",
"None",
",",
")",
"->",
"None",
":",
"cur_state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"state",
".",
"entity_id",
")",
"if",
"cur_state",
"is",
"None",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Unable to find entity %s\"",
",",
"state",
".",
"entity_id",
")",
"return",
"if",
"state",
".",
"state",
"not",
"in",
"VALID_STATES",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Invalid state specified for %s: %s\"",
",",
"state",
".",
"entity_id",
",",
"state",
".",
"state",
")",
"return",
"# Return if we are already at the right state.",
"if",
"cur_state",
".",
"state",
"==",
"state",
".",
"state",
":",
"return",
"service_data",
"=",
"{",
"ATTR_ENTITY_ID",
":",
"state",
".",
"entity_id",
"}",
"if",
"state",
".",
"state",
"==",
"STATE_ON",
":",
"service",
"=",
"SERVICE_TURN_ON",
"elif",
"state",
".",
"state",
"==",
"STATE_OFF",
":",
"service",
"=",
"SERVICE_TURN_OFF",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"service",
",",
"service_data",
",",
"context",
"=",
"context",
",",
"blocking",
"=",
"True",
")"
] | [
22,
0
] | [
55,
5
] | python | en | ['en', 'en', 'en'] | True |
async_reproduce_states | (
hass: HomeAssistantType,
states: Iterable[State],
*,
context: Optional[Context] = None,
reproduce_options: Optional[Dict[str, Any]] = None,
) | Reproduce Remote states. | Reproduce Remote states. | async def async_reproduce_states(
hass: HomeAssistantType,
states: Iterable[State],
*,
context: Optional[Context] = None,
reproduce_options: Optional[Dict[str, Any]] = None,
) -> None:
"""Reproduce Remote states."""
await asyncio.gather(
*(
_async_reproduce_state(
hass, state, context=context, reproduce_options=reproduce_options
)
for state in states
)
) | [
"async",
"def",
"async_reproduce_states",
"(",
"hass",
":",
"HomeAssistantType",
",",
"states",
":",
"Iterable",
"[",
"State",
"]",
",",
"*",
",",
"context",
":",
"Optional",
"[",
"Context",
"]",
"=",
"None",
",",
"reproduce_options",
":",
"Optional",
"[",
"Dict",
"[",
"str",
",",
"Any",
"]",
"]",
"=",
"None",
",",
")",
"->",
"None",
":",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"(",
"_async_reproduce_state",
"(",
"hass",
",",
"state",
",",
"context",
"=",
"context",
",",
"reproduce_options",
"=",
"reproduce_options",
")",
"for",
"state",
"in",
"states",
")",
")"
] | [
58,
0
] | [
73,
5
] | python | en | ['en', 'en', 'en'] | True |
setup_mock_component | (hass, entry=None) | Set up Mock Media Player. | Set up Mock Media Player. | async def setup_mock_component(hass, entry=None):
"""Set up Mock Media Player."""
if entry is None:
mock_entry = MockConfigEntry(
domain=ps4.DOMAIN, data=MOCK_DATA, version=VERSION, entry_id=MOCK_ENTRY_ID
)
else:
mock_entry = entry
mock_entry.add_to_hass(hass)
await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
await hass.async_block_till_done()
mock_entities = hass.states.async_entity_ids()
mock_entity_id = mock_entities[0]
return mock_entity_id | [
"async",
"def",
"setup_mock_component",
"(",
"hass",
",",
"entry",
"=",
"None",
")",
":",
"if",
"entry",
"is",
"None",
":",
"mock_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"ps4",
".",
"DOMAIN",
",",
"data",
"=",
"MOCK_DATA",
",",
"version",
"=",
"VERSION",
",",
"entry_id",
"=",
"MOCK_ENTRY_ID",
")",
"else",
":",
"mock_entry",
"=",
"entry",
"mock_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"await",
"async_setup_component",
"(",
"hass",
",",
"DOMAIN",
",",
"{",
"DOMAIN",
":",
"{",
"}",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"mock_entities",
"=",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
")",
"mock_entity_id",
"=",
"mock_entities",
"[",
"0",
"]",
"return",
"mock_entity_id"
] | [
126,
0
] | [
145,
25
] | python | en | ['en', 'da', 'en'] | True |
mock_ddp_response | (hass, mock_status_data) | Mock raw UDP response from device. | Mock raw UDP response from device. | async def mock_ddp_response(hass, mock_status_data):
"""Mock raw UDP response from device."""
mock_protocol = hass.data[PS4_DATA].protocol
mock_code = mock_status_data.get("status_code")
mock_status = mock_status_data.get("status")
mock_status_header = f"{mock_code} {mock_status}"
mock_response = get_ddp_message(mock_status_header, mock_status_data).encode()
mock_protocol.datagram_received(mock_response, (MOCK_HOST, MOCK_RANDOM_PORT))
await hass.async_block_till_done() | [
"async",
"def",
"mock_ddp_response",
"(",
"hass",
",",
"mock_status_data",
")",
":",
"mock_protocol",
"=",
"hass",
".",
"data",
"[",
"PS4_DATA",
"]",
".",
"protocol",
"mock_code",
"=",
"mock_status_data",
".",
"get",
"(",
"\"status_code\"",
")",
"mock_status",
"=",
"mock_status_data",
".",
"get",
"(",
"\"status\"",
")",
"mock_status_header",
"=",
"f\"{mock_code} {mock_status}\"",
"mock_response",
"=",
"get_ddp_message",
"(",
"mock_status_header",
",",
"mock_status_data",
")",
".",
"encode",
"(",
")",
"mock_protocol",
".",
"datagram_received",
"(",
"mock_response",
",",
"(",
"MOCK_HOST",
",",
"MOCK_RANDOM_PORT",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")"
] | [
148,
0
] | [
158,
38
] | python | en | ['en', 'en', 'en'] | True |
test_media_player_is_setup_correctly_with_entry | (hass) | Test entity is setup correctly with entry correctly. | Test entity is setup correctly with entry correctly. | async def test_media_player_is_setup_correctly_with_entry(hass):
"""Test entity is setup correctly with entry correctly."""
mock_entity_id = await setup_mock_component(hass)
mock_state = hass.states.get(mock_entity_id).state
# Assert status updated callback is added to protocol.
assert len(hass.data[PS4_DATA].protocol.callbacks) == 1
# Test that entity is added to hass.
assert hass.data[PS4_DATA].protocol is not None
assert mock_entity_id == f"media_player.{MOCK_NAME}"
assert mock_state == STATE_UNKNOWN | [
"async",
"def",
"test_media_player_is_setup_correctly_with_entry",
"(",
"hass",
")",
":",
"mock_entity_id",
"=",
"await",
"setup_mock_component",
"(",
"hass",
")",
"mock_state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"mock_entity_id",
")",
".",
"state",
"# Assert status updated callback is added to protocol.",
"assert",
"len",
"(",
"hass",
".",
"data",
"[",
"PS4_DATA",
"]",
".",
"protocol",
".",
"callbacks",
")",
"==",
"1",
"# Test that entity is added to hass.",
"assert",
"hass",
".",
"data",
"[",
"PS4_DATA",
"]",
".",
"protocol",
"is",
"not",
"None",
"assert",
"mock_entity_id",
"==",
"f\"media_player.{MOCK_NAME}\"",
"assert",
"mock_state",
"==",
"STATE_UNKNOWN"
] | [
161,
0
] | [
172,
38
] | python | en | ['en', 'zu', 'en'] | True |
test_state_standby_is_set | (hass) | Test that state is set to standby. | Test that state is set to standby. | async def test_state_standby_is_set(hass):
"""Test that state is set to standby."""
mock_entity_id = await setup_mock_component(hass)
await mock_ddp_response(hass, MOCK_STATUS_STANDBY)
assert hass.states.get(mock_entity_id).state == STATE_STANDBY | [
"async",
"def",
"test_state_standby_is_set",
"(",
"hass",
")",
":",
"mock_entity_id",
"=",
"await",
"setup_mock_component",
"(",
"hass",
")",
"await",
"mock_ddp_response",
"(",
"hass",
",",
"MOCK_STATUS_STANDBY",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"mock_entity_id",
")",
".",
"state",
"==",
"STATE_STANDBY"
] | [
175,
0
] | [
181,
65
] | python | en | ['en', 'en', 'en'] | True |
test_state_playing_is_set | (hass) | Test that state is set to playing. | Test that state is set to playing. | async def test_state_playing_is_set(hass):
"""Test that state is set to playing."""
mock_entity_id = await setup_mock_component(hass)
mock_func = "{}{}".format(
"homeassistant.components.ps4.media_player.",
"pyps4.Ps4Async.async_get_ps_store_data",
)
with patch(mock_func, return_value=None):
await mock_ddp_response(hass, MOCK_STATUS_PLAYING)
assert hass.states.get(mock_entity_id).state == STATE_PLAYING | [
"async",
"def",
"test_state_playing_is_set",
"(",
"hass",
")",
":",
"mock_entity_id",
"=",
"await",
"setup_mock_component",
"(",
"hass",
")",
"mock_func",
"=",
"\"{}{}\"",
".",
"format",
"(",
"\"homeassistant.components.ps4.media_player.\"",
",",
"\"pyps4.Ps4Async.async_get_ps_store_data\"",
",",
")",
"with",
"patch",
"(",
"mock_func",
",",
"return_value",
"=",
"None",
")",
":",
"await",
"mock_ddp_response",
"(",
"hass",
",",
"MOCK_STATUS_PLAYING",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"mock_entity_id",
")",
".",
"state",
"==",
"STATE_PLAYING"
] | [
184,
0
] | [
195,
65
] | python | en | ['en', 'en', 'en'] | True |
test_state_idle_is_set | (hass) | Test that state is set to idle. | Test that state is set to idle. | async def test_state_idle_is_set(hass):
"""Test that state is set to idle."""
mock_entity_id = await setup_mock_component(hass)
await mock_ddp_response(hass, MOCK_STATUS_IDLE)
assert hass.states.get(mock_entity_id).state == STATE_IDLE | [
"async",
"def",
"test_state_idle_is_set",
"(",
"hass",
")",
":",
"mock_entity_id",
"=",
"await",
"setup_mock_component",
"(",
"hass",
")",
"await",
"mock_ddp_response",
"(",
"hass",
",",
"MOCK_STATUS_IDLE",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"mock_entity_id",
")",
".",
"state",
"==",
"STATE_IDLE"
] | [
198,
0
] | [
204,
62
] | python | en | ['en', 'en', 'en'] | True |
test_state_none_is_set | (hass) | Test that state is set to None. | Test that state is set to None. | async def test_state_none_is_set(hass):
"""Test that state is set to None."""
mock_entity_id = await setup_mock_component(hass)
assert hass.states.get(mock_entity_id).state == STATE_UNKNOWN | [
"async",
"def",
"test_state_none_is_set",
"(",
"hass",
")",
":",
"mock_entity_id",
"=",
"await",
"setup_mock_component",
"(",
"hass",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"mock_entity_id",
")",
".",
"state",
"==",
"STATE_UNKNOWN"
] | [
207,
0
] | [
211,
65
] | python | en | ['en', 'en', 'en'] | True |
test_media_attributes_are_fetched | (hass) | Test that media attributes are fetched. | Test that media attributes are fetched. | async def test_media_attributes_are_fetched(hass):
"""Test that media attributes are fetched."""
mock_entity_id = await setup_mock_component(hass)
mock_func = "{}{}".format(
"homeassistant.components.ps4.media_player.",
"pyps4.Ps4Async.async_get_ps_store_data",
)
# Mock result from fetching data.
mock_result = MagicMock()
mock_result.name = MOCK_TITLE_NAME
mock_result.cover_art = MOCK_TITLE_ART_URL
mock_result.game_type = "game"
with patch(mock_func, return_value=mock_result) as mock_fetch:
await mock_ddp_response(hass, MOCK_STATUS_PLAYING)
mock_state = hass.states.get(mock_entity_id)
mock_attrs = dict(mock_state.attributes)
assert len(mock_fetch.mock_calls) == 1
assert mock_state.state == STATE_PLAYING
assert len(mock_attrs.get(ATTR_INPUT_SOURCE_LIST)) == 1
assert mock_attrs.get(ATTR_INPUT_SOURCE_LIST)[0] == MOCK_TITLE_NAME
assert mock_attrs.get(ATTR_MEDIA_CONTENT_ID) == MOCK_TITLE_ID
assert mock_attrs.get(ATTR_MEDIA_TITLE) == MOCK_TITLE_NAME
assert mock_attrs.get(ATTR_MEDIA_CONTENT_TYPE) == MOCK_TITLE_TYPE | [
"async",
"def",
"test_media_attributes_are_fetched",
"(",
"hass",
")",
":",
"mock_entity_id",
"=",
"await",
"setup_mock_component",
"(",
"hass",
")",
"mock_func",
"=",
"\"{}{}\"",
".",
"format",
"(",
"\"homeassistant.components.ps4.media_player.\"",
",",
"\"pyps4.Ps4Async.async_get_ps_store_data\"",
",",
")",
"# Mock result from fetching data.",
"mock_result",
"=",
"MagicMock",
"(",
")",
"mock_result",
".",
"name",
"=",
"MOCK_TITLE_NAME",
"mock_result",
".",
"cover_art",
"=",
"MOCK_TITLE_ART_URL",
"mock_result",
".",
"game_type",
"=",
"\"game\"",
"with",
"patch",
"(",
"mock_func",
",",
"return_value",
"=",
"mock_result",
")",
"as",
"mock_fetch",
":",
"await",
"mock_ddp_response",
"(",
"hass",
",",
"MOCK_STATUS_PLAYING",
")",
"mock_state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"mock_entity_id",
")",
"mock_attrs",
"=",
"dict",
"(",
"mock_state",
".",
"attributes",
")",
"assert",
"len",
"(",
"mock_fetch",
".",
"mock_calls",
")",
"==",
"1",
"assert",
"mock_state",
".",
"state",
"==",
"STATE_PLAYING",
"assert",
"len",
"(",
"mock_attrs",
".",
"get",
"(",
"ATTR_INPUT_SOURCE_LIST",
")",
")",
"==",
"1",
"assert",
"mock_attrs",
".",
"get",
"(",
"ATTR_INPUT_SOURCE_LIST",
")",
"[",
"0",
"]",
"==",
"MOCK_TITLE_NAME",
"assert",
"mock_attrs",
".",
"get",
"(",
"ATTR_MEDIA_CONTENT_ID",
")",
"==",
"MOCK_TITLE_ID",
"assert",
"mock_attrs",
".",
"get",
"(",
"ATTR_MEDIA_TITLE",
")",
"==",
"MOCK_TITLE_NAME",
"assert",
"mock_attrs",
".",
"get",
"(",
"ATTR_MEDIA_CONTENT_TYPE",
")",
"==",
"MOCK_TITLE_TYPE"
] | [
214,
0
] | [
241,
69
] | python | en | ['en', 'en', 'en'] | True |
test_media_attributes_are_loaded | (hass, patch_load_json) | Test that media attributes are loaded. | Test that media attributes are loaded. | async def test_media_attributes_are_loaded(hass, patch_load_json):
"""Test that media attributes are loaded."""
mock_entity_id = await setup_mock_component(hass)
patch_load_json.return_value = {MOCK_TITLE_ID: MOCK_GAMES_DATA_LOCKED}
with patch(
"homeassistant.components.ps4.media_player."
"pyps4.Ps4Async.async_get_ps_store_data",
return_value=None,
) as mock_fetch:
await mock_ddp_response(hass, MOCK_STATUS_PLAYING)
mock_state = hass.states.get(mock_entity_id)
mock_attrs = dict(mock_state.attributes)
# Ensure that data is not fetched.
assert not mock_fetch.mock_calls
assert mock_state.state == STATE_PLAYING
assert len(mock_attrs.get(ATTR_INPUT_SOURCE_LIST)) == 1
assert mock_attrs.get(ATTR_INPUT_SOURCE_LIST)[0] == MOCK_TITLE_NAME
assert mock_attrs.get(ATTR_MEDIA_CONTENT_ID) == MOCK_TITLE_ID
assert mock_attrs.get(ATTR_MEDIA_TITLE) == MOCK_TITLE_NAME
assert mock_attrs.get(ATTR_MEDIA_CONTENT_TYPE) == MOCK_TITLE_TYPE | [
"async",
"def",
"test_media_attributes_are_loaded",
"(",
"hass",
",",
"patch_load_json",
")",
":",
"mock_entity_id",
"=",
"await",
"setup_mock_component",
"(",
"hass",
")",
"patch_load_json",
".",
"return_value",
"=",
"{",
"MOCK_TITLE_ID",
":",
"MOCK_GAMES_DATA_LOCKED",
"}",
"with",
"patch",
"(",
"\"homeassistant.components.ps4.media_player.\"",
"\"pyps4.Ps4Async.async_get_ps_store_data\"",
",",
"return_value",
"=",
"None",
",",
")",
"as",
"mock_fetch",
":",
"await",
"mock_ddp_response",
"(",
"hass",
",",
"MOCK_STATUS_PLAYING",
")",
"mock_state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"mock_entity_id",
")",
"mock_attrs",
"=",
"dict",
"(",
"mock_state",
".",
"attributes",
")",
"# Ensure that data is not fetched.",
"assert",
"not",
"mock_fetch",
".",
"mock_calls",
"assert",
"mock_state",
".",
"state",
"==",
"STATE_PLAYING",
"assert",
"len",
"(",
"mock_attrs",
".",
"get",
"(",
"ATTR_INPUT_SOURCE_LIST",
")",
")",
"==",
"1",
"assert",
"mock_attrs",
".",
"get",
"(",
"ATTR_INPUT_SOURCE_LIST",
")",
"[",
"0",
"]",
"==",
"MOCK_TITLE_NAME",
"assert",
"mock_attrs",
".",
"get",
"(",
"ATTR_MEDIA_CONTENT_ID",
")",
"==",
"MOCK_TITLE_ID",
"assert",
"mock_attrs",
".",
"get",
"(",
"ATTR_MEDIA_TITLE",
")",
"==",
"MOCK_TITLE_NAME",
"assert",
"mock_attrs",
".",
"get",
"(",
"ATTR_MEDIA_CONTENT_TYPE",
")",
"==",
"MOCK_TITLE_TYPE"
] | [
244,
0
] | [
268,
69
] | python | en | ['en', 'en', 'en'] | True |
test_device_info_is_set_from_status_correctly | (hass) | Test that device info is set correctly from status update. | Test that device info is set correctly from status update. | async def test_device_info_is_set_from_status_correctly(hass):
"""Test that device info is set correctly from status update."""
mock_d_registry = mock_device_registry(hass)
with patch("pyps4_2ndscreen.ps4.get_status", return_value=MOCK_STATUS_STANDBY):
mock_entity_id = await setup_mock_component(hass)
await hass.async_block_till_done()
# Reformat mock status-sw_version for assertion.
mock_version = MOCK_STATUS_STANDBY["system-version"]
mock_version = mock_version[1:4]
mock_version = "{}.{}".format(mock_version[0], mock_version[1:])
mock_state = hass.states.get(mock_entity_id).state
mock_d_entries = mock_d_registry.devices
mock_entry = mock_d_registry.async_get_device(
identifiers={(DOMAIN, MOCK_HOST_ID)}, connections={()}
)
assert mock_state == STATE_STANDBY
assert len(mock_d_entries) == 1
assert mock_entry.name == MOCK_HOST_NAME
assert mock_entry.model == MOCK_DEVICE_MODEL
assert mock_entry.sw_version == mock_version
assert mock_entry.identifiers == {(DOMAIN, MOCK_HOST_ID)} | [
"async",
"def",
"test_device_info_is_set_from_status_correctly",
"(",
"hass",
")",
":",
"mock_d_registry",
"=",
"mock_device_registry",
"(",
"hass",
")",
"with",
"patch",
"(",
"\"pyps4_2ndscreen.ps4.get_status\"",
",",
"return_value",
"=",
"MOCK_STATUS_STANDBY",
")",
":",
"mock_entity_id",
"=",
"await",
"setup_mock_component",
"(",
"hass",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# Reformat mock status-sw_version for assertion.",
"mock_version",
"=",
"MOCK_STATUS_STANDBY",
"[",
"\"system-version\"",
"]",
"mock_version",
"=",
"mock_version",
"[",
"1",
":",
"4",
"]",
"mock_version",
"=",
"\"{}.{}\"",
".",
"format",
"(",
"mock_version",
"[",
"0",
"]",
",",
"mock_version",
"[",
"1",
":",
"]",
")",
"mock_state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"mock_entity_id",
")",
".",
"state",
"mock_d_entries",
"=",
"mock_d_registry",
".",
"devices",
"mock_entry",
"=",
"mock_d_registry",
".",
"async_get_device",
"(",
"identifiers",
"=",
"{",
"(",
"DOMAIN",
",",
"MOCK_HOST_ID",
")",
"}",
",",
"connections",
"=",
"{",
"(",
")",
"}",
")",
"assert",
"mock_state",
"==",
"STATE_STANDBY",
"assert",
"len",
"(",
"mock_d_entries",
")",
"==",
"1",
"assert",
"mock_entry",
".",
"name",
"==",
"MOCK_HOST_NAME",
"assert",
"mock_entry",
".",
"model",
"==",
"MOCK_DEVICE_MODEL",
"assert",
"mock_entry",
".",
"sw_version",
"==",
"mock_version",
"assert",
"mock_entry",
".",
"identifiers",
"==",
"{",
"(",
"DOMAIN",
",",
"MOCK_HOST_ID",
")",
"}"
] | [
271,
0
] | [
296,
61
] | python | en | ['en', 'en', 'en'] | True |
test_device_info_is_assummed | (hass) | Test that device info is assumed if device is unavailable. | Test that device info is assumed if device is unavailable. | async def test_device_info_is_assummed(hass):
"""Test that device info is assumed if device is unavailable."""
# Create a device registry entry with device info.
mock_d_registry = mock_device_registry(hass)
mock_d_registry.async_get_or_create(
config_entry_id=MOCK_ENTRY_ID,
name=MOCK_HOST_NAME,
model=MOCK_DEVICE_MODEL,
identifiers={(DOMAIN, MOCK_HOST_ID)},
sw_version=MOCK_HOST_VERSION,
)
mock_d_entries = mock_d_registry.devices
assert len(mock_d_entries) == 1
# Create a entity_registry entry which is using identifiers from device.
mock_unique_id = ps4.format_unique_id(MOCK_CREDS, MOCK_HOST_ID)
mock_e_registry = mock_registry(hass)
mock_e_registry.async_get_or_create(
"media_player", DOMAIN, mock_unique_id, config_entry=MOCK_CONFIG
)
mock_entity_id = mock_e_registry.async_get_entity_id(
"media_player", DOMAIN, mock_unique_id
)
mock_entity_id = await setup_mock_component(hass)
mock_state = hass.states.get(mock_entity_id).state
# Ensure that state is not set.
assert mock_state == STATE_UNKNOWN
# Ensure that entity_id is the same as the existing.
mock_entities = hass.states.async_entity_ids()
assert len(mock_entities) == 1
assert mock_entities[0] == mock_entity_id | [
"async",
"def",
"test_device_info_is_assummed",
"(",
"hass",
")",
":",
"# Create a device registry entry with device info.",
"mock_d_registry",
"=",
"mock_device_registry",
"(",
"hass",
")",
"mock_d_registry",
".",
"async_get_or_create",
"(",
"config_entry_id",
"=",
"MOCK_ENTRY_ID",
",",
"name",
"=",
"MOCK_HOST_NAME",
",",
"model",
"=",
"MOCK_DEVICE_MODEL",
",",
"identifiers",
"=",
"{",
"(",
"DOMAIN",
",",
"MOCK_HOST_ID",
")",
"}",
",",
"sw_version",
"=",
"MOCK_HOST_VERSION",
",",
")",
"mock_d_entries",
"=",
"mock_d_registry",
".",
"devices",
"assert",
"len",
"(",
"mock_d_entries",
")",
"==",
"1",
"# Create a entity_registry entry which is using identifiers from device.",
"mock_unique_id",
"=",
"ps4",
".",
"format_unique_id",
"(",
"MOCK_CREDS",
",",
"MOCK_HOST_ID",
")",
"mock_e_registry",
"=",
"mock_registry",
"(",
"hass",
")",
"mock_e_registry",
".",
"async_get_or_create",
"(",
"\"media_player\"",
",",
"DOMAIN",
",",
"mock_unique_id",
",",
"config_entry",
"=",
"MOCK_CONFIG",
")",
"mock_entity_id",
"=",
"mock_e_registry",
".",
"async_get_entity_id",
"(",
"\"media_player\"",
",",
"DOMAIN",
",",
"mock_unique_id",
")",
"mock_entity_id",
"=",
"await",
"setup_mock_component",
"(",
"hass",
")",
"mock_state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"mock_entity_id",
")",
".",
"state",
"# Ensure that state is not set.",
"assert",
"mock_state",
"==",
"STATE_UNKNOWN",
"# Ensure that entity_id is the same as the existing.",
"mock_entities",
"=",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
")",
"assert",
"len",
"(",
"mock_entities",
")",
"==",
"1",
"assert",
"mock_entities",
"[",
"0",
"]",
"==",
"mock_entity_id"
] | [
299,
0
] | [
332,
45
] | python | en | ['en', 'en', 'en'] | True |
test_device_info_assummed_works | (hass) | Reverse test that device info assumption works. | Reverse test that device info assumption works. | async def test_device_info_assummed_works(hass):
"""Reverse test that device info assumption works."""
mock_d_registry = mock_device_registry(hass)
mock_entity_id = await setup_mock_component(hass)
mock_state = hass.states.get(mock_entity_id).state
mock_d_entries = mock_d_registry.devices
# Ensure that state is not set.
assert mock_state == STATE_UNKNOWN
# With no state/status and no existing entries, registry should be empty.
assert not mock_d_entries | [
"async",
"def",
"test_device_info_assummed_works",
"(",
"hass",
")",
":",
"mock_d_registry",
"=",
"mock_device_registry",
"(",
"hass",
")",
"mock_entity_id",
"=",
"await",
"setup_mock_component",
"(",
"hass",
")",
"mock_state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"mock_entity_id",
")",
".",
"state",
"mock_d_entries",
"=",
"mock_d_registry",
".",
"devices",
"# Ensure that state is not set.",
"assert",
"mock_state",
"==",
"STATE_UNKNOWN",
"# With no state/status and no existing entries, registry should be empty.",
"assert",
"not",
"mock_d_entries"
] | [
335,
0
] | [
346,
29
] | python | en | ['en', 'en', 'en'] | True |
test_turn_on | (hass) | Test that turn on service calls function. | Test that turn on service calls function. | async def test_turn_on(hass):
"""Test that turn on service calls function."""
mock_entity_id = await setup_mock_component(hass)
mock_func = "{}{}".format(
"homeassistant.components.ps4.media_player.", "pyps4.Ps4Async.wakeup"
)
with patch(mock_func) as mock_call:
await hass.services.async_call(
"media_player", "turn_on", {ATTR_ENTITY_ID: mock_entity_id}
)
await hass.async_block_till_done()
assert len(mock_call.mock_calls) == 1 | [
"async",
"def",
"test_turn_on",
"(",
"hass",
")",
":",
"mock_entity_id",
"=",
"await",
"setup_mock_component",
"(",
"hass",
")",
"mock_func",
"=",
"\"{}{}\"",
".",
"format",
"(",
"\"homeassistant.components.ps4.media_player.\"",
",",
"\"pyps4.Ps4Async.wakeup\"",
")",
"with",
"patch",
"(",
"mock_func",
")",
"as",
"mock_call",
":",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"media_player\"",
",",
"\"turn_on\"",
",",
"{",
"ATTR_ENTITY_ID",
":",
"mock_entity_id",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"mock_call",
".",
"mock_calls",
")",
"==",
"1"
] | [
349,
0
] | [
362,
41
] | python | en | ['en', 'en', 'en'] | True |
test_turn_off | (hass) | Test that turn off service calls function. | Test that turn off service calls function. | async def test_turn_off(hass):
"""Test that turn off service calls function."""
mock_entity_id = await setup_mock_component(hass)
mock_func = "{}{}".format(
"homeassistant.components.ps4.media_player.", "pyps4.Ps4Async.standby"
)
with patch(mock_func) as mock_call:
await hass.services.async_call(
"media_player", "turn_off", {ATTR_ENTITY_ID: mock_entity_id}
)
await hass.async_block_till_done()
assert len(mock_call.mock_calls) == 1 | [
"async",
"def",
"test_turn_off",
"(",
"hass",
")",
":",
"mock_entity_id",
"=",
"await",
"setup_mock_component",
"(",
"hass",
")",
"mock_func",
"=",
"\"{}{}\"",
".",
"format",
"(",
"\"homeassistant.components.ps4.media_player.\"",
",",
"\"pyps4.Ps4Async.standby\"",
")",
"with",
"patch",
"(",
"mock_func",
")",
"as",
"mock_call",
":",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"media_player\"",
",",
"\"turn_off\"",
",",
"{",
"ATTR_ENTITY_ID",
":",
"mock_entity_id",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"mock_call",
".",
"mock_calls",
")",
"==",
"1"
] | [
365,
0
] | [
378,
41
] | python | en | ['en', 'en', 'en'] | True |
test_toggle | (hass) | Test that toggle service calls function. | Test that toggle service calls function. | async def test_toggle(hass):
"""Test that toggle service calls function."""
mock_entity_id = await setup_mock_component(hass)
mock_func = "{}{}".format(
"homeassistant.components.ps4.media_player.", "pyps4.Ps4Async.toggle"
)
with patch(mock_func) as mock_call:
await hass.services.async_call(
"media_player", "toggle", {ATTR_ENTITY_ID: mock_entity_id}
)
await hass.async_block_till_done()
assert len(mock_call.mock_calls) == 1 | [
"async",
"def",
"test_toggle",
"(",
"hass",
")",
":",
"mock_entity_id",
"=",
"await",
"setup_mock_component",
"(",
"hass",
")",
"mock_func",
"=",
"\"{}{}\"",
".",
"format",
"(",
"\"homeassistant.components.ps4.media_player.\"",
",",
"\"pyps4.Ps4Async.toggle\"",
")",
"with",
"patch",
"(",
"mock_func",
")",
"as",
"mock_call",
":",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"media_player\"",
",",
"\"toggle\"",
",",
"{",
"ATTR_ENTITY_ID",
":",
"mock_entity_id",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"mock_call",
".",
"mock_calls",
")",
"==",
"1"
] | [
381,
0
] | [
394,
41
] | python | en | ['en', 'en', 'en'] | True |
test_media_pause | (hass) | Test that media pause service calls function. | Test that media pause service calls function. | async def test_media_pause(hass):
"""Test that media pause service calls function."""
mock_entity_id = await setup_mock_component(hass)
mock_func = "{}{}".format(
"homeassistant.components.ps4.media_player.", "pyps4.Ps4Async.remote_control"
)
with patch(mock_func) as mock_call:
await hass.services.async_call(
"media_player", "media_pause", {ATTR_ENTITY_ID: mock_entity_id}
)
await hass.async_block_till_done()
assert len(mock_call.mock_calls) == 1 | [
"async",
"def",
"test_media_pause",
"(",
"hass",
")",
":",
"mock_entity_id",
"=",
"await",
"setup_mock_component",
"(",
"hass",
")",
"mock_func",
"=",
"\"{}{}\"",
".",
"format",
"(",
"\"homeassistant.components.ps4.media_player.\"",
",",
"\"pyps4.Ps4Async.remote_control\"",
")",
"with",
"patch",
"(",
"mock_func",
")",
"as",
"mock_call",
":",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"media_player\"",
",",
"\"media_pause\"",
",",
"{",
"ATTR_ENTITY_ID",
":",
"mock_entity_id",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"mock_call",
".",
"mock_calls",
")",
"==",
"1"
] | [
397,
0
] | [
410,
41
] | python | en | ['en', 'en', 'en'] | True |
test_media_stop | (hass) | Test that media stop service calls function. | Test that media stop service calls function. | async def test_media_stop(hass):
"""Test that media stop service calls function."""
mock_entity_id = await setup_mock_component(hass)
mock_func = "{}{}".format(
"homeassistant.components.ps4.media_player.", "pyps4.Ps4Async.remote_control"
)
with patch(mock_func) as mock_call:
await hass.services.async_call(
"media_player", "media_stop", {ATTR_ENTITY_ID: mock_entity_id}
)
await hass.async_block_till_done()
assert len(mock_call.mock_calls) == 1 | [
"async",
"def",
"test_media_stop",
"(",
"hass",
")",
":",
"mock_entity_id",
"=",
"await",
"setup_mock_component",
"(",
"hass",
")",
"mock_func",
"=",
"\"{}{}\"",
".",
"format",
"(",
"\"homeassistant.components.ps4.media_player.\"",
",",
"\"pyps4.Ps4Async.remote_control\"",
")",
"with",
"patch",
"(",
"mock_func",
")",
"as",
"mock_call",
":",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"media_player\"",
",",
"\"media_stop\"",
",",
"{",
"ATTR_ENTITY_ID",
":",
"mock_entity_id",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"mock_call",
".",
"mock_calls",
")",
"==",
"1"
] | [
413,
0
] | [
426,
41
] | python | en | ['en', 'en', 'en'] | True |
test_select_source | (hass, patch_load_json) | Test that select source service calls function with title. | Test that select source service calls function with title. | async def test_select_source(hass, patch_load_json):
"""Test that select source service calls function with title."""
patch_load_json.return_value = {MOCK_TITLE_ID: MOCK_GAMES_DATA}
with patch("pyps4_2ndscreen.ps4.get_status", return_value=MOCK_STATUS_IDLE):
mock_entity_id = await setup_mock_component(hass)
with patch("pyps4_2ndscreen.ps4.Ps4Async.start_title") as mock_call, patch(
"homeassistant.components.ps4.media_player.PS4Device.async_update"
):
# Test with title name.
await hass.services.async_call(
"media_player",
"select_source",
{ATTR_ENTITY_ID: mock_entity_id, ATTR_INPUT_SOURCE: MOCK_TITLE_NAME},
blocking=True,
)
assert len(mock_call.mock_calls) == 1 | [
"async",
"def",
"test_select_source",
"(",
"hass",
",",
"patch_load_json",
")",
":",
"patch_load_json",
".",
"return_value",
"=",
"{",
"MOCK_TITLE_ID",
":",
"MOCK_GAMES_DATA",
"}",
"with",
"patch",
"(",
"\"pyps4_2ndscreen.ps4.get_status\"",
",",
"return_value",
"=",
"MOCK_STATUS_IDLE",
")",
":",
"mock_entity_id",
"=",
"await",
"setup_mock_component",
"(",
"hass",
")",
"with",
"patch",
"(",
"\"pyps4_2ndscreen.ps4.Ps4Async.start_title\"",
")",
"as",
"mock_call",
",",
"patch",
"(",
"\"homeassistant.components.ps4.media_player.PS4Device.async_update\"",
")",
":",
"# Test with title name.",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"media_player\"",
",",
"\"select_source\"",
",",
"{",
"ATTR_ENTITY_ID",
":",
"mock_entity_id",
",",
"ATTR_INPUT_SOURCE",
":",
"MOCK_TITLE_NAME",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"assert",
"len",
"(",
"mock_call",
".",
"mock_calls",
")",
"==",
"1"
] | [
429,
0
] | [
446,
41
] | python | en | ['en', 'en', 'en'] | True |
test_select_source_caps | (hass, patch_load_json) | Test that select source service calls function with upper case title. | Test that select source service calls function with upper case title. | async def test_select_source_caps(hass, patch_load_json):
"""Test that select source service calls function with upper case title."""
patch_load_json.return_value = {MOCK_TITLE_ID: MOCK_GAMES_DATA}
with patch("pyps4_2ndscreen.ps4.get_status", return_value=MOCK_STATUS_IDLE):
mock_entity_id = await setup_mock_component(hass)
with patch("pyps4_2ndscreen.ps4.Ps4Async.start_title") as mock_call, patch(
"homeassistant.components.ps4.media_player.PS4Device.async_update"
):
# Test with title name in caps.
await hass.services.async_call(
"media_player",
"select_source",
{
ATTR_ENTITY_ID: mock_entity_id,
ATTR_INPUT_SOURCE: MOCK_TITLE_NAME.upper(),
},
blocking=True,
)
assert len(mock_call.mock_calls) == 1 | [
"async",
"def",
"test_select_source_caps",
"(",
"hass",
",",
"patch_load_json",
")",
":",
"patch_load_json",
".",
"return_value",
"=",
"{",
"MOCK_TITLE_ID",
":",
"MOCK_GAMES_DATA",
"}",
"with",
"patch",
"(",
"\"pyps4_2ndscreen.ps4.get_status\"",
",",
"return_value",
"=",
"MOCK_STATUS_IDLE",
")",
":",
"mock_entity_id",
"=",
"await",
"setup_mock_component",
"(",
"hass",
")",
"with",
"patch",
"(",
"\"pyps4_2ndscreen.ps4.Ps4Async.start_title\"",
")",
"as",
"mock_call",
",",
"patch",
"(",
"\"homeassistant.components.ps4.media_player.PS4Device.async_update\"",
")",
":",
"# Test with title name in caps.",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"media_player\"",
",",
"\"select_source\"",
",",
"{",
"ATTR_ENTITY_ID",
":",
"mock_entity_id",
",",
"ATTR_INPUT_SOURCE",
":",
"MOCK_TITLE_NAME",
".",
"upper",
"(",
")",
",",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"assert",
"len",
"(",
"mock_call",
".",
"mock_calls",
")",
"==",
"1"
] | [
449,
0
] | [
469,
41
] | python | en | ['en', 'en', 'en'] | True |
test_select_source_id | (hass, patch_load_json) | Test that select source service calls function with Title ID. | Test that select source service calls function with Title ID. | async def test_select_source_id(hass, patch_load_json):
"""Test that select source service calls function with Title ID."""
patch_load_json.return_value = {MOCK_TITLE_ID: MOCK_GAMES_DATA}
with patch("pyps4_2ndscreen.ps4.get_status", return_value=MOCK_STATUS_IDLE):
mock_entity_id = await setup_mock_component(hass)
with patch("pyps4_2ndscreen.ps4.Ps4Async.start_title") as mock_call, patch(
"homeassistant.components.ps4.media_player.PS4Device.async_update"
):
# Test with title ID.
await hass.services.async_call(
"media_player",
"select_source",
{ATTR_ENTITY_ID: mock_entity_id, ATTR_INPUT_SOURCE: MOCK_TITLE_ID},
blocking=True,
)
assert len(mock_call.mock_calls) == 1 | [
"async",
"def",
"test_select_source_id",
"(",
"hass",
",",
"patch_load_json",
")",
":",
"patch_load_json",
".",
"return_value",
"=",
"{",
"MOCK_TITLE_ID",
":",
"MOCK_GAMES_DATA",
"}",
"with",
"patch",
"(",
"\"pyps4_2ndscreen.ps4.get_status\"",
",",
"return_value",
"=",
"MOCK_STATUS_IDLE",
")",
":",
"mock_entity_id",
"=",
"await",
"setup_mock_component",
"(",
"hass",
")",
"with",
"patch",
"(",
"\"pyps4_2ndscreen.ps4.Ps4Async.start_title\"",
")",
"as",
"mock_call",
",",
"patch",
"(",
"\"homeassistant.components.ps4.media_player.PS4Device.async_update\"",
")",
":",
"# Test with title ID.",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"media_player\"",
",",
"\"select_source\"",
",",
"{",
"ATTR_ENTITY_ID",
":",
"mock_entity_id",
",",
"ATTR_INPUT_SOURCE",
":",
"MOCK_TITLE_ID",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"assert",
"len",
"(",
"mock_call",
".",
"mock_calls",
")",
"==",
"1"
] | [
472,
0
] | [
489,
41
] | python | en | ['en', 'en', 'en'] | True |
test_ps4_send_command | (hass) | Test that ps4 send command service calls function. | Test that ps4 send command service calls function. | async def test_ps4_send_command(hass):
"""Test that ps4 send command service calls function."""
mock_entity_id = await setup_mock_component(hass)
with patch("pyps4_2ndscreen.ps4.Ps4Async.remote_control") as mock_call:
await hass.services.async_call(
DOMAIN,
"send_command",
{ATTR_ENTITY_ID: mock_entity_id, ATTR_COMMAND: "ps"},
blocking=True,
)
assert len(mock_call.mock_calls) == 1 | [
"async",
"def",
"test_ps4_send_command",
"(",
"hass",
")",
":",
"mock_entity_id",
"=",
"await",
"setup_mock_component",
"(",
"hass",
")",
"with",
"patch",
"(",
"\"pyps4_2ndscreen.ps4.Ps4Async.remote_control\"",
")",
"as",
"mock_call",
":",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"\"send_command\"",
",",
"{",
"ATTR_ENTITY_ID",
":",
"mock_entity_id",
",",
"ATTR_COMMAND",
":",
"\"ps\"",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"assert",
"len",
"(",
"mock_call",
".",
"mock_calls",
")",
"==",
"1"
] | [
492,
0
] | [
504,
41
] | python | en | ['en', 'en', 'en'] | True |
test_entry_is_unloaded | (hass) | Test that entry is unloaded. | Test that entry is unloaded. | async def test_entry_is_unloaded(hass):
"""Test that entry is unloaded."""
mock_entry = MockConfigEntry(
domain=ps4.DOMAIN, data=MOCK_DATA, version=VERSION, entry_id=MOCK_ENTRY_ID
)
mock_entity_id = await setup_mock_component(hass, mock_entry)
mock_unload = await ps4.async_unload_entry(hass, mock_entry)
assert mock_unload is True
assert not hass.data[PS4_DATA].devices
# Test that callback listener for entity is removed from protocol.
assert not hass.data[PS4_DATA].protocol.callbacks
assert hass.states.get(mock_entity_id) is None | [
"async",
"def",
"test_entry_is_unloaded",
"(",
"hass",
")",
":",
"mock_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"ps4",
".",
"DOMAIN",
",",
"data",
"=",
"MOCK_DATA",
",",
"version",
"=",
"VERSION",
",",
"entry_id",
"=",
"MOCK_ENTRY_ID",
")",
"mock_entity_id",
"=",
"await",
"setup_mock_component",
"(",
"hass",
",",
"mock_entry",
")",
"mock_unload",
"=",
"await",
"ps4",
".",
"async_unload_entry",
"(",
"hass",
",",
"mock_entry",
")",
"assert",
"mock_unload",
"is",
"True",
"assert",
"not",
"hass",
".",
"data",
"[",
"PS4_DATA",
"]",
".",
"devices",
"# Test that callback listener for entity is removed from protocol.",
"assert",
"not",
"hass",
".",
"data",
"[",
"PS4_DATA",
"]",
".",
"protocol",
".",
"callbacks",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"mock_entity_id",
")",
"is",
"None"
] | [
507,
0
] | [
521,
50
] | python | en | ['en', 'en', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Create the buienradar sensor. | Create the buienradar sensor. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Create the buienradar sensor."""
latitude = config.get(CONF_LATITUDE, hass.config.latitude)
longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
timeframe = config[CONF_TIMEFRAME]
if None in (latitude, longitude):
_LOGGER.error("Latitude or longitude not set in Home Assistant config")
return False
coordinates = {CONF_LATITUDE: float(latitude), CONF_LONGITUDE: float(longitude)}
_LOGGER.debug(
"Initializing buienradar sensor coordinate %s, timeframe %s",
coordinates,
timeframe,
)
dev = []
for sensor_type in config[CONF_MONITORED_CONDITIONS]:
dev.append(BrSensor(sensor_type, config.get(CONF_NAME), coordinates))
async_add_entities(dev)
data = BrData(hass, coordinates, timeframe, dev)
# schedule the first update in 1 minute from now:
await data.schedule_update(1) | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"latitude",
"=",
"config",
".",
"get",
"(",
"CONF_LATITUDE",
",",
"hass",
".",
"config",
".",
"latitude",
")",
"longitude",
"=",
"config",
".",
"get",
"(",
"CONF_LONGITUDE",
",",
"hass",
".",
"config",
".",
"longitude",
")",
"timeframe",
"=",
"config",
"[",
"CONF_TIMEFRAME",
"]",
"if",
"None",
"in",
"(",
"latitude",
",",
"longitude",
")",
":",
"_LOGGER",
".",
"error",
"(",
"\"Latitude or longitude not set in Home Assistant config\"",
")",
"return",
"False",
"coordinates",
"=",
"{",
"CONF_LATITUDE",
":",
"float",
"(",
"latitude",
")",
",",
"CONF_LONGITUDE",
":",
"float",
"(",
"longitude",
")",
"}",
"_LOGGER",
".",
"debug",
"(",
"\"Initializing buienradar sensor coordinate %s, timeframe %s\"",
",",
"coordinates",
",",
"timeframe",
",",
")",
"dev",
"=",
"[",
"]",
"for",
"sensor_type",
"in",
"config",
"[",
"CONF_MONITORED_CONDITIONS",
"]",
":",
"dev",
".",
"append",
"(",
"BrSensor",
"(",
"sensor_type",
",",
"config",
".",
"get",
"(",
"CONF_NAME",
")",
",",
"coordinates",
")",
")",
"async_add_entities",
"(",
"dev",
")",
"data",
"=",
"BrData",
"(",
"hass",
",",
"coordinates",
",",
"timeframe",
",",
"dev",
")",
"# schedule the first update in 1 minute from now:",
"await",
"data",
".",
"schedule_update",
"(",
"1",
")"
] | [
210,
0
] | [
235,
33
] | python | en | ['en', 'ms', 'en'] | True |
BrSensor.__init__ | (self, sensor_type, client_name, coordinates) | Initialize the sensor. | Initialize the sensor. | def __init__(self, sensor_type, client_name, coordinates):
"""Initialize the sensor."""
self.client_name = client_name
self._name = SENSOR_TYPES[sensor_type][0]
self.type = sensor_type
self._state = None
self._unit_of_measurement = SENSOR_TYPES[self.type][1]
self._entity_picture = None
self._attribution = None
self._measured = None
self._stationname = None
self._unique_id = self.uid(coordinates)
# All continuous sensors should be forced to be updated
self._force_update = self.type != SYMBOL and not self.type.startswith(CONDITION)
if self.type.startswith(PRECIPITATION_FORECAST):
self._timeframe = None | [
"def",
"__init__",
"(",
"self",
",",
"sensor_type",
",",
"client_name",
",",
"coordinates",
")",
":",
"self",
".",
"client_name",
"=",
"client_name",
"self",
".",
"_name",
"=",
"SENSOR_TYPES",
"[",
"sensor_type",
"]",
"[",
"0",
"]",
"self",
".",
"type",
"=",
"sensor_type",
"self",
".",
"_state",
"=",
"None",
"self",
".",
"_unit_of_measurement",
"=",
"SENSOR_TYPES",
"[",
"self",
".",
"type",
"]",
"[",
"1",
"]",
"self",
".",
"_entity_picture",
"=",
"None",
"self",
".",
"_attribution",
"=",
"None",
"self",
".",
"_measured",
"=",
"None",
"self",
".",
"_stationname",
"=",
"None",
"self",
".",
"_unique_id",
"=",
"self",
".",
"uid",
"(",
"coordinates",
")",
"# All continuous sensors should be forced to be updated",
"self",
".",
"_force_update",
"=",
"self",
".",
"type",
"!=",
"SYMBOL",
"and",
"not",
"self",
".",
"type",
".",
"startswith",
"(",
"CONDITION",
")",
"if",
"self",
".",
"type",
".",
"startswith",
"(",
"PRECIPITATION_FORECAST",
")",
":",
"self",
".",
"_timeframe",
"=",
"None"
] | [
241,
4
] | [
258,
34
] | python | en | ['en', 'en', 'en'] | True |
BrSensor.uid | (self, coordinates) | Generate a unique id using coordinates and sensor type. | Generate a unique id using coordinates and sensor type. | def uid(self, coordinates):
"""Generate a unique id using coordinates and sensor type."""
# The combination of the location, name and sensor type is unique
return "{:2.6f}{:2.6f}{}".format(
coordinates[CONF_LATITUDE], coordinates[CONF_LONGITUDE], self.type
) | [
"def",
"uid",
"(",
"self",
",",
"coordinates",
")",
":",
"# The combination of the location, name and sensor type is unique",
"return",
"\"{:2.6f}{:2.6f}{}\"",
".",
"format",
"(",
"coordinates",
"[",
"CONF_LATITUDE",
"]",
",",
"coordinates",
"[",
"CONF_LONGITUDE",
"]",
",",
"self",
".",
"type",
")"
] | [
260,
4
] | [
265,
9
] | python | en | ['en', 'en', 'en'] | True |
BrSensor.data_updated | (self, data) | Update data. | Update data. | def data_updated(self, data):
"""Update data."""
if self._load_data(data) and self.hass:
self.async_write_ha_state() | [
"def",
"data_updated",
"(",
"self",
",",
"data",
")",
":",
"if",
"self",
".",
"_load_data",
"(",
"data",
")",
"and",
"self",
".",
"hass",
":",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
268,
4
] | [
271,
39
] | python | co | ['fr', 'co', 'en'] | False |
BrSensor._load_data | (self, data) | Load the sensor with relevant data. | Load the sensor with relevant data. | def _load_data(self, data):
"""Load the sensor with relevant data."""
# Find sensor
# Check if we have a new measurement,
# otherwise we do not have to update the sensor
if self._measured == data.get(MEASURED):
return False
self._attribution = data.get(ATTRIBUTION)
self._stationname = data.get(STATIONNAME)
self._measured = data.get(MEASURED)
if (
self.type.endswith("_1d")
or self.type.endswith("_2d")
or self.type.endswith("_3d")
or self.type.endswith("_4d")
or self.type.endswith("_5d")
):
# update forcasting sensors:
fcday = 0
if self.type.endswith("_2d"):
fcday = 1
if self.type.endswith("_3d"):
fcday = 2
if self.type.endswith("_4d"):
fcday = 3
if self.type.endswith("_5d"):
fcday = 4
# update weather symbol & status text
if self.type.startswith(SYMBOL) or self.type.startswith(CONDITION):
try:
condition = data.get(FORECAST)[fcday].get(CONDITION)
except IndexError:
_LOGGER.warning("No forecast for fcday=%s...", fcday)
return False
if condition:
new_state = condition.get(CONDITION)
if self.type.startswith(SYMBOL):
new_state = condition.get(EXACTNL)
if self.type.startswith("conditioncode"):
new_state = condition.get(CONDCODE)
if self.type.startswith("conditiondetailed"):
new_state = condition.get(DETAILED)
if self.type.startswith("conditionexact"):
new_state = condition.get(EXACT)
img = condition.get(IMAGE)
if new_state != self._state or img != self._entity_picture:
self._state = new_state
self._entity_picture = img
return True
return False
if self.type.startswith(WINDSPEED):
# hass wants windspeeds in km/h not m/s, so convert:
try:
self._state = data.get(FORECAST)[fcday].get(self.type[:-3])
if self._state is not None:
self._state = round(self._state * 3.6, 1)
return True
except IndexError:
_LOGGER.warning("No forecast for fcday=%s...", fcday)
return False
# update all other sensors
try:
self._state = data.get(FORECAST)[fcday].get(self.type[:-3])
return True
except IndexError:
_LOGGER.warning("No forecast for fcday=%s...", fcday)
return False
if self.type == SYMBOL or self.type.startswith(CONDITION):
# update weather symbol & status text
condition = data.get(CONDITION)
if condition:
if self.type == SYMBOL:
new_state = condition.get(EXACTNL)
if self.type == CONDITION:
new_state = condition.get(CONDITION)
if self.type == "conditioncode":
new_state = condition.get(CONDCODE)
if self.type == "conditiondetailed":
new_state = condition.get(DETAILED)
if self.type == "conditionexact":
new_state = condition.get(EXACT)
img = condition.get(IMAGE)
if new_state != self._state or img != self._entity_picture:
self._state = new_state
self._entity_picture = img
return True
return False
if self.type.startswith(PRECIPITATION_FORECAST):
# update nested precipitation forecast sensors
nested = data.get(PRECIPITATION_FORECAST)
self._timeframe = nested.get(TIMEFRAME)
self._state = nested.get(self.type[len(PRECIPITATION_FORECAST) + 1 :])
return True
if self.type == WINDSPEED or self.type == WINDGUST:
# hass wants windspeeds in km/h not m/s, so convert:
self._state = data.get(self.type)
if self._state is not None:
self._state = round(data.get(self.type) * 3.6, 1)
return True
if self.type == VISIBILITY:
# hass wants visibility in km (not m), so convert:
self._state = data.get(self.type)
if self._state is not None:
self._state = round(self._state / 1000, 1)
return True
# update all other sensors
self._state = data.get(self.type)
return True | [
"def",
"_load_data",
"(",
"self",
",",
"data",
")",
":",
"# Find sensor",
"# Check if we have a new measurement,",
"# otherwise we do not have to update the sensor",
"if",
"self",
".",
"_measured",
"==",
"data",
".",
"get",
"(",
"MEASURED",
")",
":",
"return",
"False",
"self",
".",
"_attribution",
"=",
"data",
".",
"get",
"(",
"ATTRIBUTION",
")",
"self",
".",
"_stationname",
"=",
"data",
".",
"get",
"(",
"STATIONNAME",
")",
"self",
".",
"_measured",
"=",
"data",
".",
"get",
"(",
"MEASURED",
")",
"if",
"(",
"self",
".",
"type",
".",
"endswith",
"(",
"\"_1d\"",
")",
"or",
"self",
".",
"type",
".",
"endswith",
"(",
"\"_2d\"",
")",
"or",
"self",
".",
"type",
".",
"endswith",
"(",
"\"_3d\"",
")",
"or",
"self",
".",
"type",
".",
"endswith",
"(",
"\"_4d\"",
")",
"or",
"self",
".",
"type",
".",
"endswith",
"(",
"\"_5d\"",
")",
")",
":",
"# update forcasting sensors:",
"fcday",
"=",
"0",
"if",
"self",
".",
"type",
".",
"endswith",
"(",
"\"_2d\"",
")",
":",
"fcday",
"=",
"1",
"if",
"self",
".",
"type",
".",
"endswith",
"(",
"\"_3d\"",
")",
":",
"fcday",
"=",
"2",
"if",
"self",
".",
"type",
".",
"endswith",
"(",
"\"_4d\"",
")",
":",
"fcday",
"=",
"3",
"if",
"self",
".",
"type",
".",
"endswith",
"(",
"\"_5d\"",
")",
":",
"fcday",
"=",
"4",
"# update weather symbol & status text",
"if",
"self",
".",
"type",
".",
"startswith",
"(",
"SYMBOL",
")",
"or",
"self",
".",
"type",
".",
"startswith",
"(",
"CONDITION",
")",
":",
"try",
":",
"condition",
"=",
"data",
".",
"get",
"(",
"FORECAST",
")",
"[",
"fcday",
"]",
".",
"get",
"(",
"CONDITION",
")",
"except",
"IndexError",
":",
"_LOGGER",
".",
"warning",
"(",
"\"No forecast for fcday=%s...\"",
",",
"fcday",
")",
"return",
"False",
"if",
"condition",
":",
"new_state",
"=",
"condition",
".",
"get",
"(",
"CONDITION",
")",
"if",
"self",
".",
"type",
".",
"startswith",
"(",
"SYMBOL",
")",
":",
"new_state",
"=",
"condition",
".",
"get",
"(",
"EXACTNL",
")",
"if",
"self",
".",
"type",
".",
"startswith",
"(",
"\"conditioncode\"",
")",
":",
"new_state",
"=",
"condition",
".",
"get",
"(",
"CONDCODE",
")",
"if",
"self",
".",
"type",
".",
"startswith",
"(",
"\"conditiondetailed\"",
")",
":",
"new_state",
"=",
"condition",
".",
"get",
"(",
"DETAILED",
")",
"if",
"self",
".",
"type",
".",
"startswith",
"(",
"\"conditionexact\"",
")",
":",
"new_state",
"=",
"condition",
".",
"get",
"(",
"EXACT",
")",
"img",
"=",
"condition",
".",
"get",
"(",
"IMAGE",
")",
"if",
"new_state",
"!=",
"self",
".",
"_state",
"or",
"img",
"!=",
"self",
".",
"_entity_picture",
":",
"self",
".",
"_state",
"=",
"new_state",
"self",
".",
"_entity_picture",
"=",
"img",
"return",
"True",
"return",
"False",
"if",
"self",
".",
"type",
".",
"startswith",
"(",
"WINDSPEED",
")",
":",
"# hass wants windspeeds in km/h not m/s, so convert:",
"try",
":",
"self",
".",
"_state",
"=",
"data",
".",
"get",
"(",
"FORECAST",
")",
"[",
"fcday",
"]",
".",
"get",
"(",
"self",
".",
"type",
"[",
":",
"-",
"3",
"]",
")",
"if",
"self",
".",
"_state",
"is",
"not",
"None",
":",
"self",
".",
"_state",
"=",
"round",
"(",
"self",
".",
"_state",
"*",
"3.6",
",",
"1",
")",
"return",
"True",
"except",
"IndexError",
":",
"_LOGGER",
".",
"warning",
"(",
"\"No forecast for fcday=%s...\"",
",",
"fcday",
")",
"return",
"False",
"# update all other sensors",
"try",
":",
"self",
".",
"_state",
"=",
"data",
".",
"get",
"(",
"FORECAST",
")",
"[",
"fcday",
"]",
".",
"get",
"(",
"self",
".",
"type",
"[",
":",
"-",
"3",
"]",
")",
"return",
"True",
"except",
"IndexError",
":",
"_LOGGER",
".",
"warning",
"(",
"\"No forecast for fcday=%s...\"",
",",
"fcday",
")",
"return",
"False",
"if",
"self",
".",
"type",
"==",
"SYMBOL",
"or",
"self",
".",
"type",
".",
"startswith",
"(",
"CONDITION",
")",
":",
"# update weather symbol & status text",
"condition",
"=",
"data",
".",
"get",
"(",
"CONDITION",
")",
"if",
"condition",
":",
"if",
"self",
".",
"type",
"==",
"SYMBOL",
":",
"new_state",
"=",
"condition",
".",
"get",
"(",
"EXACTNL",
")",
"if",
"self",
".",
"type",
"==",
"CONDITION",
":",
"new_state",
"=",
"condition",
".",
"get",
"(",
"CONDITION",
")",
"if",
"self",
".",
"type",
"==",
"\"conditioncode\"",
":",
"new_state",
"=",
"condition",
".",
"get",
"(",
"CONDCODE",
")",
"if",
"self",
".",
"type",
"==",
"\"conditiondetailed\"",
":",
"new_state",
"=",
"condition",
".",
"get",
"(",
"DETAILED",
")",
"if",
"self",
".",
"type",
"==",
"\"conditionexact\"",
":",
"new_state",
"=",
"condition",
".",
"get",
"(",
"EXACT",
")",
"img",
"=",
"condition",
".",
"get",
"(",
"IMAGE",
")",
"if",
"new_state",
"!=",
"self",
".",
"_state",
"or",
"img",
"!=",
"self",
".",
"_entity_picture",
":",
"self",
".",
"_state",
"=",
"new_state",
"self",
".",
"_entity_picture",
"=",
"img",
"return",
"True",
"return",
"False",
"if",
"self",
".",
"type",
".",
"startswith",
"(",
"PRECIPITATION_FORECAST",
")",
":",
"# update nested precipitation forecast sensors",
"nested",
"=",
"data",
".",
"get",
"(",
"PRECIPITATION_FORECAST",
")",
"self",
".",
"_timeframe",
"=",
"nested",
".",
"get",
"(",
"TIMEFRAME",
")",
"self",
".",
"_state",
"=",
"nested",
".",
"get",
"(",
"self",
".",
"type",
"[",
"len",
"(",
"PRECIPITATION_FORECAST",
")",
"+",
"1",
":",
"]",
")",
"return",
"True",
"if",
"self",
".",
"type",
"==",
"WINDSPEED",
"or",
"self",
".",
"type",
"==",
"WINDGUST",
":",
"# hass wants windspeeds in km/h not m/s, so convert:",
"self",
".",
"_state",
"=",
"data",
".",
"get",
"(",
"self",
".",
"type",
")",
"if",
"self",
".",
"_state",
"is",
"not",
"None",
":",
"self",
".",
"_state",
"=",
"round",
"(",
"data",
".",
"get",
"(",
"self",
".",
"type",
")",
"*",
"3.6",
",",
"1",
")",
"return",
"True",
"if",
"self",
".",
"type",
"==",
"VISIBILITY",
":",
"# hass wants visibility in km (not m), so convert:",
"self",
".",
"_state",
"=",
"data",
".",
"get",
"(",
"self",
".",
"type",
")",
"if",
"self",
".",
"_state",
"is",
"not",
"None",
":",
"self",
".",
"_state",
"=",
"round",
"(",
"self",
".",
"_state",
"/",
"1000",
",",
"1",
")",
"return",
"True",
"# update all other sensors",
"self",
".",
"_state",
"=",
"data",
".",
"get",
"(",
"self",
".",
"type",
")",
"return",
"True"
] | [
274,
4
] | [
399,
19
] | python | en | ['en', 'en', 'en'] | True |
BrSensor.attribution | (self) | Return the attribution. | Return the attribution. | def attribution(self):
"""Return the attribution."""
return self._attribution | [
"def",
"attribution",
"(",
"self",
")",
":",
"return",
"self",
".",
"_attribution"
] | [
402,
4
] | [
404,
32
] | python | en | ['en', 'ja', 'en'] | True |
BrSensor.unique_id | (self) | Return the unique id. | Return the unique id. | def unique_id(self):
"""Return the unique id."""
return self._unique_id | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unique_id"
] | [
407,
4
] | [
409,
30
] | python | en | ['en', 'la', 'en'] | True |
BrSensor.name | (self) | Return the name of the sensor. | Return the name of the sensor. | def name(self):
"""Return the name of the sensor."""
return f"{self.client_name} {self._name}" | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"f\"{self.client_name} {self._name}\""
] | [
412,
4
] | [
414,
49
] | python | en | ['en', 'mi', 'en'] | True |
BrSensor.state | (self) | Return the state of the device. | Return the state of the device. | def state(self):
"""Return the state of the device."""
return self._state | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
417,
4
] | [
419,
26
] | python | en | ['en', 'en', 'en'] | True |
BrSensor.should_poll | (self) | No polling needed. | No polling needed. | def should_poll(self):
"""No polling needed."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
422,
4
] | [
424,
20
] | python | en | ['en', 'en', 'en'] | True |
BrSensor.entity_picture | (self) | Weather symbol if type is symbol. | Weather symbol if type is symbol. | def entity_picture(self):
"""Weather symbol if type is symbol."""
return self._entity_picture | [
"def",
"entity_picture",
"(",
"self",
")",
":",
"return",
"self",
".",
"_entity_picture"
] | [
427,
4
] | [
429,
35
] | python | en | ['en', 'sr', 'en'] | True |
BrSensor.device_state_attributes | (self) | Return the state attributes. | Return the state attributes. | def device_state_attributes(self):
"""Return the state attributes."""
if self.type.startswith(PRECIPITATION_FORECAST):
result = {ATTR_ATTRIBUTION: self._attribution}
if self._timeframe is not None:
result[TIMEFRAME_LABEL] = "%d min" % (self._timeframe)
return result
result = {
ATTR_ATTRIBUTION: self._attribution,
SENSOR_TYPES["stationname"][0]: self._stationname,
}
if self._measured is not None:
# convert datetime (Europe/Amsterdam) into local datetime
local_dt = dt_util.as_local(self._measured)
result[MEASURED_LABEL] = local_dt.strftime("%c")
return result | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"if",
"self",
".",
"type",
".",
"startswith",
"(",
"PRECIPITATION_FORECAST",
")",
":",
"result",
"=",
"{",
"ATTR_ATTRIBUTION",
":",
"self",
".",
"_attribution",
"}",
"if",
"self",
".",
"_timeframe",
"is",
"not",
"None",
":",
"result",
"[",
"TIMEFRAME_LABEL",
"]",
"=",
"\"%d min\"",
"%",
"(",
"self",
".",
"_timeframe",
")",
"return",
"result",
"result",
"=",
"{",
"ATTR_ATTRIBUTION",
":",
"self",
".",
"_attribution",
",",
"SENSOR_TYPES",
"[",
"\"stationname\"",
"]",
"[",
"0",
"]",
":",
"self",
".",
"_stationname",
",",
"}",
"if",
"self",
".",
"_measured",
"is",
"not",
"None",
":",
"# convert datetime (Europe/Amsterdam) into local datetime",
"local_dt",
"=",
"dt_util",
".",
"as_local",
"(",
"self",
".",
"_measured",
")",
"result",
"[",
"MEASURED_LABEL",
"]",
"=",
"local_dt",
".",
"strftime",
"(",
"\"%c\"",
")",
"return",
"result"
] | [
432,
4
] | [
450,
21
] | python | en | ['en', 'en', 'en'] | True |
BrSensor.unit_of_measurement | (self) | Return the unit of measurement of this entity, if any. | Return the unit of measurement of this entity, if any. | def unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unit_of_measurement"
] | [
453,
4
] | [
455,
40
] | python | en | ['en', 'en', 'en'] | True |
BrSensor.icon | (self) | Return possible sensor specific icon. | Return possible sensor specific icon. | def icon(self):
"""Return possible sensor specific icon."""
return SENSOR_TYPES[self.type][2] | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"SENSOR_TYPES",
"[",
"self",
".",
"type",
"]",
"[",
"2",
"]"
] | [
458,
4
] | [
460,
41
] | python | en | ['en', 'it', 'en'] | True |
BrSensor.force_update | (self) | Return true for continuous sensors, false for discrete sensors. | Return true for continuous sensors, false for discrete sensors. | def force_update(self):
"""Return true for continuous sensors, false for discrete sensors."""
return self._force_update | [
"def",
"force_update",
"(",
"self",
")",
":",
"return",
"self",
".",
"_force_update"
] | [
463,
4
] | [
465,
33
] | python | en | ['en', 'ca', 'en'] | True |
async_setup | (hass, config) | Set up the emulated roku component. | Set up the emulated roku component. | async def async_setup(hass, config):
"""Set up the emulated roku component."""
conf = config.get(DOMAIN)
if conf is None:
return True
existing_servers = configured_servers(hass)
for entry in conf[CONF_SERVERS]:
if entry[CONF_NAME] not in existing_servers:
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=entry
)
)
return True | [
"async",
"def",
"async_setup",
"(",
"hass",
",",
"config",
")",
":",
"conf",
"=",
"config",
".",
"get",
"(",
"DOMAIN",
")",
"if",
"conf",
"is",
"None",
":",
"return",
"True",
"existing_servers",
"=",
"configured_servers",
"(",
"hass",
")",
"for",
"entry",
"in",
"conf",
"[",
"CONF_SERVERS",
"]",
":",
"if",
"entry",
"[",
"CONF_NAME",
"]",
"not",
"in",
"existing_servers",
":",
"hass",
".",
"async_create_task",
"(",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"config_entries",
".",
"SOURCE_IMPORT",
"}",
",",
"data",
"=",
"entry",
")",
")",
"return",
"True"
] | [
44,
0
] | [
61,
15
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config_entry) | Set up an emulated roku server from a config entry. | Set up an emulated roku server from a config entry. | async def async_setup_entry(hass, config_entry):
"""Set up an emulated roku server from a config entry."""
config = config_entry.data
if DOMAIN not in hass.data:
hass.data[DOMAIN] = {}
name = config[CONF_NAME]
listen_port = config[CONF_LISTEN_PORT]
host_ip = config.get(CONF_HOST_IP) or util.get_local_ip()
advertise_ip = config.get(CONF_ADVERTISE_IP)
advertise_port = config.get(CONF_ADVERTISE_PORT)
upnp_bind_multicast = config.get(CONF_UPNP_BIND_MULTICAST)
server = EmulatedRoku(
hass,
name,
host_ip,
listen_port,
advertise_ip,
advertise_port,
upnp_bind_multicast,
)
hass.data[DOMAIN][name] = server
return await server.setup() | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
")",
":",
"config",
"=",
"config_entry",
".",
"data",
"if",
"DOMAIN",
"not",
"in",
"hass",
".",
"data",
":",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"=",
"{",
"}",
"name",
"=",
"config",
"[",
"CONF_NAME",
"]",
"listen_port",
"=",
"config",
"[",
"CONF_LISTEN_PORT",
"]",
"host_ip",
"=",
"config",
".",
"get",
"(",
"CONF_HOST_IP",
")",
"or",
"util",
".",
"get_local_ip",
"(",
")",
"advertise_ip",
"=",
"config",
".",
"get",
"(",
"CONF_ADVERTISE_IP",
")",
"advertise_port",
"=",
"config",
".",
"get",
"(",
"CONF_ADVERTISE_PORT",
")",
"upnp_bind_multicast",
"=",
"config",
".",
"get",
"(",
"CONF_UPNP_BIND_MULTICAST",
")",
"server",
"=",
"EmulatedRoku",
"(",
"hass",
",",
"name",
",",
"host_ip",
",",
"listen_port",
",",
"advertise_ip",
",",
"advertise_port",
",",
"upnp_bind_multicast",
",",
")",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"name",
"]",
"=",
"server",
"return",
"await",
"server",
".",
"setup",
"(",
")"
] | [
64,
0
] | [
90,
31
] | python | en | ['en', 'en', 'en'] | True |
async_unload_entry | (hass, entry) | Unload a config entry. | Unload a config entry. | async def async_unload_entry(hass, entry):
"""Unload a config entry."""
name = entry.data[CONF_NAME]
server = hass.data[DOMAIN].pop(name)
return await server.unload() | [
"async",
"def",
"async_unload_entry",
"(",
"hass",
",",
"entry",
")",
":",
"name",
"=",
"entry",
".",
"data",
"[",
"CONF_NAME",
"]",
"server",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
".",
"pop",
"(",
"name",
")",
"return",
"await",
"server",
".",
"unload",
"(",
")"
] | [
93,
0
] | [
97,
32
] | python | en | ['en', 'es', 'en'] | True |
assert_setup_sensor | (hass, config, count=1) | Set up the sensor and assert it's been created. | Set up the sensor and assert it's been created. | async def assert_setup_sensor(hass, config, count=1):
"""Set up the sensor and assert it's been created."""
with assert_setup_component(count):
assert await async_setup_component(hass, sensor.DOMAIN, config)
await hass.async_block_till_done() | [
"async",
"def",
"assert_setup_sensor",
"(",
"hass",
",",
"config",
",",
"count",
"=",
"1",
")",
":",
"with",
"assert_setup_component",
"(",
"count",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"sensor",
".",
"DOMAIN",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")"
] | [
48,
0
] | [
52,
42
] | python | en | ['en', 'en', 'en'] | True |
mock_nextbus | () | Create a mock py_nextbus module. | Create a mock py_nextbus module. | def mock_nextbus():
"""Create a mock py_nextbus module."""
with patch(
"homeassistant.components.nextbus.sensor.NextBusClient"
) as NextBusClient:
yield NextBusClient | [
"def",
"mock_nextbus",
"(",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.nextbus.sensor.NextBusClient\"",
")",
"as",
"NextBusClient",
":",
"yield",
"NextBusClient"
] | [
56,
0
] | [
61,
27
] | python | en | ['en', 'ro', 'it'] | False |
mock_nextbus_predictions | (mock_nextbus) | Create a mock of NextBusClient predictions. | Create a mock of NextBusClient predictions. | def mock_nextbus_predictions(mock_nextbus):
"""Create a mock of NextBusClient predictions."""
instance = mock_nextbus.return_value
instance.get_predictions_for_multi_stops.return_value = BASIC_RESULTS
yield instance.get_predictions_for_multi_stops | [
"def",
"mock_nextbus_predictions",
"(",
"mock_nextbus",
")",
":",
"instance",
"=",
"mock_nextbus",
".",
"return_value",
"instance",
".",
"get_predictions_for_multi_stops",
".",
"return_value",
"=",
"BASIC_RESULTS",
"yield",
"instance",
".",
"get_predictions_for_multi_stops"
] | [
65,
0
] | [
70,
50
] | python | en | ['en', 'en', 'en'] | True |
mock_nextbus_lists | (mock_nextbus) | Mock all list functions in nextbus to test validate logic. | Mock all list functions in nextbus to test validate logic. | def mock_nextbus_lists(mock_nextbus):
"""Mock all list functions in nextbus to test validate logic."""
instance = mock_nextbus.return_value
instance.get_agency_list.return_value = {
"agency": [{"tag": "sf-muni", "title": "San Francisco Muni"}]
}
instance.get_route_list.return_value = {
"route": [{"tag": "F", "title": "F - Market & Wharves"}]
}
instance.get_route_config.return_value = {
"route": {"stop": [{"tag": "5650", "title": "Market St & 7th St"}]}
} | [
"def",
"mock_nextbus_lists",
"(",
"mock_nextbus",
")",
":",
"instance",
"=",
"mock_nextbus",
".",
"return_value",
"instance",
".",
"get_agency_list",
".",
"return_value",
"=",
"{",
"\"agency\"",
":",
"[",
"{",
"\"tag\"",
":",
"\"sf-muni\"",
",",
"\"title\"",
":",
"\"San Francisco Muni\"",
"}",
"]",
"}",
"instance",
".",
"get_route_list",
".",
"return_value",
"=",
"{",
"\"route\"",
":",
"[",
"{",
"\"tag\"",
":",
"\"F\"",
",",
"\"title\"",
":",
"\"F - Market & Wharves\"",
"}",
"]",
"}",
"instance",
".",
"get_route_config",
".",
"return_value",
"=",
"{",
"\"route\"",
":",
"{",
"\"stop\"",
":",
"[",
"{",
"\"tag\"",
":",
"\"5650\"",
",",
"\"title\"",
":",
"\"Market St & 7th St\"",
"}",
"]",
"}",
"}"
] | [
74,
0
] | [
85,
5
] | python | en | ['en', 'en', 'en'] | True |
test_valid_config | (hass, mock_nextbus, mock_nextbus_lists) | Test that sensor is set up properly with valid config. | Test that sensor is set up properly with valid config. | async def test_valid_config(hass, mock_nextbus, mock_nextbus_lists):
"""Test that sensor is set up properly with valid config."""
await assert_setup_sensor(hass, CONFIG_BASIC) | [
"async",
"def",
"test_valid_config",
"(",
"hass",
",",
"mock_nextbus",
",",
"mock_nextbus_lists",
")",
":",
"await",
"assert_setup_sensor",
"(",
"hass",
",",
"CONFIG_BASIC",
")"
] | [
88,
0
] | [
90,
49
] | python | en | ['en', 'en', 'en'] | True |
test_invalid_config | (hass, mock_nextbus, mock_nextbus_lists) | Checks that component is not setup when missing information. | Checks that component is not setup when missing information. | async def test_invalid_config(hass, mock_nextbus, mock_nextbus_lists):
"""Checks that component is not setup when missing information."""
await assert_setup_sensor(hass, CONFIG_INVALID_MISSING, count=0) | [
"async",
"def",
"test_invalid_config",
"(",
"hass",
",",
"mock_nextbus",
",",
"mock_nextbus_lists",
")",
":",
"await",
"assert_setup_sensor",
"(",
"hass",
",",
"CONFIG_INVALID_MISSING",
",",
"count",
"=",
"0",
")"
] | [
93,
0
] | [
95,
68
] | python | en | ['en', 'en', 'en'] | True |
test_validate_tags | (hass, mock_nextbus, mock_nextbus_lists) | Test that additional validation against the API is successful. | Test that additional validation against the API is successful. | async def test_validate_tags(hass, mock_nextbus, mock_nextbus_lists):
"""Test that additional validation against the API is successful."""
# with self.subTest('Valid everything'):
assert nextbus.validate_tags(mock_nextbus(), VALID_AGENCY, VALID_ROUTE, VALID_STOP)
# with self.subTest('Invalid agency'):
assert not nextbus.validate_tags(
mock_nextbus(), "not-valid", VALID_ROUTE, VALID_STOP
)
# with self.subTest('Invalid route'):
assert not nextbus.validate_tags(mock_nextbus(), VALID_AGENCY, "0", VALID_STOP)
# with self.subTest('Invalid stop'):
assert not nextbus.validate_tags(mock_nextbus(), VALID_AGENCY, VALID_ROUTE, 0) | [
"async",
"def",
"test_validate_tags",
"(",
"hass",
",",
"mock_nextbus",
",",
"mock_nextbus_lists",
")",
":",
"# with self.subTest('Valid everything'):",
"assert",
"nextbus",
".",
"validate_tags",
"(",
"mock_nextbus",
"(",
")",
",",
"VALID_AGENCY",
",",
"VALID_ROUTE",
",",
"VALID_STOP",
")",
"# with self.subTest('Invalid agency'):",
"assert",
"not",
"nextbus",
".",
"validate_tags",
"(",
"mock_nextbus",
"(",
")",
",",
"\"not-valid\"",
",",
"VALID_ROUTE",
",",
"VALID_STOP",
")",
"# with self.subTest('Invalid route'):",
"assert",
"not",
"nextbus",
".",
"validate_tags",
"(",
"mock_nextbus",
"(",
")",
",",
"VALID_AGENCY",
",",
"\"0\"",
",",
"VALID_STOP",
")",
"# with self.subTest('Invalid stop'):",
"assert",
"not",
"nextbus",
".",
"validate_tags",
"(",
"mock_nextbus",
"(",
")",
",",
"VALID_AGENCY",
",",
"VALID_ROUTE",
",",
"0",
")"
] | [
98,
0
] | [
111,
82
] | python | en | ['en', 'en', 'en'] | True |
test_verify_valid_state | (
hass, mock_nextbus, mock_nextbus_lists, mock_nextbus_predictions
) | Verify all attributes are set from a valid response. | Verify all attributes are set from a valid response. | async def test_verify_valid_state(
hass, mock_nextbus, mock_nextbus_lists, mock_nextbus_predictions
):
"""Verify all attributes are set from a valid response."""
await assert_setup_sensor(hass, CONFIG_BASIC)
mock_nextbus_predictions.assert_called_once_with(
[{"stop_tag": VALID_STOP, "route_tag": VALID_ROUTE}], VALID_AGENCY
)
state = hass.states.get(SENSOR_ID_SHORT)
assert state is not None
assert state.state == "2019-03-28T21:09:31+00:00"
assert state.attributes["agency"] == VALID_AGENCY_TITLE
assert state.attributes["route"] == VALID_ROUTE_TITLE
assert state.attributes["stop"] == VALID_STOP_TITLE
assert state.attributes["direction"] == "Outbound"
assert state.attributes["upcoming"] == "1, 2, 3" | [
"async",
"def",
"test_verify_valid_state",
"(",
"hass",
",",
"mock_nextbus",
",",
"mock_nextbus_lists",
",",
"mock_nextbus_predictions",
")",
":",
"await",
"assert_setup_sensor",
"(",
"hass",
",",
"CONFIG_BASIC",
")",
"mock_nextbus_predictions",
".",
"assert_called_once_with",
"(",
"[",
"{",
"\"stop_tag\"",
":",
"VALID_STOP",
",",
"\"route_tag\"",
":",
"VALID_ROUTE",
"}",
"]",
",",
"VALID_AGENCY",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"SENSOR_ID_SHORT",
")",
"assert",
"state",
"is",
"not",
"None",
"assert",
"state",
".",
"state",
"==",
"\"2019-03-28T21:09:31+00:00\"",
"assert",
"state",
".",
"attributes",
"[",
"\"agency\"",
"]",
"==",
"VALID_AGENCY_TITLE",
"assert",
"state",
".",
"attributes",
"[",
"\"route\"",
"]",
"==",
"VALID_ROUTE_TITLE",
"assert",
"state",
".",
"attributes",
"[",
"\"stop\"",
"]",
"==",
"VALID_STOP_TITLE",
"assert",
"state",
".",
"attributes",
"[",
"\"direction\"",
"]",
"==",
"\"Outbound\"",
"assert",
"state",
".",
"attributes",
"[",
"\"upcoming\"",
"]",
"==",
"\"1, 2, 3\""
] | [
114,
0
] | [
130,
52
] | python | en | ['en', 'en', 'en'] | True |
test_message_dict | (
hass, mock_nextbus, mock_nextbus_lists, mock_nextbus_predictions
) | Verify that a single dict message is rendered correctly. | Verify that a single dict message is rendered correctly. | async def test_message_dict(
hass, mock_nextbus, mock_nextbus_lists, mock_nextbus_predictions
):
"""Verify that a single dict message is rendered correctly."""
mock_nextbus_predictions.return_value = {
"predictions": {
"agencyTitle": VALID_AGENCY_TITLE,
"routeTitle": VALID_ROUTE_TITLE,
"stopTitle": VALID_STOP_TITLE,
"message": {"text": "Message"},
"direction": {
"title": "Outbound",
"prediction": [
{"minutes": "1", "epochTime": "1553807371000"},
{"minutes": "2", "epochTime": "1553807372000"},
{"minutes": "3", "epochTime": "1553807373000"},
],
},
}
}
await assert_setup_sensor(hass, CONFIG_BASIC)
state = hass.states.get(SENSOR_ID_SHORT)
assert state is not None
assert state.attributes["message"] == "Message" | [
"async",
"def",
"test_message_dict",
"(",
"hass",
",",
"mock_nextbus",
",",
"mock_nextbus_lists",
",",
"mock_nextbus_predictions",
")",
":",
"mock_nextbus_predictions",
".",
"return_value",
"=",
"{",
"\"predictions\"",
":",
"{",
"\"agencyTitle\"",
":",
"VALID_AGENCY_TITLE",
",",
"\"routeTitle\"",
":",
"VALID_ROUTE_TITLE",
",",
"\"stopTitle\"",
":",
"VALID_STOP_TITLE",
",",
"\"message\"",
":",
"{",
"\"text\"",
":",
"\"Message\"",
"}",
",",
"\"direction\"",
":",
"{",
"\"title\"",
":",
"\"Outbound\"",
",",
"\"prediction\"",
":",
"[",
"{",
"\"minutes\"",
":",
"\"1\"",
",",
"\"epochTime\"",
":",
"\"1553807371000\"",
"}",
",",
"{",
"\"minutes\"",
":",
"\"2\"",
",",
"\"epochTime\"",
":",
"\"1553807372000\"",
"}",
",",
"{",
"\"minutes\"",
":",
"\"3\"",
",",
"\"epochTime\"",
":",
"\"1553807373000\"",
"}",
",",
"]",
",",
"}",
",",
"}",
"}",
"await",
"assert_setup_sensor",
"(",
"hass",
",",
"CONFIG_BASIC",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"SENSOR_ID_SHORT",
")",
"assert",
"state",
"is",
"not",
"None",
"assert",
"state",
".",
"attributes",
"[",
"\"message\"",
"]",
"==",
"\"Message\""
] | [
133,
0
] | [
158,
51
] | python | en | ['en', 'en', 'en'] | True |
test_message_list | (
hass, mock_nextbus, mock_nextbus_lists, mock_nextbus_predictions
) | Verify that a list of messages are rendered correctly. | Verify that a list of messages are rendered correctly. | async def test_message_list(
hass, mock_nextbus, mock_nextbus_lists, mock_nextbus_predictions
):
"""Verify that a list of messages are rendered correctly."""
mock_nextbus_predictions.return_value = {
"predictions": {
"agencyTitle": VALID_AGENCY_TITLE,
"routeTitle": VALID_ROUTE_TITLE,
"stopTitle": VALID_STOP_TITLE,
"message": [{"text": "Message 1"}, {"text": "Message 2"}],
"direction": {
"title": "Outbound",
"prediction": [
{"minutes": "1", "epochTime": "1553807371000"},
{"minutes": "2", "epochTime": "1553807372000"},
{"minutes": "3", "epochTime": "1553807373000"},
],
},
}
}
await assert_setup_sensor(hass, CONFIG_BASIC)
state = hass.states.get(SENSOR_ID_SHORT)
assert state is not None
assert state.attributes["message"] == "Message 1 -- Message 2" | [
"async",
"def",
"test_message_list",
"(",
"hass",
",",
"mock_nextbus",
",",
"mock_nextbus_lists",
",",
"mock_nextbus_predictions",
")",
":",
"mock_nextbus_predictions",
".",
"return_value",
"=",
"{",
"\"predictions\"",
":",
"{",
"\"agencyTitle\"",
":",
"VALID_AGENCY_TITLE",
",",
"\"routeTitle\"",
":",
"VALID_ROUTE_TITLE",
",",
"\"stopTitle\"",
":",
"VALID_STOP_TITLE",
",",
"\"message\"",
":",
"[",
"{",
"\"text\"",
":",
"\"Message 1\"",
"}",
",",
"{",
"\"text\"",
":",
"\"Message 2\"",
"}",
"]",
",",
"\"direction\"",
":",
"{",
"\"title\"",
":",
"\"Outbound\"",
",",
"\"prediction\"",
":",
"[",
"{",
"\"minutes\"",
":",
"\"1\"",
",",
"\"epochTime\"",
":",
"\"1553807371000\"",
"}",
",",
"{",
"\"minutes\"",
":",
"\"2\"",
",",
"\"epochTime\"",
":",
"\"1553807372000\"",
"}",
",",
"{",
"\"minutes\"",
":",
"\"3\"",
",",
"\"epochTime\"",
":",
"\"1553807373000\"",
"}",
",",
"]",
",",
"}",
",",
"}",
"}",
"await",
"assert_setup_sensor",
"(",
"hass",
",",
"CONFIG_BASIC",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"SENSOR_ID_SHORT",
")",
"assert",
"state",
"is",
"not",
"None",
"assert",
"state",
".",
"attributes",
"[",
"\"message\"",
"]",
"==",
"\"Message 1 -- Message 2\""
] | [
161,
0
] | [
186,
66
] | python | en | ['en', 'en', 'en'] | True |
test_direction_list | (
hass, mock_nextbus, mock_nextbus_lists, mock_nextbus_predictions
) | Verify that a list of messages are rendered correctly. | Verify that a list of messages are rendered correctly. | async def test_direction_list(
hass, mock_nextbus, mock_nextbus_lists, mock_nextbus_predictions
):
"""Verify that a list of messages are rendered correctly."""
mock_nextbus_predictions.return_value = {
"predictions": {
"agencyTitle": VALID_AGENCY_TITLE,
"routeTitle": VALID_ROUTE_TITLE,
"stopTitle": VALID_STOP_TITLE,
"message": [{"text": "Message 1"}, {"text": "Message 2"}],
"direction": [
{
"title": "Outbound",
"prediction": [
{"minutes": "1", "epochTime": "1553807371000"},
{"minutes": "2", "epochTime": "1553807372000"},
{"minutes": "3", "epochTime": "1553807373000"},
],
},
{
"title": "Outbound 2",
"prediction": {"minutes": "0", "epochTime": "1553807374000"},
},
],
}
}
await assert_setup_sensor(hass, CONFIG_BASIC)
state = hass.states.get(SENSOR_ID_SHORT)
assert state is not None
assert state.state == "2019-03-28T21:09:31+00:00"
assert state.attributes["agency"] == VALID_AGENCY_TITLE
assert state.attributes["route"] == VALID_ROUTE_TITLE
assert state.attributes["stop"] == VALID_STOP_TITLE
assert state.attributes["direction"] == "Outbound, Outbound 2"
assert state.attributes["upcoming"] == "0, 1, 2, 3" | [
"async",
"def",
"test_direction_list",
"(",
"hass",
",",
"mock_nextbus",
",",
"mock_nextbus_lists",
",",
"mock_nextbus_predictions",
")",
":",
"mock_nextbus_predictions",
".",
"return_value",
"=",
"{",
"\"predictions\"",
":",
"{",
"\"agencyTitle\"",
":",
"VALID_AGENCY_TITLE",
",",
"\"routeTitle\"",
":",
"VALID_ROUTE_TITLE",
",",
"\"stopTitle\"",
":",
"VALID_STOP_TITLE",
",",
"\"message\"",
":",
"[",
"{",
"\"text\"",
":",
"\"Message 1\"",
"}",
",",
"{",
"\"text\"",
":",
"\"Message 2\"",
"}",
"]",
",",
"\"direction\"",
":",
"[",
"{",
"\"title\"",
":",
"\"Outbound\"",
",",
"\"prediction\"",
":",
"[",
"{",
"\"minutes\"",
":",
"\"1\"",
",",
"\"epochTime\"",
":",
"\"1553807371000\"",
"}",
",",
"{",
"\"minutes\"",
":",
"\"2\"",
",",
"\"epochTime\"",
":",
"\"1553807372000\"",
"}",
",",
"{",
"\"minutes\"",
":",
"\"3\"",
",",
"\"epochTime\"",
":",
"\"1553807373000\"",
"}",
",",
"]",
",",
"}",
",",
"{",
"\"title\"",
":",
"\"Outbound 2\"",
",",
"\"prediction\"",
":",
"{",
"\"minutes\"",
":",
"\"0\"",
",",
"\"epochTime\"",
":",
"\"1553807374000\"",
"}",
",",
"}",
",",
"]",
",",
"}",
"}",
"await",
"assert_setup_sensor",
"(",
"hass",
",",
"CONFIG_BASIC",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"SENSOR_ID_SHORT",
")",
"assert",
"state",
"is",
"not",
"None",
"assert",
"state",
".",
"state",
"==",
"\"2019-03-28T21:09:31+00:00\"",
"assert",
"state",
".",
"attributes",
"[",
"\"agency\"",
"]",
"==",
"VALID_AGENCY_TITLE",
"assert",
"state",
".",
"attributes",
"[",
"\"route\"",
"]",
"==",
"VALID_ROUTE_TITLE",
"assert",
"state",
".",
"attributes",
"[",
"\"stop\"",
"]",
"==",
"VALID_STOP_TITLE",
"assert",
"state",
".",
"attributes",
"[",
"\"direction\"",
"]",
"==",
"\"Outbound, Outbound 2\"",
"assert",
"state",
".",
"attributes",
"[",
"\"upcoming\"",
"]",
"==",
"\"0, 1, 2, 3\""
] | [
189,
0
] | [
225,
55
] | python | en | ['en', 'en', 'en'] | True |
test_custom_name | (
hass, mock_nextbus, mock_nextbus_lists, mock_nextbus_predictions
) | Verify that a custom name can be set via config. | Verify that a custom name can be set via config. | async def test_custom_name(
hass, mock_nextbus, mock_nextbus_lists, mock_nextbus_predictions
):
"""Verify that a custom name can be set via config."""
config = deepcopy(CONFIG_BASIC)
config["sensor"]["name"] = "Custom Name"
await assert_setup_sensor(hass, config)
state = hass.states.get("sensor.custom_name")
assert state is not None | [
"async",
"def",
"test_custom_name",
"(",
"hass",
",",
"mock_nextbus",
",",
"mock_nextbus_lists",
",",
"mock_nextbus_predictions",
")",
":",
"config",
"=",
"deepcopy",
"(",
"CONFIG_BASIC",
")",
"config",
"[",
"\"sensor\"",
"]",
"[",
"\"name\"",
"]",
"=",
"\"Custom Name\"",
"await",
"assert_setup_sensor",
"(",
"hass",
",",
"config",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.custom_name\"",
")",
"assert",
"state",
"is",
"not",
"None"
] | [
228,
0
] | [
237,
28
] | python | en | ['en', 'pt', 'en'] | True |
test_no_predictions | (
hass, mock_nextbus, mock_nextbus_predictions, mock_nextbus_lists
) | Verify there are no exceptions when no predictions are returned. | Verify there are no exceptions when no predictions are returned. | async def test_no_predictions(
hass, mock_nextbus, mock_nextbus_predictions, mock_nextbus_lists
):
"""Verify there are no exceptions when no predictions are returned."""
mock_nextbus_predictions.return_value = {}
await assert_setup_sensor(hass, CONFIG_BASIC)
state = hass.states.get(SENSOR_ID_SHORT)
assert state is not None
assert state.state == "unknown" | [
"async",
"def",
"test_no_predictions",
"(",
"hass",
",",
"mock_nextbus",
",",
"mock_nextbus_predictions",
",",
"mock_nextbus_lists",
")",
":",
"mock_nextbus_predictions",
".",
"return_value",
"=",
"{",
"}",
"await",
"assert_setup_sensor",
"(",
"hass",
",",
"CONFIG_BASIC",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"SENSOR_ID_SHORT",
")",
"assert",
"state",
"is",
"not",
"None",
"assert",
"state",
".",
"state",
"==",
"\"unknown\""
] | [
240,
0
] | [
250,
35
] | python | en | ['en', 'en', 'en'] | True |
test_verify_no_upcoming | (
hass, mock_nextbus, mock_nextbus_lists, mock_nextbus_predictions
) | Verify attributes are set despite no upcoming times. | Verify attributes are set despite no upcoming times. | async def test_verify_no_upcoming(
hass, mock_nextbus, mock_nextbus_lists, mock_nextbus_predictions
):
"""Verify attributes are set despite no upcoming times."""
mock_nextbus_predictions.return_value = {
"predictions": {
"agencyTitle": VALID_AGENCY_TITLE,
"routeTitle": VALID_ROUTE_TITLE,
"stopTitle": VALID_STOP_TITLE,
"direction": {"title": "Outbound", "prediction": []},
}
}
await assert_setup_sensor(hass, CONFIG_BASIC)
state = hass.states.get(SENSOR_ID_SHORT)
assert state is not None
assert state.state == "unknown"
assert state.attributes["upcoming"] == "No upcoming predictions" | [
"async",
"def",
"test_verify_no_upcoming",
"(",
"hass",
",",
"mock_nextbus",
",",
"mock_nextbus_lists",
",",
"mock_nextbus_predictions",
")",
":",
"mock_nextbus_predictions",
".",
"return_value",
"=",
"{",
"\"predictions\"",
":",
"{",
"\"agencyTitle\"",
":",
"VALID_AGENCY_TITLE",
",",
"\"routeTitle\"",
":",
"VALID_ROUTE_TITLE",
",",
"\"stopTitle\"",
":",
"VALID_STOP_TITLE",
",",
"\"direction\"",
":",
"{",
"\"title\"",
":",
"\"Outbound\"",
",",
"\"prediction\"",
":",
"[",
"]",
"}",
",",
"}",
"}",
"await",
"assert_setup_sensor",
"(",
"hass",
",",
"CONFIG_BASIC",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"SENSOR_ID_SHORT",
")",
"assert",
"state",
"is",
"not",
"None",
"assert",
"state",
".",
"state",
"==",
"\"unknown\"",
"assert",
"state",
".",
"attributes",
"[",
"\"upcoming\"",
"]",
"==",
"\"No upcoming predictions\""
] | [
253,
0
] | [
271,
68
] | python | en | ['en', 'pt', 'en'] | True |
setup_comp | (hass) | Set up demo component. | Set up demo component. | async def setup_comp(hass):
"""Set up demo component."""
assert await async_setup_component(
hass, LIGHT_DOMAIN, {LIGHT_DOMAIN: {"platform": DOMAIN}}
)
await hass.async_block_till_done() | [
"async",
"def",
"setup_comp",
"(",
"hass",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"LIGHT_DOMAIN",
",",
"{",
"LIGHT_DOMAIN",
":",
"{",
"\"platform\"",
":",
"DOMAIN",
"}",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")"
] | [
26,
0
] | [
31,
38
] | python | en | ['en', 'da', 'en'] | True |
test_state_attributes | (hass) | Test light state attributes. | Test light state attributes. | async def test_state_attributes(hass):
"""Test light state attributes."""
await hass.services.async_call(
LIGHT_DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: ENTITY_LIGHT, ATTR_XY_COLOR: (0.4, 0.4), ATTR_BRIGHTNESS: 25},
blocking=True,
)
state = hass.states.get(ENTITY_LIGHT)
assert state.state == STATE_ON
assert state.attributes.get(ATTR_XY_COLOR) == (0.4, 0.4)
assert state.attributes.get(ATTR_BRIGHTNESS) == 25
assert state.attributes.get(ATTR_RGB_COLOR) == (255, 234, 164)
assert state.attributes.get(ATTR_EFFECT) == "rainbow"
await hass.services.async_call(
LIGHT_DOMAIN,
SERVICE_TURN_ON,
{
ATTR_ENTITY_ID: ENTITY_LIGHT,
ATTR_RGB_COLOR: (251, 253, 255),
ATTR_WHITE_VALUE: 254,
},
blocking=True,
)
state = hass.states.get(ENTITY_LIGHT)
assert state.attributes.get(ATTR_WHITE_VALUE) == 254
assert state.attributes.get(ATTR_RGB_COLOR) == (250, 252, 255)
assert state.attributes.get(ATTR_XY_COLOR) == (0.319, 0.326)
await hass.services.async_call(
LIGHT_DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: ENTITY_LIGHT, ATTR_EFFECT: "none", ATTR_COLOR_TEMP: 400},
blocking=True,
)
state = hass.states.get(ENTITY_LIGHT)
assert state.attributes.get(ATTR_COLOR_TEMP) == 400
assert state.attributes.get(ATTR_MIN_MIREDS) == 153
assert state.attributes.get(ATTR_MAX_MIREDS) == 500
assert state.attributes.get(ATTR_EFFECT) == "none"
await hass.services.async_call(
LIGHT_DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: ENTITY_LIGHT, ATTR_BRIGHTNESS_PCT: 50, ATTR_KELVIN: 3000},
blocking=True,
)
state = hass.states.get(ENTITY_LIGHT)
assert state.attributes.get(ATTR_COLOR_TEMP) == 333
assert state.attributes.get(ATTR_BRIGHTNESS) == 128 | [
"async",
"def",
"test_state_attributes",
"(",
"hass",
")",
":",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_LIGHT",
",",
"ATTR_XY_COLOR",
":",
"(",
"0.4",
",",
"0.4",
")",
",",
"ATTR_BRIGHTNESS",
":",
"25",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_LIGHT",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_ON",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_XY_COLOR",
")",
"==",
"(",
"0.4",
",",
"0.4",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_BRIGHTNESS",
")",
"==",
"25",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_RGB_COLOR",
")",
"==",
"(",
"255",
",",
"234",
",",
"164",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_EFFECT",
")",
"==",
"\"rainbow\"",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_LIGHT",
",",
"ATTR_RGB_COLOR",
":",
"(",
"251",
",",
"253",
",",
"255",
")",
",",
"ATTR_WHITE_VALUE",
":",
"254",
",",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_LIGHT",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_WHITE_VALUE",
")",
"==",
"254",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_RGB_COLOR",
")",
"==",
"(",
"250",
",",
"252",
",",
"255",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_XY_COLOR",
")",
"==",
"(",
"0.319",
",",
"0.326",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_LIGHT",
",",
"ATTR_EFFECT",
":",
"\"none\"",
",",
"ATTR_COLOR_TEMP",
":",
"400",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_LIGHT",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_COLOR_TEMP",
")",
"==",
"400",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MIN_MIREDS",
")",
"==",
"153",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MAX_MIREDS",
")",
"==",
"500",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_EFFECT",
")",
"==",
"\"none\"",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_LIGHT",
",",
"ATTR_BRIGHTNESS_PCT",
":",
"50",
",",
"ATTR_KELVIN",
":",
"3000",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_LIGHT",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_COLOR_TEMP",
")",
"==",
"333",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_BRIGHTNESS",
")",
"==",
"128"
] | [
34,
0
] | [
88,
55
] | python | en | ['en', 'en', 'en'] | True |
test_turn_off | (hass) | Test light turn off method. | Test light turn off method. | async def test_turn_off(hass):
"""Test light turn off method."""
await hass.services.async_call(
LIGHT_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: ENTITY_LIGHT}, blocking=True
)
state = hass.states.get(ENTITY_LIGHT)
assert state.state == STATE_ON
await hass.services.async_call(
LIGHT_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: ENTITY_LIGHT}, blocking=True
)
state = hass.states.get(ENTITY_LIGHT)
assert state.state == STATE_OFF | [
"async",
"def",
"test_turn_off",
"(",
"hass",
")",
":",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_LIGHT",
"}",
",",
"blocking",
"=",
"True",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_LIGHT",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_ON",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_OFF",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_LIGHT",
"}",
",",
"blocking",
"=",
"True",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_LIGHT",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_OFF"
] | [
91,
0
] | [
105,
35
] | python | en | ['en', 'et', 'en'] | True |
test_turn_off_without_entity_id | (hass) | Test light turn off all lights. | Test light turn off all lights. | async def test_turn_off_without_entity_id(hass):
"""Test light turn off all lights."""
await hass.services.async_call(
LIGHT_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: "all"}, blocking=True
)
state = hass.states.get(ENTITY_LIGHT)
assert state.state == STATE_ON
await hass.services.async_call(
LIGHT_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: "all"}, blocking=True
)
state = hass.states.get(ENTITY_LIGHT)
assert state.state == STATE_OFF | [
"async",
"def",
"test_turn_off_without_entity_id",
"(",
"hass",
")",
":",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"all\"",
"}",
",",
"blocking",
"=",
"True",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_LIGHT",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_ON",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_OFF",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"all\"",
"}",
",",
"blocking",
"=",
"True",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_LIGHT",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_OFF"
] | [
108,
0
] | [
122,
35
] | python | en | ['en', 'et', 'en'] | True |
KonnectedFlowHandler.__init__ | (self) | Initialize the Konnected flow. | Initialize the Konnected flow. | def __init__(self):
"""Initialize the Konnected flow."""
self.data = {}
self.options = OPTIONS_SCHEMA({CONF_IO: {}}) | [
"def",
"__init__",
"(",
"self",
")",
":",
"self",
".",
"data",
"=",
"{",
"}",
"self",
".",
"options",
"=",
"OPTIONS_SCHEMA",
"(",
"{",
"CONF_IO",
":",
"{",
"}",
"}",
")"
] | [
173,
4
] | [
176,
52
] | python | en | ['en', 'en', 'en'] | True |
KonnectedFlowHandler.async_gen_config | (self, host, port) | Populate self.data based on panel status.
This will raise CannotConnect if an error occurs
| Populate self.data based on panel status. | async def async_gen_config(self, host, port):
"""Populate self.data based on panel status.
This will raise CannotConnect if an error occurs
"""
self.data[CONF_HOST] = host
self.data[CONF_PORT] = port
try:
status = await get_status(self.hass, host, port)
self.data[CONF_ID] = status.get("chipId", status["mac"].replace(":", ""))
except (CannotConnect, KeyError) as err:
raise CannotConnect from err
else:
self.data[CONF_MODEL] = status.get("model", KONN_MODEL)
self.data[CONF_ACCESS_TOKEN] = "".join(
random.choices(f"{string.ascii_uppercase}{string.digits}", k=20)
) | [
"async",
"def",
"async_gen_config",
"(",
"self",
",",
"host",
",",
"port",
")",
":",
"self",
".",
"data",
"[",
"CONF_HOST",
"]",
"=",
"host",
"self",
".",
"data",
"[",
"CONF_PORT",
"]",
"=",
"port",
"try",
":",
"status",
"=",
"await",
"get_status",
"(",
"self",
".",
"hass",
",",
"host",
",",
"port",
")",
"self",
".",
"data",
"[",
"CONF_ID",
"]",
"=",
"status",
".",
"get",
"(",
"\"chipId\"",
",",
"status",
"[",
"\"mac\"",
"]",
".",
"replace",
"(",
"\":\"",
",",
"\"\"",
")",
")",
"except",
"(",
"CannotConnect",
",",
"KeyError",
")",
"as",
"err",
":",
"raise",
"CannotConnect",
"from",
"err",
"else",
":",
"self",
".",
"data",
"[",
"CONF_MODEL",
"]",
"=",
"status",
".",
"get",
"(",
"\"model\"",
",",
"KONN_MODEL",
")",
"self",
".",
"data",
"[",
"CONF_ACCESS_TOKEN",
"]",
"=",
"\"\"",
".",
"join",
"(",
"random",
".",
"choices",
"(",
"f\"{string.ascii_uppercase}{string.digits}\"",
",",
"k",
"=",
"20",
")",
")"
] | [
178,
4
] | [
194,
13
] | python | en | ['en', 'et', 'en'] | True |
KonnectedFlowHandler.async_step_import | (self, device_config) | Import a configuration.yaml config.
This flow is triggered by `async_setup` for configured panels.
| Import a configuration.yaml config. | async def async_step_import(self, device_config):
"""Import a configuration.yaml config.
This flow is triggered by `async_setup` for configured panels.
"""
_LOGGER.debug(device_config)
# save the data and confirm connection via user step
await self.async_set_unique_id(device_config["id"])
self.options = device_config[CONF_DEFAULT_OPTIONS]
# config schema ensures we have port if we have host
if device_config.get(CONF_HOST):
# automatically connect if we have host info
return await self.async_step_user(
user_input={
CONF_HOST: device_config[CONF_HOST],
CONF_PORT: device_config[CONF_PORT],
}
)
# if we have no host info wait for it or abort if previously configured
self._abort_if_unique_id_configured()
return await self.async_step_import_confirm() | [
"async",
"def",
"async_step_import",
"(",
"self",
",",
"device_config",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"device_config",
")",
"# save the data and confirm connection via user step",
"await",
"self",
".",
"async_set_unique_id",
"(",
"device_config",
"[",
"\"id\"",
"]",
")",
"self",
".",
"options",
"=",
"device_config",
"[",
"CONF_DEFAULT_OPTIONS",
"]",
"# config schema ensures we have port if we have host",
"if",
"device_config",
".",
"get",
"(",
"CONF_HOST",
")",
":",
"# automatically connect if we have host info",
"return",
"await",
"self",
".",
"async_step_user",
"(",
"user_input",
"=",
"{",
"CONF_HOST",
":",
"device_config",
"[",
"CONF_HOST",
"]",
",",
"CONF_PORT",
":",
"device_config",
"[",
"CONF_PORT",
"]",
",",
"}",
")",
"# if we have no host info wait for it or abort if previously configured",
"self",
".",
"_abort_if_unique_id_configured",
"(",
")",
"return",
"await",
"self",
".",
"async_step_import_confirm",
"(",
")"
] | [
196,
4
] | [
219,
53
] | python | en | ['en', 'en', 'en'] | True |
KonnectedFlowHandler.async_step_import_confirm | (self, user_input=None) | Confirm the user wants to import the config entry. | Confirm the user wants to import the config entry. | async def async_step_import_confirm(self, user_input=None):
"""Confirm the user wants to import the config entry."""
if user_input is None:
return self.async_show_form(
step_id="import_confirm",
description_placeholders={"id": self.unique_id},
)
# if we have ssdp discovered applicable host info use it
if KonnectedFlowHandler.discovered_hosts.get(self.unique_id):
return await self.async_step_user(
user_input={
CONF_HOST: KonnectedFlowHandler.discovered_hosts[self.unique_id][
CONF_HOST
],
CONF_PORT: KonnectedFlowHandler.discovered_hosts[self.unique_id][
CONF_PORT
],
}
)
return await self.async_step_user() | [
"async",
"def",
"async_step_import_confirm",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"if",
"user_input",
"is",
"None",
":",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"import_confirm\"",
",",
"description_placeholders",
"=",
"{",
"\"id\"",
":",
"self",
".",
"unique_id",
"}",
",",
")",
"# if we have ssdp discovered applicable host info use it",
"if",
"KonnectedFlowHandler",
".",
"discovered_hosts",
".",
"get",
"(",
"self",
".",
"unique_id",
")",
":",
"return",
"await",
"self",
".",
"async_step_user",
"(",
"user_input",
"=",
"{",
"CONF_HOST",
":",
"KonnectedFlowHandler",
".",
"discovered_hosts",
"[",
"self",
".",
"unique_id",
"]",
"[",
"CONF_HOST",
"]",
",",
"CONF_PORT",
":",
"KonnectedFlowHandler",
".",
"discovered_hosts",
"[",
"self",
".",
"unique_id",
"]",
"[",
"CONF_PORT",
"]",
",",
"}",
")",
"return",
"await",
"self",
".",
"async_step_user",
"(",
")"
] | [
221,
4
] | [
241,
43
] | python | en | ['en', 'en', 'en'] | True |
KonnectedFlowHandler.async_step_ssdp | (self, discovery_info) | Handle a discovered konnected panel.
This flow is triggered by the SSDP component. It will check if the
device is already configured and attempt to finish the config if not.
| Handle a discovered konnected panel. | async def async_step_ssdp(self, discovery_info):
"""Handle a discovered konnected panel.
This flow is triggered by the SSDP component. It will check if the
device is already configured and attempt to finish the config if not.
"""
_LOGGER.debug(discovery_info)
try:
if discovery_info[ATTR_UPNP_MANUFACTURER] != KONN_MANUFACTURER:
return self.async_abort(reason="not_konn_panel")
if not any(
name in discovery_info[ATTR_UPNP_MODEL_NAME]
for name in KONN_PANEL_MODEL_NAMES
):
_LOGGER.warning(
"Discovered unrecognized Konnected device %s",
discovery_info.get(ATTR_UPNP_MODEL_NAME, "Unknown"),
)
return self.async_abort(reason="not_konn_panel")
# If MAC is missing it is a bug in the device fw but we'll guard
# against it since the field is so vital
except KeyError:
_LOGGER.error("Malformed Konnected SSDP info")
else:
# extract host/port from ssdp_location
netloc = urlparse(discovery_info["ssdp_location"]).netloc.split(":")
return await self.async_step_user(
user_input={CONF_HOST: netloc[0], CONF_PORT: int(netloc[1])}
)
return self.async_abort(reason="unknown") | [
"async",
"def",
"async_step_ssdp",
"(",
"self",
",",
"discovery_info",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"discovery_info",
")",
"try",
":",
"if",
"discovery_info",
"[",
"ATTR_UPNP_MANUFACTURER",
"]",
"!=",
"KONN_MANUFACTURER",
":",
"return",
"self",
".",
"async_abort",
"(",
"reason",
"=",
"\"not_konn_panel\"",
")",
"if",
"not",
"any",
"(",
"name",
"in",
"discovery_info",
"[",
"ATTR_UPNP_MODEL_NAME",
"]",
"for",
"name",
"in",
"KONN_PANEL_MODEL_NAMES",
")",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Discovered unrecognized Konnected device %s\"",
",",
"discovery_info",
".",
"get",
"(",
"ATTR_UPNP_MODEL_NAME",
",",
"\"Unknown\"",
")",
",",
")",
"return",
"self",
".",
"async_abort",
"(",
"reason",
"=",
"\"not_konn_panel\"",
")",
"# If MAC is missing it is a bug in the device fw but we'll guard",
"# against it since the field is so vital",
"except",
"KeyError",
":",
"_LOGGER",
".",
"error",
"(",
"\"Malformed Konnected SSDP info\"",
")",
"else",
":",
"# extract host/port from ssdp_location",
"netloc",
"=",
"urlparse",
"(",
"discovery_info",
"[",
"\"ssdp_location\"",
"]",
")",
".",
"netloc",
".",
"split",
"(",
"\":\"",
")",
"return",
"await",
"self",
".",
"async_step_user",
"(",
"user_input",
"=",
"{",
"CONF_HOST",
":",
"netloc",
"[",
"0",
"]",
",",
"CONF_PORT",
":",
"int",
"(",
"netloc",
"[",
"1",
"]",
")",
"}",
")",
"return",
"self",
".",
"async_abort",
"(",
"reason",
"=",
"\"unknown\"",
")"
] | [
243,
4
] | [
276,
49
] | python | en | ['en', 'en', 'en'] | True |
KonnectedFlowHandler.async_step_user | (self, user_input=None) | Connect to panel and get config. | Connect to panel and get config. | async def async_step_user(self, user_input=None):
"""Connect to panel and get config."""
errors = {}
if user_input:
# build config info and wait for user confirmation
self.data[CONF_HOST] = user_input[CONF_HOST]
self.data[CONF_PORT] = user_input[CONF_PORT]
# brief delay to allow processing of recent status req
await asyncio.sleep(0.1)
try:
status = await get_status(
self.hass, self.data[CONF_HOST], self.data[CONF_PORT]
)
except CannotConnect:
errors["base"] = "cannot_connect"
else:
self.data[CONF_ID] = status.get(
"chipId", status["mac"].replace(":", "")
)
self.data[CONF_MODEL] = status.get("model", KONN_MODEL)
# save off our discovered host info
KonnectedFlowHandler.discovered_hosts[self.data[CONF_ID]] = {
CONF_HOST: self.data[CONF_HOST],
CONF_PORT: self.data[CONF_PORT],
}
return await self.async_step_confirm()
return self.async_show_form(
step_id="user",
description_placeholders={
"host": self.data.get(CONF_HOST, "Unknown"),
"port": self.data.get(CONF_PORT, "Unknown"),
},
data_schema=vol.Schema(
{
vol.Required(CONF_HOST, default=self.data.get(CONF_HOST)): str,
vol.Required(CONF_PORT, default=self.data.get(CONF_PORT)): int,
}
),
errors=errors,
) | [
"async",
"def",
"async_step_user",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"errors",
"=",
"{",
"}",
"if",
"user_input",
":",
"# build config info and wait for user confirmation",
"self",
".",
"data",
"[",
"CONF_HOST",
"]",
"=",
"user_input",
"[",
"CONF_HOST",
"]",
"self",
".",
"data",
"[",
"CONF_PORT",
"]",
"=",
"user_input",
"[",
"CONF_PORT",
"]",
"# brief delay to allow processing of recent status req",
"await",
"asyncio",
".",
"sleep",
"(",
"0.1",
")",
"try",
":",
"status",
"=",
"await",
"get_status",
"(",
"self",
".",
"hass",
",",
"self",
".",
"data",
"[",
"CONF_HOST",
"]",
",",
"self",
".",
"data",
"[",
"CONF_PORT",
"]",
")",
"except",
"CannotConnect",
":",
"errors",
"[",
"\"base\"",
"]",
"=",
"\"cannot_connect\"",
"else",
":",
"self",
".",
"data",
"[",
"CONF_ID",
"]",
"=",
"status",
".",
"get",
"(",
"\"chipId\"",
",",
"status",
"[",
"\"mac\"",
"]",
".",
"replace",
"(",
"\":\"",
",",
"\"\"",
")",
")",
"self",
".",
"data",
"[",
"CONF_MODEL",
"]",
"=",
"status",
".",
"get",
"(",
"\"model\"",
",",
"KONN_MODEL",
")",
"# save off our discovered host info",
"KonnectedFlowHandler",
".",
"discovered_hosts",
"[",
"self",
".",
"data",
"[",
"CONF_ID",
"]",
"]",
"=",
"{",
"CONF_HOST",
":",
"self",
".",
"data",
"[",
"CONF_HOST",
"]",
",",
"CONF_PORT",
":",
"self",
".",
"data",
"[",
"CONF_PORT",
"]",
",",
"}",
"return",
"await",
"self",
".",
"async_step_confirm",
"(",
")",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"user\"",
",",
"description_placeholders",
"=",
"{",
"\"host\"",
":",
"self",
".",
"data",
".",
"get",
"(",
"CONF_HOST",
",",
"\"Unknown\"",
")",
",",
"\"port\"",
":",
"self",
".",
"data",
".",
"get",
"(",
"CONF_PORT",
",",
"\"Unknown\"",
")",
",",
"}",
",",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"{",
"vol",
".",
"Required",
"(",
"CONF_HOST",
",",
"default",
"=",
"self",
".",
"data",
".",
"get",
"(",
"CONF_HOST",
")",
")",
":",
"str",
",",
"vol",
".",
"Required",
"(",
"CONF_PORT",
",",
"default",
"=",
"self",
".",
"data",
".",
"get",
"(",
"CONF_PORT",
")",
")",
":",
"int",
",",
"}",
")",
",",
"errors",
"=",
"errors",
",",
")"
] | [
278,
4
] | [
320,
9
] | python | en | ['en', 'en', 'en'] | True |
KonnectedFlowHandler.async_step_confirm | (self, user_input=None) | Attempt to link with the Konnected panel.
Given a configured host, will ask the user to confirm and finalize
the connection.
| Attempt to link with the Konnected panel. | async def async_step_confirm(self, user_input=None):
"""Attempt to link with the Konnected panel.
Given a configured host, will ask the user to confirm and finalize
the connection.
"""
if user_input is None:
# abort and update an existing config entry if host info changes
await self.async_set_unique_id(self.data[CONF_ID])
self._abort_if_unique_id_configured(
updates=self.data, reload_on_update=False
)
return self.async_show_form(
step_id="confirm",
description_placeholders={
"model": KONN_PANEL_MODEL_NAMES[self.data[CONF_MODEL]],
"id": self.unique_id,
"host": self.data[CONF_HOST],
"port": self.data[CONF_PORT],
},
)
# Create access token, attach default options and create entry
self.data[CONF_DEFAULT_OPTIONS] = self.options
self.data[CONF_ACCESS_TOKEN] = self.hass.data.get(DOMAIN, {}).get(
CONF_ACCESS_TOKEN
) or "".join(random.choices(f"{string.ascii_uppercase}{string.digits}", k=20))
return self.async_create_entry(
title=KONN_PANEL_MODEL_NAMES[self.data[CONF_MODEL]],
data=self.data,
) | [
"async",
"def",
"async_step_confirm",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"if",
"user_input",
"is",
"None",
":",
"# abort and update an existing config entry if host info changes",
"await",
"self",
".",
"async_set_unique_id",
"(",
"self",
".",
"data",
"[",
"CONF_ID",
"]",
")",
"self",
".",
"_abort_if_unique_id_configured",
"(",
"updates",
"=",
"self",
".",
"data",
",",
"reload_on_update",
"=",
"False",
")",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"confirm\"",
",",
"description_placeholders",
"=",
"{",
"\"model\"",
":",
"KONN_PANEL_MODEL_NAMES",
"[",
"self",
".",
"data",
"[",
"CONF_MODEL",
"]",
"]",
",",
"\"id\"",
":",
"self",
".",
"unique_id",
",",
"\"host\"",
":",
"self",
".",
"data",
"[",
"CONF_HOST",
"]",
",",
"\"port\"",
":",
"self",
".",
"data",
"[",
"CONF_PORT",
"]",
",",
"}",
",",
")",
"# Create access token, attach default options and create entry",
"self",
".",
"data",
"[",
"CONF_DEFAULT_OPTIONS",
"]",
"=",
"self",
".",
"options",
"self",
".",
"data",
"[",
"CONF_ACCESS_TOKEN",
"]",
"=",
"self",
".",
"hass",
".",
"data",
".",
"get",
"(",
"DOMAIN",
",",
"{",
"}",
")",
".",
"get",
"(",
"CONF_ACCESS_TOKEN",
")",
"or",
"\"\"",
".",
"join",
"(",
"random",
".",
"choices",
"(",
"f\"{string.ascii_uppercase}{string.digits}\"",
",",
"k",
"=",
"20",
")",
")",
"return",
"self",
".",
"async_create_entry",
"(",
"title",
"=",
"KONN_PANEL_MODEL_NAMES",
"[",
"self",
".",
"data",
"[",
"CONF_MODEL",
"]",
"]",
",",
"data",
"=",
"self",
".",
"data",
",",
")"
] | [
322,
4
] | [
353,
9
] | python | en | ['en', 'en', 'en'] | True |
KonnectedFlowHandler.async_get_options_flow | (config_entry) | Return the Options Flow. | Return the Options Flow. | def async_get_options_flow(config_entry):
"""Return the Options Flow."""
return OptionsFlowHandler(config_entry) | [
"def",
"async_get_options_flow",
"(",
"config_entry",
")",
":",
"return",
"OptionsFlowHandler",
"(",
"config_entry",
")"
] | [
357,
4
] | [
359,
47
] | python | en | ['en', 'en', 'en'] | True |
OptionsFlowHandler.__init__ | (self, config_entry: config_entries.ConfigEntry) | Initialize options flow. | Initialize options flow. | def __init__(self, config_entry: config_entries.ConfigEntry):
"""Initialize options flow."""
self.entry = config_entry
self.model = self.entry.data[CONF_MODEL]
self.current_opt = self.entry.options or self.entry.data[CONF_DEFAULT_OPTIONS]
# as config proceeds we'll build up new options and then replace what's in the config entry
self.new_opt = {CONF_IO: {}}
self.active_cfg = None
self.io_cfg = {}
self.current_states = []
self.current_state = 1 | [
"def",
"__init__",
"(",
"self",
",",
"config_entry",
":",
"config_entries",
".",
"ConfigEntry",
")",
":",
"self",
".",
"entry",
"=",
"config_entry",
"self",
".",
"model",
"=",
"self",
".",
"entry",
".",
"data",
"[",
"CONF_MODEL",
"]",
"self",
".",
"current_opt",
"=",
"self",
".",
"entry",
".",
"options",
"or",
"self",
".",
"entry",
".",
"data",
"[",
"CONF_DEFAULT_OPTIONS",
"]",
"# as config proceeds we'll build up new options and then replace what's in the config entry",
"self",
".",
"new_opt",
"=",
"{",
"CONF_IO",
":",
"{",
"}",
"}",
"self",
".",
"active_cfg",
"=",
"None",
"self",
".",
"io_cfg",
"=",
"{",
"}",
"self",
".",
"current_states",
"=",
"[",
"]",
"self",
".",
"current_state",
"=",
"1"
] | [
365,
4
] | [
376,
30
] | python | en | ['en', 'en', 'en'] | True |
OptionsFlowHandler.get_current_cfg | (self, io_type, zone) | Get the current zone config. | Get the current zone config. | def get_current_cfg(self, io_type, zone):
"""Get the current zone config."""
return next(
(
cfg
for cfg in self.current_opt.get(io_type, [])
if cfg[CONF_ZONE] == zone
),
{},
) | [
"def",
"get_current_cfg",
"(",
"self",
",",
"io_type",
",",
"zone",
")",
":",
"return",
"next",
"(",
"(",
"cfg",
"for",
"cfg",
"in",
"self",
".",
"current_opt",
".",
"get",
"(",
"io_type",
",",
"[",
"]",
")",
"if",
"cfg",
"[",
"CONF_ZONE",
"]",
"==",
"zone",
")",
",",
"{",
"}",
",",
")"
] | [
379,
4
] | [
388,
9
] | python | en | ['en', 'en', 'en'] | True |
OptionsFlowHandler.async_step_init | (self, user_input=None) | Handle options flow. | Handle options flow. | async def async_step_init(self, user_input=None):
"""Handle options flow."""
return await self.async_step_options_io() | [
"async",
"def",
"async_step_init",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"return",
"await",
"self",
".",
"async_step_options_io",
"(",
")"
] | [
390,
4
] | [
392,
49
] | python | en | ['en', 'nl', 'en'] | True |
OptionsFlowHandler.async_step_options_io | (self, user_input=None) | Configure legacy panel IO or first half of pro IO. | Configure legacy panel IO or first half of pro IO. | async def async_step_options_io(self, user_input=None):
"""Configure legacy panel IO or first half of pro IO."""
errors = {}
current_io = self.current_opt.get(CONF_IO, {})
if user_input is not None:
# strip out disabled io and save for options cfg
for key, value in user_input.items():
if value != CONF_IO_DIS:
self.new_opt[CONF_IO][key] = value
return await self.async_step_options_io_ext()
if self.model == KONN_MODEL:
return self.async_show_form(
step_id="options_io",
data_schema=vol.Schema(
{
vol.Required(
"1", default=current_io.get("1", CONF_IO_DIS)
): OPTIONS_IO_ANY,
vol.Required(
"2", default=current_io.get("2", CONF_IO_DIS)
): OPTIONS_IO_ANY,
vol.Required(
"3", default=current_io.get("3", CONF_IO_DIS)
): OPTIONS_IO_ANY,
vol.Required(
"4", default=current_io.get("4", CONF_IO_DIS)
): OPTIONS_IO_ANY,
vol.Required(
"5", default=current_io.get("5", CONF_IO_DIS)
): OPTIONS_IO_ANY,
vol.Required(
"6", default=current_io.get("6", CONF_IO_DIS)
): OPTIONS_IO_ANY,
vol.Required(
"out", default=current_io.get("out", CONF_IO_DIS)
): OPTIONS_IO_OUTPUT_ONLY,
}
),
description_placeholders={
"model": KONN_PANEL_MODEL_NAMES[self.model],
"host": self.entry.data[CONF_HOST],
},
errors=errors,
)
# configure the first half of the pro board io
if self.model == KONN_MODEL_PRO:
return self.async_show_form(
step_id="options_io",
data_schema=vol.Schema(
{
vol.Required(
"1", default=current_io.get("1", CONF_IO_DIS)
): OPTIONS_IO_ANY,
vol.Required(
"2", default=current_io.get("2", CONF_IO_DIS)
): OPTIONS_IO_ANY,
vol.Required(
"3", default=current_io.get("3", CONF_IO_DIS)
): OPTIONS_IO_ANY,
vol.Required(
"4", default=current_io.get("4", CONF_IO_DIS)
): OPTIONS_IO_ANY,
vol.Required(
"5", default=current_io.get("5", CONF_IO_DIS)
): OPTIONS_IO_ANY,
vol.Required(
"6", default=current_io.get("6", CONF_IO_DIS)
): OPTIONS_IO_ANY,
vol.Required(
"7", default=current_io.get("7", CONF_IO_DIS)
): OPTIONS_IO_ANY,
}
),
description_placeholders={
"model": KONN_PANEL_MODEL_NAMES[self.model],
"host": self.entry.data[CONF_HOST],
},
errors=errors,
)
return self.async_abort(reason="not_konn_panel") | [
"async",
"def",
"async_step_options_io",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"errors",
"=",
"{",
"}",
"current_io",
"=",
"self",
".",
"current_opt",
".",
"get",
"(",
"CONF_IO",
",",
"{",
"}",
")",
"if",
"user_input",
"is",
"not",
"None",
":",
"# strip out disabled io and save for options cfg",
"for",
"key",
",",
"value",
"in",
"user_input",
".",
"items",
"(",
")",
":",
"if",
"value",
"!=",
"CONF_IO_DIS",
":",
"self",
".",
"new_opt",
"[",
"CONF_IO",
"]",
"[",
"key",
"]",
"=",
"value",
"return",
"await",
"self",
".",
"async_step_options_io_ext",
"(",
")",
"if",
"self",
".",
"model",
"==",
"KONN_MODEL",
":",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"options_io\"",
",",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"{",
"vol",
".",
"Required",
"(",
"\"1\"",
",",
"default",
"=",
"current_io",
".",
"get",
"(",
"\"1\"",
",",
"CONF_IO_DIS",
")",
")",
":",
"OPTIONS_IO_ANY",
",",
"vol",
".",
"Required",
"(",
"\"2\"",
",",
"default",
"=",
"current_io",
".",
"get",
"(",
"\"2\"",
",",
"CONF_IO_DIS",
")",
")",
":",
"OPTIONS_IO_ANY",
",",
"vol",
".",
"Required",
"(",
"\"3\"",
",",
"default",
"=",
"current_io",
".",
"get",
"(",
"\"3\"",
",",
"CONF_IO_DIS",
")",
")",
":",
"OPTIONS_IO_ANY",
",",
"vol",
".",
"Required",
"(",
"\"4\"",
",",
"default",
"=",
"current_io",
".",
"get",
"(",
"\"4\"",
",",
"CONF_IO_DIS",
")",
")",
":",
"OPTIONS_IO_ANY",
",",
"vol",
".",
"Required",
"(",
"\"5\"",
",",
"default",
"=",
"current_io",
".",
"get",
"(",
"\"5\"",
",",
"CONF_IO_DIS",
")",
")",
":",
"OPTIONS_IO_ANY",
",",
"vol",
".",
"Required",
"(",
"\"6\"",
",",
"default",
"=",
"current_io",
".",
"get",
"(",
"\"6\"",
",",
"CONF_IO_DIS",
")",
")",
":",
"OPTIONS_IO_ANY",
",",
"vol",
".",
"Required",
"(",
"\"out\"",
",",
"default",
"=",
"current_io",
".",
"get",
"(",
"\"out\"",
",",
"CONF_IO_DIS",
")",
")",
":",
"OPTIONS_IO_OUTPUT_ONLY",
",",
"}",
")",
",",
"description_placeholders",
"=",
"{",
"\"model\"",
":",
"KONN_PANEL_MODEL_NAMES",
"[",
"self",
".",
"model",
"]",
",",
"\"host\"",
":",
"self",
".",
"entry",
".",
"data",
"[",
"CONF_HOST",
"]",
",",
"}",
",",
"errors",
"=",
"errors",
",",
")",
"# configure the first half of the pro board io",
"if",
"self",
".",
"model",
"==",
"KONN_MODEL_PRO",
":",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"options_io\"",
",",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"{",
"vol",
".",
"Required",
"(",
"\"1\"",
",",
"default",
"=",
"current_io",
".",
"get",
"(",
"\"1\"",
",",
"CONF_IO_DIS",
")",
")",
":",
"OPTIONS_IO_ANY",
",",
"vol",
".",
"Required",
"(",
"\"2\"",
",",
"default",
"=",
"current_io",
".",
"get",
"(",
"\"2\"",
",",
"CONF_IO_DIS",
")",
")",
":",
"OPTIONS_IO_ANY",
",",
"vol",
".",
"Required",
"(",
"\"3\"",
",",
"default",
"=",
"current_io",
".",
"get",
"(",
"\"3\"",
",",
"CONF_IO_DIS",
")",
")",
":",
"OPTIONS_IO_ANY",
",",
"vol",
".",
"Required",
"(",
"\"4\"",
",",
"default",
"=",
"current_io",
".",
"get",
"(",
"\"4\"",
",",
"CONF_IO_DIS",
")",
")",
":",
"OPTIONS_IO_ANY",
",",
"vol",
".",
"Required",
"(",
"\"5\"",
",",
"default",
"=",
"current_io",
".",
"get",
"(",
"\"5\"",
",",
"CONF_IO_DIS",
")",
")",
":",
"OPTIONS_IO_ANY",
",",
"vol",
".",
"Required",
"(",
"\"6\"",
",",
"default",
"=",
"current_io",
".",
"get",
"(",
"\"6\"",
",",
"CONF_IO_DIS",
")",
")",
":",
"OPTIONS_IO_ANY",
",",
"vol",
".",
"Required",
"(",
"\"7\"",
",",
"default",
"=",
"current_io",
".",
"get",
"(",
"\"7\"",
",",
"CONF_IO_DIS",
")",
")",
":",
"OPTIONS_IO_ANY",
",",
"}",
")",
",",
"description_placeholders",
"=",
"{",
"\"model\"",
":",
"KONN_PANEL_MODEL_NAMES",
"[",
"self",
".",
"model",
"]",
",",
"\"host\"",
":",
"self",
".",
"entry",
".",
"data",
"[",
"CONF_HOST",
"]",
",",
"}",
",",
"errors",
"=",
"errors",
",",
")",
"return",
"self",
".",
"async_abort",
"(",
"reason",
"=",
"\"not_konn_panel\"",
")"
] | [
394,
4
] | [
477,
56
] | python | en | ['en', 'en', 'en'] | True |
OptionsFlowHandler.async_step_options_io_ext | (self, user_input=None) | Allow the user to configure the extended IO for pro. | Allow the user to configure the extended IO for pro. | async def async_step_options_io_ext(self, user_input=None):
"""Allow the user to configure the extended IO for pro."""
errors = {}
current_io = self.current_opt.get(CONF_IO, {})
if user_input is not None:
# strip out disabled io and save for options cfg
for key, value in user_input.items():
if value != CONF_IO_DIS:
self.new_opt[CONF_IO].update({key: value})
self.io_cfg = copy.deepcopy(self.new_opt[CONF_IO])
return await self.async_step_options_binary()
if self.model == KONN_MODEL:
self.io_cfg = copy.deepcopy(self.new_opt[CONF_IO])
return await self.async_step_options_binary()
if self.model == KONN_MODEL_PRO:
return self.async_show_form(
step_id="options_io_ext",
data_schema=vol.Schema(
{
vol.Required(
"8", default=current_io.get("8", CONF_IO_DIS)
): OPTIONS_IO_ANY,
vol.Required(
"9", default=current_io.get("9", CONF_IO_DIS)
): OPTIONS_IO_INPUT_ONLY,
vol.Required(
"10", default=current_io.get("10", CONF_IO_DIS)
): OPTIONS_IO_INPUT_ONLY,
vol.Required(
"11", default=current_io.get("11", CONF_IO_DIS)
): OPTIONS_IO_INPUT_ONLY,
vol.Required(
"12", default=current_io.get("12", CONF_IO_DIS)
): OPTIONS_IO_INPUT_ONLY,
vol.Required(
"alarm1", default=current_io.get("alarm1", CONF_IO_DIS)
): OPTIONS_IO_OUTPUT_ONLY,
vol.Required(
"out1", default=current_io.get("out1", CONF_IO_DIS)
): OPTIONS_IO_OUTPUT_ONLY,
vol.Required(
"alarm2_out2",
default=current_io.get("alarm2_out2", CONF_IO_DIS),
): OPTIONS_IO_OUTPUT_ONLY,
}
),
description_placeholders={
"model": KONN_PANEL_MODEL_NAMES[self.model],
"host": self.entry.data[CONF_HOST],
},
errors=errors,
)
return self.async_abort(reason="not_konn_panel") | [
"async",
"def",
"async_step_options_io_ext",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"errors",
"=",
"{",
"}",
"current_io",
"=",
"self",
".",
"current_opt",
".",
"get",
"(",
"CONF_IO",
",",
"{",
"}",
")",
"if",
"user_input",
"is",
"not",
"None",
":",
"# strip out disabled io and save for options cfg",
"for",
"key",
",",
"value",
"in",
"user_input",
".",
"items",
"(",
")",
":",
"if",
"value",
"!=",
"CONF_IO_DIS",
":",
"self",
".",
"new_opt",
"[",
"CONF_IO",
"]",
".",
"update",
"(",
"{",
"key",
":",
"value",
"}",
")",
"self",
".",
"io_cfg",
"=",
"copy",
".",
"deepcopy",
"(",
"self",
".",
"new_opt",
"[",
"CONF_IO",
"]",
")",
"return",
"await",
"self",
".",
"async_step_options_binary",
"(",
")",
"if",
"self",
".",
"model",
"==",
"KONN_MODEL",
":",
"self",
".",
"io_cfg",
"=",
"copy",
".",
"deepcopy",
"(",
"self",
".",
"new_opt",
"[",
"CONF_IO",
"]",
")",
"return",
"await",
"self",
".",
"async_step_options_binary",
"(",
")",
"if",
"self",
".",
"model",
"==",
"KONN_MODEL_PRO",
":",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"options_io_ext\"",
",",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"{",
"vol",
".",
"Required",
"(",
"\"8\"",
",",
"default",
"=",
"current_io",
".",
"get",
"(",
"\"8\"",
",",
"CONF_IO_DIS",
")",
")",
":",
"OPTIONS_IO_ANY",
",",
"vol",
".",
"Required",
"(",
"\"9\"",
",",
"default",
"=",
"current_io",
".",
"get",
"(",
"\"9\"",
",",
"CONF_IO_DIS",
")",
")",
":",
"OPTIONS_IO_INPUT_ONLY",
",",
"vol",
".",
"Required",
"(",
"\"10\"",
",",
"default",
"=",
"current_io",
".",
"get",
"(",
"\"10\"",
",",
"CONF_IO_DIS",
")",
")",
":",
"OPTIONS_IO_INPUT_ONLY",
",",
"vol",
".",
"Required",
"(",
"\"11\"",
",",
"default",
"=",
"current_io",
".",
"get",
"(",
"\"11\"",
",",
"CONF_IO_DIS",
")",
")",
":",
"OPTIONS_IO_INPUT_ONLY",
",",
"vol",
".",
"Required",
"(",
"\"12\"",
",",
"default",
"=",
"current_io",
".",
"get",
"(",
"\"12\"",
",",
"CONF_IO_DIS",
")",
")",
":",
"OPTIONS_IO_INPUT_ONLY",
",",
"vol",
".",
"Required",
"(",
"\"alarm1\"",
",",
"default",
"=",
"current_io",
".",
"get",
"(",
"\"alarm1\"",
",",
"CONF_IO_DIS",
")",
")",
":",
"OPTIONS_IO_OUTPUT_ONLY",
",",
"vol",
".",
"Required",
"(",
"\"out1\"",
",",
"default",
"=",
"current_io",
".",
"get",
"(",
"\"out1\"",
",",
"CONF_IO_DIS",
")",
")",
":",
"OPTIONS_IO_OUTPUT_ONLY",
",",
"vol",
".",
"Required",
"(",
"\"alarm2_out2\"",
",",
"default",
"=",
"current_io",
".",
"get",
"(",
"\"alarm2_out2\"",
",",
"CONF_IO_DIS",
")",
",",
")",
":",
"OPTIONS_IO_OUTPUT_ONLY",
",",
"}",
")",
",",
"description_placeholders",
"=",
"{",
"\"model\"",
":",
"KONN_PANEL_MODEL_NAMES",
"[",
"self",
".",
"model",
"]",
",",
"\"host\"",
":",
"self",
".",
"entry",
".",
"data",
"[",
"CONF_HOST",
"]",
",",
"}",
",",
"errors",
"=",
"errors",
",",
")",
"return",
"self",
".",
"async_abort",
"(",
"reason",
"=",
"\"not_konn_panel\"",
")"
] | [
479,
4
] | [
535,
56
] | python | en | ['en', 'en', 'en'] | True |
OptionsFlowHandler.async_step_options_binary | (self, user_input=None) | Allow the user to configure the IO options for binary sensors. | Allow the user to configure the IO options for binary sensors. | async def async_step_options_binary(self, user_input=None):
"""Allow the user to configure the IO options for binary sensors."""
errors = {}
if user_input is not None:
zone = {"zone": self.active_cfg}
zone.update(user_input)
self.new_opt[CONF_BINARY_SENSORS] = self.new_opt.get(
CONF_BINARY_SENSORS, []
) + [zone]
self.io_cfg.pop(self.active_cfg)
self.active_cfg = None
if self.active_cfg:
current_cfg = self.get_current_cfg(CONF_BINARY_SENSORS, self.active_cfg)
return self.async_show_form(
step_id="options_binary",
data_schema=vol.Schema(
{
vol.Required(
CONF_TYPE,
default=current_cfg.get(CONF_TYPE, DEVICE_CLASS_DOOR),
): DEVICE_CLASSES_SCHEMA,
vol.Optional(
CONF_NAME, default=current_cfg.get(CONF_NAME, vol.UNDEFINED)
): str,
vol.Optional(
CONF_INVERSE, default=current_cfg.get(CONF_INVERSE, False)
): bool,
}
),
description_placeholders={
"zone": f"Zone {self.active_cfg}"
if len(self.active_cfg) < 3
else self.active_cfg.upper
},
errors=errors,
)
# find the next unconfigured binary sensor
for key, value in self.io_cfg.items():
if value == CONF_IO_BIN:
self.active_cfg = key
current_cfg = self.get_current_cfg(CONF_BINARY_SENSORS, self.active_cfg)
return self.async_show_form(
step_id="options_binary",
data_schema=vol.Schema(
{
vol.Required(
CONF_TYPE,
default=current_cfg.get(CONF_TYPE, DEVICE_CLASS_DOOR),
): DEVICE_CLASSES_SCHEMA,
vol.Optional(
CONF_NAME,
default=current_cfg.get(CONF_NAME, vol.UNDEFINED),
): str,
vol.Optional(
CONF_INVERSE,
default=current_cfg.get(CONF_INVERSE, False),
): bool,
}
),
description_placeholders={
"zone": f"Zone {self.active_cfg}"
if len(self.active_cfg) < 3
else self.active_cfg.upper
},
errors=errors,
)
return await self.async_step_options_digital() | [
"async",
"def",
"async_step_options_binary",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"errors",
"=",
"{",
"}",
"if",
"user_input",
"is",
"not",
"None",
":",
"zone",
"=",
"{",
"\"zone\"",
":",
"self",
".",
"active_cfg",
"}",
"zone",
".",
"update",
"(",
"user_input",
")",
"self",
".",
"new_opt",
"[",
"CONF_BINARY_SENSORS",
"]",
"=",
"self",
".",
"new_opt",
".",
"get",
"(",
"CONF_BINARY_SENSORS",
",",
"[",
"]",
")",
"+",
"[",
"zone",
"]",
"self",
".",
"io_cfg",
".",
"pop",
"(",
"self",
".",
"active_cfg",
")",
"self",
".",
"active_cfg",
"=",
"None",
"if",
"self",
".",
"active_cfg",
":",
"current_cfg",
"=",
"self",
".",
"get_current_cfg",
"(",
"CONF_BINARY_SENSORS",
",",
"self",
".",
"active_cfg",
")",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"options_binary\"",
",",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"{",
"vol",
".",
"Required",
"(",
"CONF_TYPE",
",",
"default",
"=",
"current_cfg",
".",
"get",
"(",
"CONF_TYPE",
",",
"DEVICE_CLASS_DOOR",
")",
",",
")",
":",
"DEVICE_CLASSES_SCHEMA",
",",
"vol",
".",
"Optional",
"(",
"CONF_NAME",
",",
"default",
"=",
"current_cfg",
".",
"get",
"(",
"CONF_NAME",
",",
"vol",
".",
"UNDEFINED",
")",
")",
":",
"str",
",",
"vol",
".",
"Optional",
"(",
"CONF_INVERSE",
",",
"default",
"=",
"current_cfg",
".",
"get",
"(",
"CONF_INVERSE",
",",
"False",
")",
")",
":",
"bool",
",",
"}",
")",
",",
"description_placeholders",
"=",
"{",
"\"zone\"",
":",
"f\"Zone {self.active_cfg}\"",
"if",
"len",
"(",
"self",
".",
"active_cfg",
")",
"<",
"3",
"else",
"self",
".",
"active_cfg",
".",
"upper",
"}",
",",
"errors",
"=",
"errors",
",",
")",
"# find the next unconfigured binary sensor",
"for",
"key",
",",
"value",
"in",
"self",
".",
"io_cfg",
".",
"items",
"(",
")",
":",
"if",
"value",
"==",
"CONF_IO_BIN",
":",
"self",
".",
"active_cfg",
"=",
"key",
"current_cfg",
"=",
"self",
".",
"get_current_cfg",
"(",
"CONF_BINARY_SENSORS",
",",
"self",
".",
"active_cfg",
")",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"options_binary\"",
",",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"{",
"vol",
".",
"Required",
"(",
"CONF_TYPE",
",",
"default",
"=",
"current_cfg",
".",
"get",
"(",
"CONF_TYPE",
",",
"DEVICE_CLASS_DOOR",
")",
",",
")",
":",
"DEVICE_CLASSES_SCHEMA",
",",
"vol",
".",
"Optional",
"(",
"CONF_NAME",
",",
"default",
"=",
"current_cfg",
".",
"get",
"(",
"CONF_NAME",
",",
"vol",
".",
"UNDEFINED",
")",
",",
")",
":",
"str",
",",
"vol",
".",
"Optional",
"(",
"CONF_INVERSE",
",",
"default",
"=",
"current_cfg",
".",
"get",
"(",
"CONF_INVERSE",
",",
"False",
")",
",",
")",
":",
"bool",
",",
"}",
")",
",",
"description_placeholders",
"=",
"{",
"\"zone\"",
":",
"f\"Zone {self.active_cfg}\"",
"if",
"len",
"(",
"self",
".",
"active_cfg",
")",
"<",
"3",
"else",
"self",
".",
"active_cfg",
".",
"upper",
"}",
",",
"errors",
"=",
"errors",
",",
")",
"return",
"await",
"self",
".",
"async_step_options_digital",
"(",
")"
] | [
537,
4
] | [
606,
54
] | python | en | ['en', 'en', 'en'] | True |
OptionsFlowHandler.async_step_options_digital | (self, user_input=None) | Allow the user to configure the IO options for digital sensors. | Allow the user to configure the IO options for digital sensors. | async def async_step_options_digital(self, user_input=None):
"""Allow the user to configure the IO options for digital sensors."""
errors = {}
if user_input is not None:
zone = {"zone": self.active_cfg}
zone.update(user_input)
self.new_opt[CONF_SENSORS] = self.new_opt.get(CONF_SENSORS, []) + [zone]
self.io_cfg.pop(self.active_cfg)
self.active_cfg = None
if self.active_cfg:
current_cfg = self.get_current_cfg(CONF_SENSORS, self.active_cfg)
return self.async_show_form(
step_id="options_digital",
data_schema=vol.Schema(
{
vol.Required(
CONF_TYPE, default=current_cfg.get(CONF_TYPE, "dht")
): vol.All(vol.Lower, vol.In(["dht", "ds18b20"])),
vol.Optional(
CONF_NAME, default=current_cfg.get(CONF_NAME, vol.UNDEFINED)
): str,
vol.Optional(
CONF_POLL_INTERVAL,
default=current_cfg.get(CONF_POLL_INTERVAL, 3),
): vol.All(vol.Coerce(int), vol.Range(min=1)),
}
),
description_placeholders={
"zone": f"Zone {self.active_cfg}"
if len(self.active_cfg) < 3
else self.active_cfg.upper()
},
errors=errors,
)
# find the next unconfigured digital sensor
for key, value in self.io_cfg.items():
if value == CONF_IO_DIG:
self.active_cfg = key
current_cfg = self.get_current_cfg(CONF_SENSORS, self.active_cfg)
return self.async_show_form(
step_id="options_digital",
data_schema=vol.Schema(
{
vol.Required(
CONF_TYPE, default=current_cfg.get(CONF_TYPE, "dht")
): vol.All(vol.Lower, vol.In(["dht", "ds18b20"])),
vol.Optional(
CONF_NAME,
default=current_cfg.get(CONF_NAME, vol.UNDEFINED),
): str,
vol.Optional(
CONF_POLL_INTERVAL,
default=current_cfg.get(CONF_POLL_INTERVAL, 3),
): vol.All(vol.Coerce(int), vol.Range(min=1)),
}
),
description_placeholders={
"zone": f"Zone {self.active_cfg}"
if len(self.active_cfg) < 3
else self.active_cfg.upper()
},
errors=errors,
)
return await self.async_step_options_switch() | [
"async",
"def",
"async_step_options_digital",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"errors",
"=",
"{",
"}",
"if",
"user_input",
"is",
"not",
"None",
":",
"zone",
"=",
"{",
"\"zone\"",
":",
"self",
".",
"active_cfg",
"}",
"zone",
".",
"update",
"(",
"user_input",
")",
"self",
".",
"new_opt",
"[",
"CONF_SENSORS",
"]",
"=",
"self",
".",
"new_opt",
".",
"get",
"(",
"CONF_SENSORS",
",",
"[",
"]",
")",
"+",
"[",
"zone",
"]",
"self",
".",
"io_cfg",
".",
"pop",
"(",
"self",
".",
"active_cfg",
")",
"self",
".",
"active_cfg",
"=",
"None",
"if",
"self",
".",
"active_cfg",
":",
"current_cfg",
"=",
"self",
".",
"get_current_cfg",
"(",
"CONF_SENSORS",
",",
"self",
".",
"active_cfg",
")",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"options_digital\"",
",",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"{",
"vol",
".",
"Required",
"(",
"CONF_TYPE",
",",
"default",
"=",
"current_cfg",
".",
"get",
"(",
"CONF_TYPE",
",",
"\"dht\"",
")",
")",
":",
"vol",
".",
"All",
"(",
"vol",
".",
"Lower",
",",
"vol",
".",
"In",
"(",
"[",
"\"dht\"",
",",
"\"ds18b20\"",
"]",
")",
")",
",",
"vol",
".",
"Optional",
"(",
"CONF_NAME",
",",
"default",
"=",
"current_cfg",
".",
"get",
"(",
"CONF_NAME",
",",
"vol",
".",
"UNDEFINED",
")",
")",
":",
"str",
",",
"vol",
".",
"Optional",
"(",
"CONF_POLL_INTERVAL",
",",
"default",
"=",
"current_cfg",
".",
"get",
"(",
"CONF_POLL_INTERVAL",
",",
"3",
")",
",",
")",
":",
"vol",
".",
"All",
"(",
"vol",
".",
"Coerce",
"(",
"int",
")",
",",
"vol",
".",
"Range",
"(",
"min",
"=",
"1",
")",
")",
",",
"}",
")",
",",
"description_placeholders",
"=",
"{",
"\"zone\"",
":",
"f\"Zone {self.active_cfg}\"",
"if",
"len",
"(",
"self",
".",
"active_cfg",
")",
"<",
"3",
"else",
"self",
".",
"active_cfg",
".",
"upper",
"(",
")",
"}",
",",
"errors",
"=",
"errors",
",",
")",
"# find the next unconfigured digital sensor",
"for",
"key",
",",
"value",
"in",
"self",
".",
"io_cfg",
".",
"items",
"(",
")",
":",
"if",
"value",
"==",
"CONF_IO_DIG",
":",
"self",
".",
"active_cfg",
"=",
"key",
"current_cfg",
"=",
"self",
".",
"get_current_cfg",
"(",
"CONF_SENSORS",
",",
"self",
".",
"active_cfg",
")",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"options_digital\"",
",",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"{",
"vol",
".",
"Required",
"(",
"CONF_TYPE",
",",
"default",
"=",
"current_cfg",
".",
"get",
"(",
"CONF_TYPE",
",",
"\"dht\"",
")",
")",
":",
"vol",
".",
"All",
"(",
"vol",
".",
"Lower",
",",
"vol",
".",
"In",
"(",
"[",
"\"dht\"",
",",
"\"ds18b20\"",
"]",
")",
")",
",",
"vol",
".",
"Optional",
"(",
"CONF_NAME",
",",
"default",
"=",
"current_cfg",
".",
"get",
"(",
"CONF_NAME",
",",
"vol",
".",
"UNDEFINED",
")",
",",
")",
":",
"str",
",",
"vol",
".",
"Optional",
"(",
"CONF_POLL_INTERVAL",
",",
"default",
"=",
"current_cfg",
".",
"get",
"(",
"CONF_POLL_INTERVAL",
",",
"3",
")",
",",
")",
":",
"vol",
".",
"All",
"(",
"vol",
".",
"Coerce",
"(",
"int",
")",
",",
"vol",
".",
"Range",
"(",
"min",
"=",
"1",
")",
")",
",",
"}",
")",
",",
"description_placeholders",
"=",
"{",
"\"zone\"",
":",
"f\"Zone {self.active_cfg}\"",
"if",
"len",
"(",
"self",
".",
"active_cfg",
")",
"<",
"3",
"else",
"self",
".",
"active_cfg",
".",
"upper",
"(",
")",
"}",
",",
"errors",
"=",
"errors",
",",
")",
"return",
"await",
"self",
".",
"async_step_options_switch",
"(",
")"
] | [
608,
4
] | [
674,
53
] | python | en | ['en', 'en', 'en'] | True |
OptionsFlowHandler.async_step_options_switch | (self, user_input=None) | Allow the user to configure the IO options for switches. | Allow the user to configure the IO options for switches. | async def async_step_options_switch(self, user_input=None):
"""Allow the user to configure the IO options for switches."""
errors = {}
if user_input is not None:
zone = {"zone": self.active_cfg}
zone.update(user_input)
del zone[CONF_MORE_STATES]
self.new_opt[CONF_SWITCHES] = self.new_opt.get(CONF_SWITCHES, []) + [zone]
# iterate through multiple switch states
if self.current_states:
self.current_states.pop(0)
# only go to next zone if all states are entered
self.current_state += 1
if user_input[CONF_MORE_STATES] == CONF_NO:
self.io_cfg.pop(self.active_cfg)
self.active_cfg = None
if self.active_cfg:
current_cfg = next(iter(self.current_states), {})
return self.async_show_form(
step_id="options_switch",
data_schema=vol.Schema(
{
vol.Optional(
CONF_NAME, default=current_cfg.get(CONF_NAME, vol.UNDEFINED)
): str,
vol.Optional(
CONF_ACTIVATION,
default=current_cfg.get(CONF_ACTIVATION, STATE_HIGH),
): vol.All(vol.Lower, vol.In([STATE_HIGH, STATE_LOW])),
vol.Optional(
CONF_MOMENTARY,
default=current_cfg.get(CONF_MOMENTARY, vol.UNDEFINED),
): vol.All(vol.Coerce(int), vol.Range(min=10)),
vol.Optional(
CONF_PAUSE,
default=current_cfg.get(CONF_PAUSE, vol.UNDEFINED),
): vol.All(vol.Coerce(int), vol.Range(min=10)),
vol.Optional(
CONF_REPEAT,
default=current_cfg.get(CONF_REPEAT, vol.UNDEFINED),
): vol.All(vol.Coerce(int), vol.Range(min=-1)),
vol.Required(
CONF_MORE_STATES,
default=CONF_YES
if len(self.current_states) > 1
else CONF_NO,
): vol.In([CONF_YES, CONF_NO]),
}
),
description_placeholders={
"zone": f"Zone {self.active_cfg}"
if len(self.active_cfg) < 3
else self.active_cfg.upper(),
"state": str(self.current_state),
},
errors=errors,
)
# find the next unconfigured switch
for key, value in self.io_cfg.items():
if value == CONF_IO_SWI:
self.active_cfg = key
self.current_states = [
cfg
for cfg in self.current_opt.get(CONF_SWITCHES, [])
if cfg[CONF_ZONE] == self.active_cfg
]
current_cfg = next(iter(self.current_states), {})
self.current_state = 1
return self.async_show_form(
step_id="options_switch",
data_schema=vol.Schema(
{
vol.Optional(
CONF_NAME,
default=current_cfg.get(CONF_NAME, vol.UNDEFINED),
): str,
vol.Optional(
CONF_ACTIVATION,
default=current_cfg.get(CONF_ACTIVATION, STATE_HIGH),
): vol.In(["low", "high"]),
vol.Optional(
CONF_MOMENTARY,
default=current_cfg.get(CONF_MOMENTARY, vol.UNDEFINED),
): vol.All(vol.Coerce(int), vol.Range(min=10)),
vol.Optional(
CONF_PAUSE,
default=current_cfg.get(CONF_PAUSE, vol.UNDEFINED),
): vol.All(vol.Coerce(int), vol.Range(min=10)),
vol.Optional(
CONF_REPEAT,
default=current_cfg.get(CONF_REPEAT, vol.UNDEFINED),
): vol.All(vol.Coerce(int), vol.Range(min=-1)),
vol.Required(
CONF_MORE_STATES,
default=CONF_YES
if len(self.current_states) > 1
else CONF_NO,
): vol.In([CONF_YES, CONF_NO]),
}
),
description_placeholders={
"zone": f"Zone {self.active_cfg}"
if len(self.active_cfg) < 3
else self.active_cfg.upper(),
"state": str(self.current_state),
},
errors=errors,
)
return await self.async_step_options_misc() | [
"async",
"def",
"async_step_options_switch",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"errors",
"=",
"{",
"}",
"if",
"user_input",
"is",
"not",
"None",
":",
"zone",
"=",
"{",
"\"zone\"",
":",
"self",
".",
"active_cfg",
"}",
"zone",
".",
"update",
"(",
"user_input",
")",
"del",
"zone",
"[",
"CONF_MORE_STATES",
"]",
"self",
".",
"new_opt",
"[",
"CONF_SWITCHES",
"]",
"=",
"self",
".",
"new_opt",
".",
"get",
"(",
"CONF_SWITCHES",
",",
"[",
"]",
")",
"+",
"[",
"zone",
"]",
"# iterate through multiple switch states",
"if",
"self",
".",
"current_states",
":",
"self",
".",
"current_states",
".",
"pop",
"(",
"0",
")",
"# only go to next zone if all states are entered",
"self",
".",
"current_state",
"+=",
"1",
"if",
"user_input",
"[",
"CONF_MORE_STATES",
"]",
"==",
"CONF_NO",
":",
"self",
".",
"io_cfg",
".",
"pop",
"(",
"self",
".",
"active_cfg",
")",
"self",
".",
"active_cfg",
"=",
"None",
"if",
"self",
".",
"active_cfg",
":",
"current_cfg",
"=",
"next",
"(",
"iter",
"(",
"self",
".",
"current_states",
")",
",",
"{",
"}",
")",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"options_switch\"",
",",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"{",
"vol",
".",
"Optional",
"(",
"CONF_NAME",
",",
"default",
"=",
"current_cfg",
".",
"get",
"(",
"CONF_NAME",
",",
"vol",
".",
"UNDEFINED",
")",
")",
":",
"str",
",",
"vol",
".",
"Optional",
"(",
"CONF_ACTIVATION",
",",
"default",
"=",
"current_cfg",
".",
"get",
"(",
"CONF_ACTIVATION",
",",
"STATE_HIGH",
")",
",",
")",
":",
"vol",
".",
"All",
"(",
"vol",
".",
"Lower",
",",
"vol",
".",
"In",
"(",
"[",
"STATE_HIGH",
",",
"STATE_LOW",
"]",
")",
")",
",",
"vol",
".",
"Optional",
"(",
"CONF_MOMENTARY",
",",
"default",
"=",
"current_cfg",
".",
"get",
"(",
"CONF_MOMENTARY",
",",
"vol",
".",
"UNDEFINED",
")",
",",
")",
":",
"vol",
".",
"All",
"(",
"vol",
".",
"Coerce",
"(",
"int",
")",
",",
"vol",
".",
"Range",
"(",
"min",
"=",
"10",
")",
")",
",",
"vol",
".",
"Optional",
"(",
"CONF_PAUSE",
",",
"default",
"=",
"current_cfg",
".",
"get",
"(",
"CONF_PAUSE",
",",
"vol",
".",
"UNDEFINED",
")",
",",
")",
":",
"vol",
".",
"All",
"(",
"vol",
".",
"Coerce",
"(",
"int",
")",
",",
"vol",
".",
"Range",
"(",
"min",
"=",
"10",
")",
")",
",",
"vol",
".",
"Optional",
"(",
"CONF_REPEAT",
",",
"default",
"=",
"current_cfg",
".",
"get",
"(",
"CONF_REPEAT",
",",
"vol",
".",
"UNDEFINED",
")",
",",
")",
":",
"vol",
".",
"All",
"(",
"vol",
".",
"Coerce",
"(",
"int",
")",
",",
"vol",
".",
"Range",
"(",
"min",
"=",
"-",
"1",
")",
")",
",",
"vol",
".",
"Required",
"(",
"CONF_MORE_STATES",
",",
"default",
"=",
"CONF_YES",
"if",
"len",
"(",
"self",
".",
"current_states",
")",
">",
"1",
"else",
"CONF_NO",
",",
")",
":",
"vol",
".",
"In",
"(",
"[",
"CONF_YES",
",",
"CONF_NO",
"]",
")",
",",
"}",
")",
",",
"description_placeholders",
"=",
"{",
"\"zone\"",
":",
"f\"Zone {self.active_cfg}\"",
"if",
"len",
"(",
"self",
".",
"active_cfg",
")",
"<",
"3",
"else",
"self",
".",
"active_cfg",
".",
"upper",
"(",
")",
",",
"\"state\"",
":",
"str",
"(",
"self",
".",
"current_state",
")",
",",
"}",
",",
"errors",
"=",
"errors",
",",
")",
"# find the next unconfigured switch",
"for",
"key",
",",
"value",
"in",
"self",
".",
"io_cfg",
".",
"items",
"(",
")",
":",
"if",
"value",
"==",
"CONF_IO_SWI",
":",
"self",
".",
"active_cfg",
"=",
"key",
"self",
".",
"current_states",
"=",
"[",
"cfg",
"for",
"cfg",
"in",
"self",
".",
"current_opt",
".",
"get",
"(",
"CONF_SWITCHES",
",",
"[",
"]",
")",
"if",
"cfg",
"[",
"CONF_ZONE",
"]",
"==",
"self",
".",
"active_cfg",
"]",
"current_cfg",
"=",
"next",
"(",
"iter",
"(",
"self",
".",
"current_states",
")",
",",
"{",
"}",
")",
"self",
".",
"current_state",
"=",
"1",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"options_switch\"",
",",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"{",
"vol",
".",
"Optional",
"(",
"CONF_NAME",
",",
"default",
"=",
"current_cfg",
".",
"get",
"(",
"CONF_NAME",
",",
"vol",
".",
"UNDEFINED",
")",
",",
")",
":",
"str",
",",
"vol",
".",
"Optional",
"(",
"CONF_ACTIVATION",
",",
"default",
"=",
"current_cfg",
".",
"get",
"(",
"CONF_ACTIVATION",
",",
"STATE_HIGH",
")",
",",
")",
":",
"vol",
".",
"In",
"(",
"[",
"\"low\"",
",",
"\"high\"",
"]",
")",
",",
"vol",
".",
"Optional",
"(",
"CONF_MOMENTARY",
",",
"default",
"=",
"current_cfg",
".",
"get",
"(",
"CONF_MOMENTARY",
",",
"vol",
".",
"UNDEFINED",
")",
",",
")",
":",
"vol",
".",
"All",
"(",
"vol",
".",
"Coerce",
"(",
"int",
")",
",",
"vol",
".",
"Range",
"(",
"min",
"=",
"10",
")",
")",
",",
"vol",
".",
"Optional",
"(",
"CONF_PAUSE",
",",
"default",
"=",
"current_cfg",
".",
"get",
"(",
"CONF_PAUSE",
",",
"vol",
".",
"UNDEFINED",
")",
",",
")",
":",
"vol",
".",
"All",
"(",
"vol",
".",
"Coerce",
"(",
"int",
")",
",",
"vol",
".",
"Range",
"(",
"min",
"=",
"10",
")",
")",
",",
"vol",
".",
"Optional",
"(",
"CONF_REPEAT",
",",
"default",
"=",
"current_cfg",
".",
"get",
"(",
"CONF_REPEAT",
",",
"vol",
".",
"UNDEFINED",
")",
",",
")",
":",
"vol",
".",
"All",
"(",
"vol",
".",
"Coerce",
"(",
"int",
")",
",",
"vol",
".",
"Range",
"(",
"min",
"=",
"-",
"1",
")",
")",
",",
"vol",
".",
"Required",
"(",
"CONF_MORE_STATES",
",",
"default",
"=",
"CONF_YES",
"if",
"len",
"(",
"self",
".",
"current_states",
")",
">",
"1",
"else",
"CONF_NO",
",",
")",
":",
"vol",
".",
"In",
"(",
"[",
"CONF_YES",
",",
"CONF_NO",
"]",
")",
",",
"}",
")",
",",
"description_placeholders",
"=",
"{",
"\"zone\"",
":",
"f\"Zone {self.active_cfg}\"",
"if",
"len",
"(",
"self",
".",
"active_cfg",
")",
"<",
"3",
"else",
"self",
".",
"active_cfg",
".",
"upper",
"(",
")",
",",
"\"state\"",
":",
"str",
"(",
"self",
".",
"current_state",
")",
",",
"}",
",",
"errors",
"=",
"errors",
",",
")",
"return",
"await",
"self",
".",
"async_step_options_misc",
"(",
")"
] | [
676,
4
] | [
789,
51
] | python | en | ['en', 'en', 'en'] | True |
OptionsFlowHandler.async_step_options_misc | (self, user_input=None) | Allow the user to configure the LED behavior. | Allow the user to configure the LED behavior. | async def async_step_options_misc(self, user_input=None):
"""Allow the user to configure the LED behavior."""
errors = {}
if user_input is not None:
# config schema only does basic schema val so check url here
try:
if user_input[CONF_OVERRIDE_API_HOST]:
cv.url(user_input.get(CONF_API_HOST, ""))
else:
user_input[CONF_API_HOST] = ""
except vol.Invalid:
errors["base"] = "bad_host"
else:
# no need to store the override - can infer
del user_input[CONF_OVERRIDE_API_HOST]
self.new_opt.update(user_input)
return self.async_create_entry(title="", data=self.new_opt)
return self.async_show_form(
step_id="options_misc",
data_schema=vol.Schema(
{
vol.Required(
CONF_DISCOVERY,
default=self.current_opt.get(CONF_DISCOVERY, True),
): bool,
vol.Required(
CONF_BLINK, default=self.current_opt.get(CONF_BLINK, True)
): bool,
vol.Required(
CONF_OVERRIDE_API_HOST,
default=bool(self.current_opt.get(CONF_API_HOST)),
): bool,
vol.Optional(
CONF_API_HOST, default=self.current_opt.get(CONF_API_HOST, "")
): str,
}
),
errors=errors,
) | [
"async",
"def",
"async_step_options_misc",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"errors",
"=",
"{",
"}",
"if",
"user_input",
"is",
"not",
"None",
":",
"# config schema only does basic schema val so check url here",
"try",
":",
"if",
"user_input",
"[",
"CONF_OVERRIDE_API_HOST",
"]",
":",
"cv",
".",
"url",
"(",
"user_input",
".",
"get",
"(",
"CONF_API_HOST",
",",
"\"\"",
")",
")",
"else",
":",
"user_input",
"[",
"CONF_API_HOST",
"]",
"=",
"\"\"",
"except",
"vol",
".",
"Invalid",
":",
"errors",
"[",
"\"base\"",
"]",
"=",
"\"bad_host\"",
"else",
":",
"# no need to store the override - can infer",
"del",
"user_input",
"[",
"CONF_OVERRIDE_API_HOST",
"]",
"self",
".",
"new_opt",
".",
"update",
"(",
"user_input",
")",
"return",
"self",
".",
"async_create_entry",
"(",
"title",
"=",
"\"\"",
",",
"data",
"=",
"self",
".",
"new_opt",
")",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"options_misc\"",
",",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"{",
"vol",
".",
"Required",
"(",
"CONF_DISCOVERY",
",",
"default",
"=",
"self",
".",
"current_opt",
".",
"get",
"(",
"CONF_DISCOVERY",
",",
"True",
")",
",",
")",
":",
"bool",
",",
"vol",
".",
"Required",
"(",
"CONF_BLINK",
",",
"default",
"=",
"self",
".",
"current_opt",
".",
"get",
"(",
"CONF_BLINK",
",",
"True",
")",
")",
":",
"bool",
",",
"vol",
".",
"Required",
"(",
"CONF_OVERRIDE_API_HOST",
",",
"default",
"=",
"bool",
"(",
"self",
".",
"current_opt",
".",
"get",
"(",
"CONF_API_HOST",
")",
")",
",",
")",
":",
"bool",
",",
"vol",
".",
"Optional",
"(",
"CONF_API_HOST",
",",
"default",
"=",
"self",
".",
"current_opt",
".",
"get",
"(",
"CONF_API_HOST",
",",
"\"\"",
")",
")",
":",
"str",
",",
"}",
")",
",",
"errors",
"=",
"errors",
",",
")"
] | [
791,
4
] | [
830,
9
] | python | en | ['en', 'en', 'en'] | True |
mock_command | (self, cmd, params=None) | Mock the Mikrotik command method. | Mock the Mikrotik command method. | def mock_command(self, cmd, params=None):
"""Mock the Mikrotik command method."""
if cmd == mikrotik.const.MIKROTIK_SERVICES[mikrotik.const.IS_WIRELESS]:
return True
if cmd == mikrotik.const.MIKROTIK_SERVICES[mikrotik.const.DHCP]:
return DHCP_DATA
if cmd == mikrotik.const.MIKROTIK_SERVICES[mikrotik.const.WIRELESS]:
return WIRELESS_DATA
return {} | [
"def",
"mock_command",
"(",
"self",
",",
"cmd",
",",
"params",
"=",
"None",
")",
":",
"if",
"cmd",
"==",
"mikrotik",
".",
"const",
".",
"MIKROTIK_SERVICES",
"[",
"mikrotik",
".",
"const",
".",
"IS_WIRELESS",
"]",
":",
"return",
"True",
"if",
"cmd",
"==",
"mikrotik",
".",
"const",
".",
"MIKROTIK_SERVICES",
"[",
"mikrotik",
".",
"const",
".",
"DHCP",
"]",
":",
"return",
"DHCP_DATA",
"if",
"cmd",
"==",
"mikrotik",
".",
"const",
".",
"MIKROTIK_SERVICES",
"[",
"mikrotik",
".",
"const",
".",
"WIRELESS",
"]",
":",
"return",
"WIRELESS_DATA",
"return",
"{",
"}"
] | [
17,
0
] | [
25,
13
] | python | en | ['en', 'et', 'en'] | True |
test_platform_manually_configured | (hass) | Test that nothing happens when configuring mikrotik through device tracker platform. | Test that nothing happens when configuring mikrotik through device tracker platform. | async def test_platform_manually_configured(hass):
"""Test that nothing happens when configuring mikrotik through device tracker platform."""
assert (
await async_setup_component(
hass,
device_tracker.DOMAIN,
{device_tracker.DOMAIN: {"platform": "mikrotik"}},
)
is False
)
assert mikrotik.DOMAIN not in hass.data | [
"async",
"def",
"test_platform_manually_configured",
"(",
"hass",
")",
":",
"assert",
"(",
"await",
"async_setup_component",
"(",
"hass",
",",
"device_tracker",
".",
"DOMAIN",
",",
"{",
"device_tracker",
".",
"DOMAIN",
":",
"{",
"\"platform\"",
":",
"\"mikrotik\"",
"}",
"}",
",",
")",
"is",
"False",
")",
"assert",
"mikrotik",
".",
"DOMAIN",
"not",
"in",
"hass",
".",
"data"
] | [
28,
0
] | [
38,
43
] | python | en | ['en', 'en', 'en'] | True |
test_device_trackers | (hass, legacy_patchable_time) | Test device_trackers created by mikrotik. | Test device_trackers created by mikrotik. | async def test_device_trackers(hass, legacy_patchable_time):
"""Test device_trackers created by mikrotik."""
# test devices are added from wireless list only
hub = await setup_mikrotik_entry(hass)
device_1 = hass.states.get("device_tracker.device_1")
assert device_1 is not None
assert device_1.state == "home"
device_2 = hass.states.get("device_tracker.device_2")
assert device_2 is None
with patch.object(mikrotik.hub.MikrotikData, "command", new=mock_command):
# test device_2 is added after connecting to wireless network
WIRELESS_DATA.append(DEVICE_2_WIRELESS)
await hub.async_update()
await hass.async_block_till_done()
device_2 = hass.states.get("device_tracker.device_2")
assert device_2 is not None
assert device_2.state == "home"
# test state remains home if last_seen consider_home_interval
del WIRELESS_DATA[1] # device 2 is removed from wireless list
hub.api.devices["00:00:00:00:00:02"]._last_seen = dt_util.utcnow() - timedelta(
minutes=4
)
await hub.async_update()
await hass.async_block_till_done()
device_2 = hass.states.get("device_tracker.device_2")
assert device_2.state != "not_home"
# test state changes to away if last_seen > consider_home_interval
hub.api.devices["00:00:00:00:00:02"]._last_seen = dt_util.utcnow() - timedelta(
minutes=5
)
await hub.async_update()
await hass.async_block_till_done()
device_2 = hass.states.get("device_tracker.device_2")
assert device_2.state == "not_home" | [
"async",
"def",
"test_device_trackers",
"(",
"hass",
",",
"legacy_patchable_time",
")",
":",
"# test devices are added from wireless list only",
"hub",
"=",
"await",
"setup_mikrotik_entry",
"(",
"hass",
")",
"device_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_1\"",
")",
"assert",
"device_1",
"is",
"not",
"None",
"assert",
"device_1",
".",
"state",
"==",
"\"home\"",
"device_2",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_2\"",
")",
"assert",
"device_2",
"is",
"None",
"with",
"patch",
".",
"object",
"(",
"mikrotik",
".",
"hub",
".",
"MikrotikData",
",",
"\"command\"",
",",
"new",
"=",
"mock_command",
")",
":",
"# test device_2 is added after connecting to wireless network",
"WIRELESS_DATA",
".",
"append",
"(",
"DEVICE_2_WIRELESS",
")",
"await",
"hub",
".",
"async_update",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"device_2",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_2\"",
")",
"assert",
"device_2",
"is",
"not",
"None",
"assert",
"device_2",
".",
"state",
"==",
"\"home\"",
"# test state remains home if last_seen consider_home_interval",
"del",
"WIRELESS_DATA",
"[",
"1",
"]",
"# device 2 is removed from wireless list",
"hub",
".",
"api",
".",
"devices",
"[",
"\"00:00:00:00:00:02\"",
"]",
".",
"_last_seen",
"=",
"dt_util",
".",
"utcnow",
"(",
")",
"-",
"timedelta",
"(",
"minutes",
"=",
"4",
")",
"await",
"hub",
".",
"async_update",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"device_2",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_2\"",
")",
"assert",
"device_2",
".",
"state",
"!=",
"\"not_home\"",
"# test state changes to away if last_seen > consider_home_interval",
"hub",
".",
"api",
".",
"devices",
"[",
"\"00:00:00:00:00:02\"",
"]",
".",
"_last_seen",
"=",
"dt_util",
".",
"utcnow",
"(",
")",
"-",
"timedelta",
"(",
"minutes",
"=",
"5",
")",
"await",
"hub",
".",
"async_update",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"device_2",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_2\"",
")",
"assert",
"device_2",
".",
"state",
"==",
"\"not_home\""
] | [
41,
0
] | [
83,
43
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.