Search is not available for this dataset
identifier stringlengths 1 155 | parameters stringlengths 2 6.09k | docstring stringlengths 11 63.4k | docstring_summary stringlengths 0 63.4k | function stringlengths 29 99.8k | function_tokens list | start_point list | end_point list | language stringclasses 1
value | docstring_language stringlengths 2 7 | docstring_language_predictions stringlengths 18 23 | is_langid_reliable stringclasses 2
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
CloudPreferences._load_cloud_user | (self) | Load cloud user if available. | Load cloud user if available. | async def _load_cloud_user(self) -> Optional[User]:
"""Load cloud user if available."""
user_id = self._prefs.get(PREF_CLOUD_USER)
if user_id is None:
return None
# Fetch the user. It can happen that the user no longer exists if
# an image was restored without resto... | [
"async",
"def",
"_load_cloud_user",
"(",
"self",
")",
"->",
"Optional",
"[",
"User",
"]",
":",
"user_id",
"=",
"self",
".",
"_prefs",
".",
"get",
"(",
"PREF_CLOUD_USER",
")",
"if",
"user_id",
"is",
"None",
":",
"return",
"None",
"# Fetch the user. It can hap... | [
294,
4
] | [
303,
60
] | python | en | ['en', 'en', 'en'] | True |
CloudPreferences._has_local_trusted_network | (self) | Return if we allow localhost to bypass auth. | Return if we allow localhost to bypass auth. | def _has_local_trusted_network(self) -> bool:
"""Return if we allow localhost to bypass auth."""
local4 = ip_address("127.0.0.1")
local6 = ip_address("::1")
for prv in self._hass.auth.auth_providers:
if prv.type != "trusted_networks":
continue
fo... | [
"def",
"_has_local_trusted_network",
"(",
"self",
")",
"->",
"bool",
":",
"local4",
"=",
"ip_address",
"(",
"\"127.0.0.1\"",
")",
"local6",
"=",
"ip_address",
"(",
"\"::1\"",
")",
"for",
"prv",
"in",
"self",
".",
"_hass",
".",
"auth",
".",
"auth_providers",
... | [
306,
4
] | [
319,
20
] | python | en | ['en', 'en', 'en'] | True |
CloudPreferences._has_local_trusted_proxies | (self) | Return if we allow localhost to be a proxy and use its data. | Return if we allow localhost to be a proxy and use its data. | def _has_local_trusted_proxies(self) -> bool:
"""Return if we allow localhost to be a proxy and use its data."""
if not hasattr(self._hass, "http"):
return False
local4 = ip_address("127.0.0.1")
local6 = ip_address("::1")
if any(
local4 in nwk or local6 ... | [
"def",
"_has_local_trusted_proxies",
"(",
"self",
")",
"->",
"bool",
":",
"if",
"not",
"hasattr",
"(",
"self",
".",
"_hass",
",",
"\"http\"",
")",
":",
"return",
"False",
"local4",
"=",
"ip_address",
"(",
"\"127.0.0.1\"",
")",
"local6",
"=",
"ip_address",
... | [
322,
4
] | [
335,
20
] | python | en | ['en', 'en', 'en'] | True |
CloudPreferences._save_prefs | (self, prefs) | Save preferences to disk. | Save preferences to disk. | async def _save_prefs(self, prefs):
"""Save preferences to disk."""
self._prefs = prefs
await self._store.async_save(self._prefs)
for listener in self._listeners:
self._hass.async_create_task(async_create_catching_coro(listener(self))) | [
"async",
"def",
"_save_prefs",
"(",
"self",
",",
"prefs",
")",
":",
"self",
".",
"_prefs",
"=",
"prefs",
"await",
"self",
".",
"_store",
".",
"async_save",
"(",
"self",
".",
"_prefs",
")",
"for",
"listener",
"in",
"self",
".",
"_listeners",
":",
"self"... | [
337,
4
] | [
343,
84
] | python | en | ['en', 'en', 'en'] | True |
CloudPreferences._empty_config | (self, username) | Return an empty config. | Return an empty config. | def _empty_config(self, username):
"""Return an empty config."""
return {
PREF_ALEXA_DEFAULT_EXPOSE: DEFAULT_EXPOSED_DOMAINS,
PREF_ALEXA_ENTITY_CONFIGS: {},
PREF_CLOUD_USER: None,
PREF_CLOUDHOOKS: {},
PREF_ENABLE_ALEXA: True,
PREF_E... | [
"def",
"_empty_config",
"(",
"self",
",",
"username",
")",
":",
"return",
"{",
"PREF_ALEXA_DEFAULT_EXPOSE",
":",
"DEFAULT_EXPOSED_DOMAINS",
",",
"PREF_ALEXA_ENTITY_CONFIGS",
":",
"{",
"}",
",",
"PREF_CLOUD_USER",
":",
"None",
",",
"PREF_CLOUDHOOKS",
":",
"{",
"}",... | [
346,
4
] | [
361,
9
] | python | en | ['en', 'cy', 'en'] | True |
test_async_setup_entry | (hass) | Test a successful setup entry. | Test a successful setup entry. | async def test_async_setup_entry(hass):
"""Test a successful setup entry."""
await init_integration(hass)
state = hass.states.get("weather.home")
assert state is not None
assert state.state != STATE_UNAVAILABLE
assert state.state == "sunny" | [
"async",
"def",
"test_async_setup_entry",
"(",
"hass",
")",
":",
"await",
"init_integration",
"(",
"hass",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"weather.home\"",
")",
"assert",
"state",
"is",
"not",
"None",
"assert",
"state",
".",
"... | [
14,
0
] | [
21,
33
] | python | en | ['en', 'en', 'en'] | True |
test_config_not_ready | (hass) | Test for setup failure if connection to AccuWeather is missing. | Test for setup failure if connection to AccuWeather is missing. | async def test_config_not_ready(hass):
"""Test for setup failure if connection to AccuWeather is missing."""
entry = MockConfigEntry(
domain=DOMAIN,
title="Home",
unique_id="0123456",
data={
"api_key": "32-character-string-1234567890qw",
"latitude": 55.55,... | [
"async",
"def",
"test_config_not_ready",
"(",
"hass",
")",
":",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"title",
"=",
"\"Home\"",
",",
"unique_id",
"=",
"\"0123456\"",
",",
"data",
"=",
"{",
"\"api_key\"",
":",
"\"32-character-strin... | [
24,
0
] | [
44,
53
] | python | en | ['en', 'en', 'en'] | True |
test_unload_entry | (hass) | Test successful unload of entry. | Test successful unload of entry. | async def test_unload_entry(hass):
"""Test successful unload of entry."""
entry = await init_integration(hass)
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
assert entry.state == ENTRY_STATE_LOADED
assert await hass.config_entries.async_unload(entry.entry_id)
await hass.async_bloc... | [
"async",
"def",
"test_unload_entry",
"(",
"hass",
")",
":",
"entry",
"=",
"await",
"init_integration",
"(",
"hass",
")",
"assert",
"len",
"(",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"DOMAIN",
")",
")",
"==",
"1",
"assert",
"entry",
".",
... | [
47,
0
] | [
58,
36
] | python | en | ['en', 'en', 'en'] | True |
sample_logits | (embedding, bias, labels, inputs, sampler) |
embedding: an nn.Embedding layer
bias: [n_vocab]
labels: [b1, b2]
inputs: [b1, b2, n_emb]
sampler: you may use a LogUniformSampler
Return
logits: [b1, b2, 1 + n_sample]
|
embedding: an nn.Embedding layer
bias: [n_vocab]
labels: [b1, b2]
inputs: [b1, b2, n_emb]
sampler: you may use a LogUniformSampler
Return
logits: [b1, b2, 1 + n_sample]
| def sample_logits(embedding, bias, labels, inputs, sampler):
"""
embedding: an nn.Embedding layer
bias: [n_vocab]
labels: [b1, b2]
inputs: [b1, b2, n_emb]
sampler: you may use a LogUniformSampler
Return
logits: [b1, b2, 1 + n_sample]
"""
true_log_probs, sa... | [
"def",
"sample_logits",
"(",
"embedding",
",",
"bias",
",",
"labels",
",",
"inputs",
",",
"sampler",
")",
":",
"true_log_probs",
",",
"samp_log_probs",
",",
"neg_samples",
"=",
"sampler",
".",
"sample",
"(",
"labels",
")",
"n_sample",
"=",
"neg_samples",
"."... | [
301,
0
] | [
332,
17
] | python | en | ['en', 'error', 'th'] | False |
ProjectedAdaptiveLogSoftmax.forward | (self, hidden, target=None, keep_order=False) |
Params:
hidden :: [len*bsz x d_proj]
target :: [len*bsz]
Return:
if target is None:
out :: [len*bsz] Negative log likelihood
else:
out :: [len*bsz x n_tokens] log probabilities of tokens over... |
Params:
hidden :: [len*bsz x d_proj]
target :: [len*bsz]
Return:
if target is None:
out :: [len*bsz] Negative log likelihood
else:
out :: [len*bsz x n_tokens] log probabilities of tokens over... | def forward(self, hidden, target=None, keep_order=False):
'''
Params:
hidden :: [len*bsz x d_proj]
target :: [len*bsz]
Return:
if target is None:
out :: [len*bsz] Negative log likelihood
else:
... | [
"def",
"forward",
"(",
"self",
",",
"hidden",
",",
"target",
"=",
"None",
",",
"keep_order",
"=",
"False",
")",
":",
"if",
"target",
"is",
"not",
"None",
":",
"target",
"=",
"target",
".",
"view",
"(",
"-",
"1",
")",
"if",
"hidden",
".",
"size",
... | [
91,
4
] | [
194,
18
] | python | en | ['en', 'error', 'th'] | False |
ProjectedAdaptiveLogSoftmax.log_prob | (self, hidden) | r""" Computes log probabilities for all :math:`n\_classes`
From: https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/adaptive.py
Args:
hidden (Tensor): a minibatch of examples
Returns:
log-probabilities of for each class :math:`c`
in range :math:`0... | r""" Computes log probabilities for all :math:`n\_classes`
From: https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/adaptive.py
Args:
hidden (Tensor): a minibatch of examples
Returns:
log-probabilities of for each class :math:`c`
in range :math:`0... | def log_prob(self, hidden):
r""" Computes log probabilities for all :math:`n\_classes`
From: https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/adaptive.py
Args:
hidden (Tensor): a minibatch of examples
Returns:
log-probabilities of for each class :ma... | [
"def",
"log_prob",
"(",
"self",
",",
"hidden",
")",
":",
"if",
"self",
".",
"n_clusters",
"==",
"0",
":",
"logit",
"=",
"self",
".",
"_compute_logit",
"(",
"hidden",
",",
"self",
".",
"out_layers",
"[",
"0",
"]",
".",
"weight",
",",
"self",
".",
"o... | [
197,
4
] | [
256,
22
] | python | en | ['en', 'en', 'en'] | True |
LogUniformSampler.__init__ | (self, range_max, n_sample) |
Reference : https://github.com/tensorflow/tensorflow/blob/r1.10/tensorflow/python/ops/candidate_sampling_ops.py
`P(class) = (log(class + 2) - log(class + 1)) / log(range_max + 1)`
expected count can be approximated by 1 - (1 - p)^n
and we use a numerically stable version -expm1(num... |
Reference : https://github.com/tensorflow/tensorflow/blob/r1.10/tensorflow/python/ops/candidate_sampling_ops.py
`P(class) = (log(class + 2) - log(class + 1)) / log(range_max + 1)` | def __init__(self, range_max, n_sample):
"""
Reference : https://github.com/tensorflow/tensorflow/blob/r1.10/tensorflow/python/ops/candidate_sampling_ops.py
`P(class) = (log(class + 2) - log(class + 1)) / log(range_max + 1)`
expected count can be approximated by 1 - (1 - p)^n
... | [
"def",
"__init__",
"(",
"self",
",",
"range_max",
",",
"n_sample",
")",
":",
"with",
"torch",
".",
"no_grad",
"(",
")",
":",
"self",
".",
"range_max",
"=",
"range_max",
"log_indices",
"=",
"torch",
".",
"arange",
"(",
"1.",
",",
"range_max",
"+",
"2.",... | [
260,
4
] | [
278,
32
] | python | en | ['en', 'error', 'th'] | False |
LogUniformSampler.sample | (self, labels) |
labels: [b1, b2]
Return
true_log_probs: [b1, b2]
samp_log_probs: [n_sample]
neg_samples: [n_sample]
|
labels: [b1, b2]
Return
true_log_probs: [b1, b2]
samp_log_probs: [n_sample]
neg_samples: [n_sample]
| def sample(self, labels):
"""
labels: [b1, b2]
Return
true_log_probs: [b1, b2]
samp_log_probs: [n_sample]
neg_samples: [n_sample]
"""
# neg_samples = torch.empty(0).long()
n_sample = self.n_sample
n_tries = 2 * n_sample
... | [
"def",
"sample",
"(",
"self",
",",
"labels",
")",
":",
"# neg_samples = torch.empty(0).long()",
"n_sample",
"=",
"self",
".",
"n_sample",
"n_tries",
"=",
"2",
"*",
"n_sample",
"with",
"torch",
".",
"no_grad",
"(",
")",
":",
"neg_samples",
"=",
"torch",
".",
... | [
280,
4
] | [
299,
62
] | python | en | ['en', 'error', 'th'] | False |
FlaxAutoModel.from_config | (cls, config) | r"""
Instantiates one of the base model classes of the library from a configuration.
Args:
config (:class:`~transformers.PretrainedConfig`):
The model class to instantiate is selected based on the configuration class:
- isInstance of `roberta` configuration ... | r"""
Instantiates one of the base model classes of the library from a configuration. | def from_config(cls, config):
r"""
Instantiates one of the base model classes of the library from a configuration.
Args:
config (:class:`~transformers.PretrainedConfig`):
The model class to instantiate is selected based on the configuration class:
- ... | [
"def",
"from_config",
"(",
"cls",
",",
"config",
")",
":",
"for",
"config_class",
",",
"model_class",
"in",
"FLAX_MODEL_MAPPING",
".",
"items",
"(",
")",
":",
"if",
"isinstance",
"(",
"config",
",",
"config_class",
")",
":",
"return",
"model_class",
"(",
"... | [
54,
4
] | [
79,
9
] | python | cy | ['en', 'cy', 'hi'] | False |
FlaxAutoModel.from_pretrained | (cls, pretrained_model_name_or_path, *model_args, **kwargs) | r"""
Instantiates one of the base model classes of the library from a pre-trained model configuration.
The `from_pretrained()` method takes care of returning the correct model class instance based on the
`model_type` property of the config object, or when it's missing, falling back to using pat... | r"""
Instantiates one of the base model classes of the library from a pre-trained model configuration. | def from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs):
r"""
Instantiates one of the base model classes of the library from a pre-trained model configuration.
The `from_pretrained()` method takes care of returning the correct model class instance based on the
`mo... | [
"def",
"from_pretrained",
"(",
"cls",
",",
"pretrained_model_name_or_path",
",",
"*",
"model_args",
",",
"*",
"*",
"kwargs",
")",
":",
"config",
"=",
"kwargs",
".",
"pop",
"(",
"\"config\"",
",",
"None",
")",
"if",
"not",
"isinstance",
"(",
"config",
",",
... | [
82,
4
] | [
165,
9
] | python | cy | ['en', 'cy', 'hi'] | False |
TestCommandSensorSensor.setUp | (self) | Set up things to be run when tests are started. | Set up things to be run when tests are started. | def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.addCleanup(self.hass.stop) | [
"def",
"setUp",
"(",
"self",
")",
":",
"self",
".",
"hass",
"=",
"get_test_home_assistant",
"(",
")",
"self",
".",
"addCleanup",
"(",
"self",
".",
"hass",
".",
"stop",
")"
] | [
13,
4
] | [
16,
39
] | python | en | ['en', 'en', 'en'] | True |
TestCommandSensorSensor.update_side_effect | (self, data) | Side effect function for mocking CommandSensorData.update(). | Side effect function for mocking CommandSensorData.update(). | def update_side_effect(self, data):
"""Side effect function for mocking CommandSensorData.update()."""
self.commandline.data = data | [
"def",
"update_side_effect",
"(",
"self",
",",
"data",
")",
":",
"self",
".",
"commandline",
".",
"data",
"=",
"data"
] | [
18,
4
] | [
20,
36
] | python | en | ['en', 'da', 'en'] | True |
TestCommandSensorSensor.test_setup | (self) | Test sensor setup. | Test sensor setup. | def test_setup(self):
"""Test sensor setup."""
config = {
"name": "Test",
"unit_of_measurement": "in",
"command": "echo 5",
"command_timeout": 15,
}
devices = []
def add_dev_callback(devs, update):
"""Add callback to ad... | [
"def",
"test_setup",
"(",
"self",
")",
":",
"config",
"=",
"{",
"\"name\"",
":",
"\"Test\"",
",",
"\"unit_of_measurement\"",
":",
"\"in\"",
",",
"\"command\"",
":",
"\"echo 5\"",
",",
"\"command_timeout\"",
":",
"15",
",",
"}",
"devices",
"=",
"[",
"]",
"d... | [
22,
4
] | [
44,
34
] | python | en | ['en', 'bs', 'en'] | True |
TestCommandSensorSensor.test_template | (self) | Test command sensor with template. | Test command sensor with template. | def test_template(self):
"""Test command sensor with template."""
data = command_line.CommandSensorData(self.hass, "echo 50", 15)
entity = command_line.CommandSensor(
self.hass,
data,
"test",
"in",
Template("{{ value | multiply(0.1) }}... | [
"def",
"test_template",
"(",
"self",
")",
":",
"data",
"=",
"command_line",
".",
"CommandSensorData",
"(",
"self",
".",
"hass",
",",
"\"echo 50\"",
",",
"15",
")",
"entity",
"=",
"command_line",
".",
"CommandSensor",
"(",
"self",
".",
"hass",
",",
"data",
... | [
46,
4
] | [
60,
39
] | python | en | ['en', 'en', 'en'] | True |
TestCommandSensorSensor.test_template_render | (self) | Ensure command with templates get rendered properly. | Ensure command with templates get rendered properly. | def test_template_render(self):
"""Ensure command with templates get rendered properly."""
self.hass.states.set("sensor.test_state", "Works")
data = command_line.CommandSensorData(
self.hass, "echo {{ states.sensor.test_state.state }}", 15
)
data.update()
ass... | [
"def",
"test_template_render",
"(",
"self",
")",
":",
"self",
".",
"hass",
".",
"states",
".",
"set",
"(",
"\"sensor.test_state\"",
",",
"\"Works\"",
")",
"data",
"=",
"command_line",
".",
"CommandSensorData",
"(",
"self",
".",
"hass",
",",
"\"echo {{ states.s... | [
62,
4
] | [
70,
36
] | python | en | ['en', 'en', 'en'] | True |
TestCommandSensorSensor.test_template_render_with_quote | (self) | Ensure command with templates and quotes get rendered properly. | Ensure command with templates and quotes get rendered properly. | def test_template_render_with_quote(self):
"""Ensure command with templates and quotes get rendered properly."""
self.hass.states.set("sensor.test_state", "Works 2")
with patch(
"homeassistant.components.command_line.subprocess.check_output",
return_value=b"Works\n",
... | [
"def",
"test_template_render_with_quote",
"(",
"self",
")",
":",
"self",
".",
"hass",
".",
"states",
".",
"set",
"(",
"\"sensor.test_state\"",
",",
"\"Works 2\"",
")",
"with",
"patch",
"(",
"\"homeassistant.components.command_line.subprocess.check_output\"",
",",
"retur... | [
72,
4
] | [
89,
9
] | python | en | ['en', 'en', 'en'] | True |
TestCommandSensorSensor.test_bad_command | (self) | Test bad command. | Test bad command. | def test_bad_command(self):
"""Test bad command."""
data = command_line.CommandSensorData(self.hass, "asdfasdf", 15)
data.update()
assert data.value is None | [
"def",
"test_bad_command",
"(",
"self",
")",
":",
"data",
"=",
"command_line",
".",
"CommandSensorData",
"(",
"self",
".",
"hass",
",",
"\"asdfasdf\"",
",",
"15",
")",
"data",
".",
"update",
"(",
")",
"assert",
"data",
".",
"value",
"is",
"None"
] | [
91,
4
] | [
96,
33
] | python | en | ['en', 'bg', 'en'] | True |
TestCommandSensorSensor.test_update_with_json_attrs | (self) | Test attributes get extracted from a JSON result. | Test attributes get extracted from a JSON result. | def test_update_with_json_attrs(self):
"""Test attributes get extracted from a JSON result."""
data = command_line.CommandSensorData(
self.hass,
(
'echo { \\"key\\": \\"some_json_value\\", \\"another_key\\":\
\\"another_json_value\\", \\"key_three\\":... | [
"def",
"test_update_with_json_attrs",
"(",
"self",
")",
":",
"data",
"=",
"command_line",
".",
"CommandSensorData",
"(",
"self",
".",
"hass",
",",
"(",
"'echo { \\\\\"key\\\\\": \\\\\"some_json_value\\\\\", \\\\\"another_key\\\\\":\\\n \\\\\"another_json_value\\\\\", \\... | [
98,
4
] | [
117,
80
] | python | en | ['en', 'en', 'en'] | True |
TestCommandSensorSensor.test_update_with_json_attrs_no_data | (self, mock_logger) | Test attributes when no JSON result fetched. | Test attributes when no JSON result fetched. | def test_update_with_json_attrs_no_data(self, mock_logger):
"""Test attributes when no JSON result fetched."""
data = command_line.CommandSensorData(self.hass, "echo ", 15)
self.sensor = command_line.CommandSensor(
self.hass, data, "test", None, None, ["key"]
)
self.s... | [
"def",
"test_update_with_json_attrs_no_data",
"(",
"self",
",",
"mock_logger",
")",
":",
"data",
"=",
"command_line",
".",
"CommandSensorData",
"(",
"self",
".",
"hass",
",",
"\"echo \"",
",",
"15",
")",
"self",
".",
"sensor",
"=",
"command_line",
".",
"Comman... | [
120,
4
] | [
128,
41
] | python | en | ['en', 'en', 'en'] | True |
TestCommandSensorSensor.test_update_with_json_attrs_not_dict | (self, mock_logger) | Test attributes get extracted from a JSON result. | Test attributes get extracted from a JSON result. | def test_update_with_json_attrs_not_dict(self, mock_logger):
"""Test attributes get extracted from a JSON result."""
data = command_line.CommandSensorData(self.hass, "echo [1, 2, 3]", 15)
self.sensor = command_line.CommandSensor(
self.hass, data, "test", None, None, ["key"]
)... | [
"def",
"test_update_with_json_attrs_not_dict",
"(",
"self",
",",
"mock_logger",
")",
":",
"data",
"=",
"command_line",
".",
"CommandSensorData",
"(",
"self",
".",
"hass",
",",
"\"echo [1, 2, 3]\"",
",",
"15",
")",
"self",
".",
"sensor",
"=",
"command_line",
".",... | [
131,
4
] | [
139,
41
] | python | en | ['en', 'en', 'en'] | True |
TestCommandSensorSensor.test_update_with_json_attrs_bad_JSON | (self, mock_logger) | Test attributes get extracted from a JSON result. | Test attributes get extracted from a JSON result. | def test_update_with_json_attrs_bad_JSON(self, mock_logger):
"""Test attributes get extracted from a JSON result."""
data = command_line.CommandSensorData(
self.hass, "echo This is text rather than JSON data.", 15
)
self.sensor = command_line.CommandSensor(
self.h... | [
"def",
"test_update_with_json_attrs_bad_JSON",
"(",
"self",
",",
"mock_logger",
")",
":",
"data",
"=",
"command_line",
".",
"CommandSensorData",
"(",
"self",
".",
"hass",
",",
"\"echo This is text rather than JSON data.\"",
",",
"15",
")",
"self",
".",
"sensor",
"="... | [
142,
4
] | [
152,
41
] | python | en | ['en', 'en', 'en'] | True |
TestCommandSensorSensor.test_update_with_missing_json_attrs | (self) | Test attributes get extracted from a JSON result. | Test attributes get extracted from a JSON result. | def test_update_with_missing_json_attrs(self):
"""Test attributes get extracted from a JSON result."""
data = command_line.CommandSensorData(
self.hass,
(
'echo { \\"key\\": \\"some_json_value\\", \\"another_key\\":\
\\"another_json_value\\", \\"key_t... | [
"def",
"test_update_with_missing_json_attrs",
"(",
"self",
")",
":",
"data",
"=",
"command_line",
".",
"CommandSensorData",
"(",
"self",
".",
"hass",
",",
"(",
"'echo { \\\\\"key\\\\\": \\\\\"some_json_value\\\\\", \\\\\"another_key\\\\\":\\\n \\\\\"another_json_value\\... | [
154,
4
] | [
179,
71
] | python | en | ['en', 'en', 'en'] | True |
TestCommandSensorSensor.test_update_with_unnecessary_json_attrs | (self) | Test attributes get extracted from a JSON result. | Test attributes get extracted from a JSON result. | def test_update_with_unnecessary_json_attrs(self):
"""Test attributes get extracted from a JSON result."""
data = command_line.CommandSensorData(
self.hass,
(
'echo { \\"key\\": \\"some_json_value\\", \\"another_key\\":\
\\"another_json_value\\", \\"k... | [
"def",
"test_update_with_unnecessary_json_attrs",
"(",
"self",
")",
":",
"data",
"=",
"command_line",
".",
"CommandSensorData",
"(",
"self",
".",
"hass",
",",
"(",
"'echo { \\\\\"key\\\\\": \\\\\"some_json_value\\\\\", \\\\\"another_key\\\\\":\\\n \\\\\"another_json_val... | [
181,
4
] | [
200,
69
] | python | en | ['en', 'en', 'en'] | True |
mock_controller_assert | () | Mock the velbus controller with an assert. | Mock the velbus controller with an assert. | def mock_controller_assert():
"""Mock the velbus controller with an assert."""
with patch("velbus.Controller", side_effect=Exception()):
yield | [
"def",
"mock_controller_assert",
"(",
")",
":",
"with",
"patch",
"(",
"\"velbus.Controller\"",
",",
"side_effect",
"=",
"Exception",
"(",
")",
")",
":",
"yield"
] | [
15,
0
] | [
18,
13
] | python | en | ['en', 'en', 'en'] | True |
mock_controller | () | Mock a successful velbus controller. | Mock a successful velbus controller. | def mock_controller():
"""Mock a successful velbus controller."""
controller = Mock()
with patch("velbus.Controller", return_value=controller):
yield controller | [
"def",
"mock_controller",
"(",
")",
":",
"controller",
"=",
"Mock",
"(",
")",
"with",
"patch",
"(",
"\"velbus.Controller\"",
",",
"return_value",
"=",
"controller",
")",
":",
"yield",
"controller"
] | [
22,
0
] | [
26,
24
] | python | cs | ['cs', 'ro', 'en'] | False |
init_config_flow | (hass) | Init a configuration flow. | Init a configuration flow. | def init_config_flow(hass):
"""Init a configuration flow."""
flow = config_flow.VelbusConfigFlow()
flow.hass = hass
return flow | [
"def",
"init_config_flow",
"(",
"hass",
")",
":",
"flow",
"=",
"config_flow",
".",
"VelbusConfigFlow",
"(",
")",
"flow",
".",
"hass",
"=",
"hass",
"return",
"flow"
] | [
29,
0
] | [
33,
15
] | python | en | ['es', 'fr', 'en'] | False |
test_user | (hass, controller) | Test user config. | Test user config. | async def test_user(hass, controller):
"""Test user config."""
flow = init_config_flow(hass)
result = await flow.async_step_user()
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "user"
result = await flow.async_step_user(
{CONF_NAME: "Velbus Test ... | [
"async",
"def",
"test_user",
"(",
"hass",
",",
"controller",
")",
":",
"flow",
"=",
"init_config_flow",
"(",
"hass",
")",
"result",
"=",
"await",
"flow",
".",
"async_step_user",
"(",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
"... | [
36,
0
] | [
56,
48
] | python | en | ['en', 'da', 'en'] | True |
test_user_fail | (hass, controller_assert) | Test user config. | Test user config. | async def test_user_fail(hass, controller_assert):
"""Test user config."""
flow = init_config_flow(hass)
result = await flow.async_step_user(
{CONF_NAME: "Velbus Test Serial", CONF_PORT: PORT_SERIAL}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["errors"] == ... | [
"async",
"def",
"test_user_fail",
"(",
"hass",
",",
"controller_assert",
")",
":",
"flow",
"=",
"init_config_flow",
"(",
"hass",
")",
"result",
"=",
"await",
"flow",
".",
"async_step_user",
"(",
"{",
"CONF_NAME",
":",
"\"Velbus Test Serial\"",
",",
"CONF_PORT",
... | [
59,
0
] | [
73,
60
] | python | en | ['en', 'da', 'en'] | True |
test_import | (hass, controller) | Test import step. | Test import step. | async def test_import(hass, controller):
"""Test import step."""
flow = init_config_flow(hass)
result = await flow.async_step_import({CONF_PORT: PORT_TCP})
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == "velbus_import" | [
"async",
"def",
"test_import",
"(",
"hass",
",",
"controller",
")",
":",
"flow",
"=",
"init_config_flow",
"(",
"hass",
")",
"result",
"=",
"await",
"flow",
".",
"async_step_import",
"(",
"{",
"CONF_PORT",
":",
"PORT_TCP",
"}",
")",
"assert",
"result",
"[",... | [
76,
0
] | [
82,
45
] | python | de | ['de', 'sd', 'en'] | False |
test_abort_if_already_setup | (hass) | Test we abort if Daikin is already setup. | Test we abort if Daikin is already setup. | async def test_abort_if_already_setup(hass):
"""Test we abort if Daikin is already setup."""
flow = init_config_flow(hass)
MockConfigEntry(
domain="velbus", data={CONF_PORT: PORT_TCP, CONF_NAME: "velbus home"}
).add_to_hass(hass)
result = await flow.async_step_import(
{CONF_PORT: PO... | [
"async",
"def",
"test_abort_if_already_setup",
"(",
"hass",
")",
":",
"flow",
"=",
"init_config_flow",
"(",
"hass",
")",
"MockConfigEntry",
"(",
"domain",
"=",
"\"velbus\"",
",",
"data",
"=",
"{",
"CONF_PORT",
":",
"PORT_TCP",
",",
"CONF_NAME",
":",
"\"velbus ... | [
85,
0
] | [
102,
61
] | python | en | ['en', 'de', 'en'] | True |
get_scanner | (hass, config) | Validate the configuration and return a Nmap scanner. | Validate the configuration and return a Nmap scanner. | def get_scanner(hass, config):
"""Validate the configuration and return a Nmap scanner."""
return NmapDeviceScanner(config[DOMAIN]) | [
"def",
"get_scanner",
"(",
"hass",
",",
"config",
")",
":",
"return",
"NmapDeviceScanner",
"(",
"config",
"[",
"DOMAIN",
"]",
")"
] | [
37,
0
] | [
39,
44
] | python | en | ['en', 'en', 'en'] | True |
NmapDeviceScanner.__init__ | (self, config) | Initialize the scanner. | Initialize the scanner. | def __init__(self, config):
"""Initialize the scanner."""
self.last_results = []
self.hosts = config[CONF_HOSTS]
self.exclude = config[CONF_EXCLUDE]
minutes = config[CONF_HOME_INTERVAL]
self._options = config[CONF_OPTIONS]
self.home_interval = timedelta(minutes=m... | [
"def",
"__init__",
"(",
"self",
",",
"config",
")",
":",
"self",
".",
"last_results",
"=",
"[",
"]",
"self",
".",
"hosts",
"=",
"config",
"[",
"CONF_HOSTS",
"]",
"self",
".",
"exclude",
"=",
"config",
"[",
"CONF_EXCLUDE",
"]",
"minutes",
"=",
"config",... | [
50,
4
] | [
60,
44
] | python | en | ['en', 'en', 'en'] | True |
NmapDeviceScanner.scan_devices | (self) | Scan for new devices and return a list with found device IDs. | Scan for new devices and return a list with found device IDs. | def scan_devices(self):
"""Scan for new devices and return a list with found device IDs."""
self._update_info()
_LOGGER.debug("Nmap last results %s", self.last_results)
return [device.mac for device in self.last_results] | [
"def",
"scan_devices",
"(",
"self",
")",
":",
"self",
".",
"_update_info",
"(",
")",
"_LOGGER",
".",
"debug",
"(",
"\"Nmap last results %s\"",
",",
"self",
".",
"last_results",
")",
"return",
"[",
"device",
".",
"mac",
"for",
"device",
"in",
"self",
".",
... | [
62,
4
] | [
68,
59
] | python | en | ['en', 'en', 'en'] | True |
NmapDeviceScanner.get_device_name | (self, device) | Return the name of the given device or None if we don't know. | Return the name of the given device or None if we don't know. | def get_device_name(self, device):
"""Return the name of the given device or None if we don't know."""
filter_named = [
result.name for result in self.last_results if result.mac == device
]
if filter_named:
return filter_named[0]
return None | [
"def",
"get_device_name",
"(",
"self",
",",
"device",
")",
":",
"filter_named",
"=",
"[",
"result",
".",
"name",
"for",
"result",
"in",
"self",
".",
"last_results",
"if",
"result",
".",
"mac",
"==",
"device",
"]",
"if",
"filter_named",
":",
"return",
"fi... | [
70,
4
] | [
78,
19
] | python | en | ['en', 'en', 'en'] | True |
NmapDeviceScanner.get_extra_attributes | (self, device) | Return the IP of the given device. | Return the IP of the given device. | def get_extra_attributes(self, device):
"""Return the IP of the given device."""
filter_ip = next(
(result.ip for result in self.last_results if result.mac == device), None
)
return {"ip": filter_ip} | [
"def",
"get_extra_attributes",
"(",
"self",
",",
"device",
")",
":",
"filter_ip",
"=",
"next",
"(",
"(",
"result",
".",
"ip",
"for",
"result",
"in",
"self",
".",
"last_results",
"if",
"result",
".",
"mac",
"==",
"device",
")",
",",
"None",
")",
"return... | [
80,
4
] | [
85,
32
] | python | en | ['en', 'en', 'en'] | True |
NmapDeviceScanner._update_info | (self) | Scan the network for devices.
Returns boolean if scanning successful.
| Scan the network for devices. | def _update_info(self):
"""Scan the network for devices.
Returns boolean if scanning successful.
"""
_LOGGER.debug("Scanning...")
scanner = PortScanner()
options = self._options
if self.home_interval:
boundary = dt_util.now() - self.home_interval
... | [
"def",
"_update_info",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Scanning...\"",
")",
"scanner",
"=",
"PortScanner",
"(",
")",
"options",
"=",
"self",
".",
"_options",
"if",
"self",
".",
"home_interval",
":",
"boundary",
"=",
"dt_util",
".",
... | [
87,
4
] | [
133,
19
] | python | en | ['en', 'en', 'en'] | True |
async_setup | (hass, config) | Set up the iFrame frontend panels. | Set up the iFrame frontend panels. | async def async_setup(hass, config):
"""Set up the iFrame frontend panels."""
for url_path, info in config[DOMAIN].items():
hass.components.frontend.async_register_built_in_panel(
"iframe",
info.get(CONF_TITLE),
info.get(CONF_ICON),
url_path,
{... | [
"async",
"def",
"async_setup",
"(",
"hass",
",",
"config",
")",
":",
"for",
"url_path",
",",
"info",
"in",
"config",
"[",
"DOMAIN",
"]",
".",
"items",
"(",
")",
":",
"hass",
".",
"components",
".",
"frontend",
".",
"async_register_built_in_panel",
"(",
"... | [
37,
0
] | [
49,
15
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up Tasmota switch dynamically through discovery. | Set up Tasmota switch dynamically through discovery. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up Tasmota switch dynamically through discovery."""
@callback
def async_discover(tasmota_entity, discovery_hash):
"""Discover and add a Tasmota switch."""
async_add_entities(
[
TasmotaSwi... | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"@",
"callback",
"def",
"async_discover",
"(",
"tasmota_entity",
",",
"discovery_hash",
")",
":",
"\"\"\"Discover and add a Tasmota switch.\"\"\"",
"async_add_entit... | [
12,
0
] | [
32,
5
] | python | en | ['en', 'en', 'en'] | True |
TasmotaSwitch.__init__ | (self, **kwds) | Initialize the Tasmota switch. | Initialize the Tasmota switch. | def __init__(self, **kwds):
"""Initialize the Tasmota switch."""
self._state = False
super().__init__(
discovery_update=self.discovery_update,
**kwds,
) | [
"def",
"__init__",
"(",
"self",
",",
"*",
"*",
"kwds",
")",
":",
"self",
".",
"_state",
"=",
"False",
"super",
"(",
")",
".",
"__init__",
"(",
"discovery_update",
"=",
"self",
".",
"discovery_update",
",",
"*",
"*",
"kwds",
",",
")"
] | [
42,
4
] | [
49,
9
] | python | en | ['en', 'pl', 'en'] | True |
TasmotaSwitch.is_on | (self) | Return true if device is on. | Return true if device is on. | def is_on(self):
"""Return true if device is on."""
return self._state | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
52,
4
] | [
54,
26
] | python | en | ['en', 'fy', 'en'] | True |
TasmotaSwitch.async_turn_on | (self, **kwargs) | Turn the device on. | Turn the device on. | async def async_turn_on(self, **kwargs):
"""Turn the device on."""
self._tasmota_entity.set_state(True) | [
"async",
"def",
"async_turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_tasmota_entity",
".",
"set_state",
"(",
"True",
")"
] | [
56,
4
] | [
58,
44
] | python | en | ['en', 'en', 'en'] | True |
TasmotaSwitch.async_turn_off | (self, **kwargs) | Turn the device off. | Turn the device off. | async def async_turn_off(self, **kwargs):
"""Turn the device off."""
self._tasmota_entity.set_state(False) | [
"async",
"def",
"async_turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_tasmota_entity",
".",
"set_state",
"(",
"False",
")"
] | [
60,
4
] | [
62,
45
] | python | en | ['en', 'en', 'en'] | True |
RoombaVacuum.device_state_attributes | (self) | Return the state attributes of the device. | Return the state attributes of the device. | def device_state_attributes(self):
"""Return the state attributes of the device."""
state_attrs = super().device_state_attributes
# Get bin state
bin_raw_state = self.vacuum_state.get("bin", {})
bin_state = {}
if bin_raw_state.get("present") is not None:
bin_... | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"state_attrs",
"=",
"super",
"(",
")",
".",
"device_state_attributes",
"# Get bin state",
"bin_raw_state",
"=",
"self",
".",
"vacuum_state",
".",
"get",
"(",
"\"bin\"",
",",
"{",
"}",
")",
"bin_state",
"... | [
25,
4
] | [
38,
26
] | python | en | ['en', 'en', 'en'] | True |
RoombaVacuumCarpetBoost.supported_features | (self) | Flag vacuum cleaner robot features that are supported. | Flag vacuum cleaner robot features that are supported. | def supported_features(self):
"""Flag vacuum cleaner robot features that are supported."""
return SUPPORT_ROOMBA_CARPET_BOOST | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORT_ROOMBA_CARPET_BOOST"
] | [
45,
4
] | [
47,
42
] | python | en | ['en', 'en', 'en'] | True |
RoombaVacuumCarpetBoost.fan_speed | (self) | Return the fan speed of the vacuum cleaner. | Return the fan speed of the vacuum cleaner. | def fan_speed(self):
"""Return the fan speed of the vacuum cleaner."""
fan_speed = None
carpet_boost = self.vacuum_state.get("carpetBoost")
high_perf = self.vacuum_state.get("vacHigh")
if carpet_boost is not None and high_perf is not None:
if carpet_boost:
... | [
"def",
"fan_speed",
"(",
"self",
")",
":",
"fan_speed",
"=",
"None",
"carpet_boost",
"=",
"self",
".",
"vacuum_state",
".",
"get",
"(",
"\"carpetBoost\"",
")",
"high_perf",
"=",
"self",
".",
"vacuum_state",
".",
"get",
"(",
"\"vacHigh\"",
")",
"if",
"carpe... | [
50,
4
] | [
62,
24
] | python | en | ['en', 'en', 'en'] | True |
RoombaVacuumCarpetBoost.fan_speed_list | (self) | Get the list of available fan speed steps of the vacuum cleaner. | Get the list of available fan speed steps of the vacuum cleaner. | def fan_speed_list(self):
"""Get the list of available fan speed steps of the vacuum cleaner."""
return FAN_SPEEDS | [
"def",
"fan_speed_list",
"(",
"self",
")",
":",
"return",
"FAN_SPEEDS"
] | [
65,
4
] | [
67,
25
] | python | en | ['en', 'en', 'en'] | True |
RoombaVacuumCarpetBoost.async_set_fan_speed | (self, fan_speed, **kwargs) | Set fan speed. | Set fan speed. | async def async_set_fan_speed(self, fan_speed, **kwargs):
"""Set fan speed."""
if fan_speed.capitalize() in FAN_SPEEDS:
fan_speed = fan_speed.capitalize()
_LOGGER.debug("Set fan speed to: %s", fan_speed)
high_perf = None
carpet_boost = None
if fan_speed == FAN... | [
"async",
"def",
"async_set_fan_speed",
"(",
"self",
",",
"fan_speed",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"fan_speed",
".",
"capitalize",
"(",
")",
"in",
"FAN_SPEEDS",
":",
"fan_speed",
"=",
"fan_speed",
".",
"capitalize",
"(",
")",
"_LOGGER",
".",
... | [
69,
4
] | [
94,
9
] | python | fy | ['sv', 'fy', 'ur'] | False |
test_reload | (hass) | Verify we can reload filter sensors. | Verify we can reload filter sensors. | async def test_reload(hass):
"""Verify we can reload filter sensors."""
await hass.async_add_executor_job(
init_recorder_component, hass
) # force in memory db
hass.states.async_set("sensor.test_monitored", 12345)
await async_setup_component(
hass,
"sensor",
{
... | [
"async",
"def",
"test_reload",
"(",
"hass",
")",
":",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"init_recorder_component",
",",
"hass",
")",
"# force in memory db",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"sensor.test_monitored\"",
",",
"12345",
... | [
315,
0
] | [
363,
64
] | python | en | ['en', 'da', 'en'] | True |
TestFilterSensor.setup_method | (self, method) | Set up things to be run when tests are started. | Set up things to be run when tests are started. | def setup_method(self, method):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.hass.config.components.add("history")
raw_values = [20, 19, 18, 21, 22, 0]
self.values = []
timestamp = dt_util.utcnow()
for val in ra... | [
"def",
"setup_method",
"(",
"self",
",",
"method",
")",
":",
"self",
".",
"hass",
"=",
"get_test_home_assistant",
"(",
")",
"self",
".",
"hass",
".",
"config",
".",
"components",
".",
"add",
"(",
"\"history\"",
")",
"raw_values",
"=",
"[",
"20",
",",
"... | [
31,
4
] | [
43,
45
] | python | en | ['en', 'en', 'en'] | True |
TestFilterSensor.teardown_method | (self, method) | Stop everything that was started. | Stop everything that was started. | def teardown_method(self, method):
"""Stop everything that was started."""
self.hass.stop() | [
"def",
"teardown_method",
"(",
"self",
",",
"method",
")",
":",
"self",
".",
"hass",
".",
"stop",
"(",
")"
] | [
45,
4
] | [
47,
24
] | python | en | ['en', 'en', 'en'] | True |
TestFilterSensor.init_recorder | (self) | Initialize the recorder. | Initialize the recorder. | def init_recorder(self):
"""Initialize the recorder."""
init_recorder_component(self.hass)
self.hass.start() | [
"def",
"init_recorder",
"(",
"self",
")",
":",
"init_recorder_component",
"(",
"self",
".",
"hass",
")",
"self",
".",
"hass",
".",
"start",
"(",
")"
] | [
49,
4
] | [
52,
25
] | python | en | ['en', 'en', 'en'] | True |
TestFilterSensor.test_setup_fail | (self) | Test if filter doesn't exist. | Test if filter doesn't exist. | def test_setup_fail(self):
"""Test if filter doesn't exist."""
config = {
"sensor": {
"platform": "filter",
"entity_id": "sensor.test_monitored",
"filters": [{"filter": "nonexisting"}],
}
}
with assert_setup_componen... | [
"def",
"test_setup_fail",
"(",
"self",
")",
":",
"config",
"=",
"{",
"\"sensor\"",
":",
"{",
"\"platform\"",
":",
"\"filter\"",
",",
"\"entity_id\"",
":",
"\"sensor.test_monitored\"",
",",
"\"filters\"",
":",
"[",
"{",
"\"filter\"",
":",
"\"nonexisting\"",
"}",
... | [
54,
4
] | [
65,
39
] | python | en | ['de', 'en', 'en'] | True |
TestFilterSensor.test_chain | (self) | Test if filter chaining works. | Test if filter chaining works. | def test_chain(self):
"""Test if filter chaining works."""
config = {
"sensor": {
"platform": "filter",
"name": "test",
"entity_id": "sensor.test_monitored",
"filters": [
{"filter": "outlier", "window_size": ... | [
"def",
"test_chain",
"(",
"self",
")",
":",
"config",
"=",
"{",
"\"sensor\"",
":",
"{",
"\"platform\"",
":",
"\"filter\"",
",",
"\"name\"",
":",
"\"test\"",
",",
"\"entity_id\"",
":",
"\"sensor.test_monitored\"",
",",
"\"filters\"",
":",
"[",
"{",
"\"filter\""... | [
67,
4
] | [
91,
41
] | python | en | ['nl', 'en', 'en'] | True |
TestFilterSensor.test_chain_history | (self, missing=False) | Test if filter chaining works. | Test if filter chaining works. | def test_chain_history(self, missing=False):
"""Test if filter chaining works."""
self.init_recorder()
config = {
"history": {},
"sensor": {
"platform": "filter",
"name": "test",
"entity_id": "sensor.test_monitored",
... | [
"def",
"test_chain_history",
"(",
"self",
",",
"missing",
"=",
"False",
")",
":",
"self",
".",
"init_recorder",
"(",
")",
"config",
"=",
"{",
"\"history\"",
":",
"{",
"}",
",",
"\"sensor\"",
":",
"{",
"\"platform\"",
":",
"\"filter\"",
",",
"\"name\"",
"... | [
93,
4
] | [
146,
49
] | python | en | ['nl', 'en', 'en'] | True |
TestFilterSensor.test_chain_history_missing | (self) | Test if filter chaining works when recorder is enabled but the source is not recorded. | Test if filter chaining works when recorder is enabled but the source is not recorded. | def test_chain_history_missing(self):
"""Test if filter chaining works when recorder is enabled but the source is not recorded."""
return self.test_chain_history(missing=True) | [
"def",
"test_chain_history_missing",
"(",
"self",
")",
":",
"return",
"self",
".",
"test_chain_history",
"(",
"missing",
"=",
"True",
")"
] | [
148,
4
] | [
150,
52
] | python | en | ['en', 'en', 'en'] | True |
TestFilterSensor.test_history_time | (self) | Test loading from history based on a time window. | Test loading from history based on a time window. | def test_history_time(self):
"""Test loading from history based on a time window."""
self.init_recorder()
config = {
"history": {},
"sensor": {
"platform": "filter",
"name": "test",
"entity_id": "sensor.test_monitored",
... | [
"def",
"test_history_time",
"(",
"self",
")",
":",
"self",
".",
"init_recorder",
"(",
")",
"config",
"=",
"{",
"\"history\"",
":",
"{",
"}",
",",
"\"sensor\"",
":",
"{",
"\"platform\"",
":",
"\"filter\"",
",",
"\"name\"",
":",
"\"test\"",
",",
"\"entity_id... | [
152,
4
] | [
189,
44
] | python | en | ['en', 'en', 'en'] | True |
TestFilterSensor.test_outlier | (self) | Test if outlier filter works. | Test if outlier filter works. | def test_outlier(self):
"""Test if outlier filter works."""
filt = OutlierFilter(window_size=3, precision=2, entity=None, radius=4.0)
for state in self.values:
filtered = filt.filter_state(state)
assert 21 == filtered.state | [
"def",
"test_outlier",
"(",
"self",
")",
":",
"filt",
"=",
"OutlierFilter",
"(",
"window_size",
"=",
"3",
",",
"precision",
"=",
"2",
",",
"entity",
"=",
"None",
",",
"radius",
"=",
"4.0",
")",
"for",
"state",
"in",
"self",
".",
"values",
":",
"filte... | [
191,
4
] | [
196,
35
] | python | en | ['en', 'en', 'en'] | True |
TestFilterSensor.test_outlier_step | (self) |
Test step-change handling in outlier.
Test if outlier filter handles long-running step-changes correctly.
It should converge to no longer filter once just over half the
window_size is occupied by the new post step-change values.
|
Test step-change handling in outlier. | def test_outlier_step(self):
"""
Test step-change handling in outlier.
Test if outlier filter handles long-running step-changes correctly.
It should converge to no longer filter once just over half the
window_size is occupied by the new post step-change values.
"""
... | [
"def",
"test_outlier_step",
"(",
"self",
")",
":",
"filt",
"=",
"OutlierFilter",
"(",
"window_size",
"=",
"3",
",",
"precision",
"=",
"2",
",",
"entity",
"=",
"None",
",",
"radius",
"=",
"1.1",
")",
"self",
".",
"values",
"[",
"-",
"1",
"]",
".",
"... | [
198,
4
] | [
210,
35
] | python | en | ['en', 'error', 'th'] | False |
TestFilterSensor.test_initial_outlier | (self) | Test issue #13363. | Test issue #13363. | def test_initial_outlier(self):
"""Test issue #13363."""
filt = OutlierFilter(window_size=3, precision=2, entity=None, radius=4.0)
out = ha.State("sensor.test_monitored", 4000)
for state in [out] + self.values:
filtered = filt.filter_state(state)
assert 21 == filtered... | [
"def",
"test_initial_outlier",
"(",
"self",
")",
":",
"filt",
"=",
"OutlierFilter",
"(",
"window_size",
"=",
"3",
",",
"precision",
"=",
"2",
",",
"entity",
"=",
"None",
",",
"radius",
"=",
"4.0",
")",
"out",
"=",
"ha",
".",
"State",
"(",
"\"sensor.tes... | [
212,
4
] | [
218,
35
] | python | en | ['en', 'en', 'en'] | True |
TestFilterSensor.test_unknown_state_outlier | (self) | Test issue #32395. | Test issue #32395. | def test_unknown_state_outlier(self):
"""Test issue #32395."""
filt = OutlierFilter(window_size=3, precision=2, entity=None, radius=4.0)
out = ha.State("sensor.test_monitored", "unknown")
for state in [out] + self.values + [out]:
try:
filtered = filt.filter_st... | [
"def",
"test_unknown_state_outlier",
"(",
"self",
")",
":",
"filt",
"=",
"OutlierFilter",
"(",
"window_size",
"=",
"3",
",",
"precision",
"=",
"2",
",",
"entity",
"=",
"None",
",",
"radius",
"=",
"4.0",
")",
"out",
"=",
"ha",
".",
"State",
"(",
"\"sens... | [
220,
4
] | [
229,
35
] | python | en | ['en', 'en', 'en'] | True |
TestFilterSensor.test_precision_zero | (self) | Test if precision of zero returns an integer. | Test if precision of zero returns an integer. | def test_precision_zero(self):
"""Test if precision of zero returns an integer."""
filt = LowPassFilter(window_size=10, precision=0, entity=None, time_constant=10)
for state in self.values:
filtered = filt.filter_state(state)
assert isinstance(filtered.state, int) | [
"def",
"test_precision_zero",
"(",
"self",
")",
":",
"filt",
"=",
"LowPassFilter",
"(",
"window_size",
"=",
"10",
",",
"precision",
"=",
"0",
",",
"entity",
"=",
"None",
",",
"time_constant",
"=",
"10",
")",
"for",
"state",
"in",
"self",
".",
"values",
... | [
231,
4
] | [
236,
46
] | python | en | ['en', 'lb', 'en'] | True |
TestFilterSensor.test_lowpass | (self) | Test if lowpass filter works. | Test if lowpass filter works. | def test_lowpass(self):
"""Test if lowpass filter works."""
filt = LowPassFilter(window_size=10, precision=2, entity=None, time_constant=10)
out = ha.State("sensor.test_monitored", "unknown")
for state in [out] + self.values + [out]:
try:
filtered = filt.filte... | [
"def",
"test_lowpass",
"(",
"self",
")",
":",
"filt",
"=",
"LowPassFilter",
"(",
"window_size",
"=",
"10",
",",
"precision",
"=",
"2",
",",
"entity",
"=",
"None",
",",
"time_constant",
"=",
"10",
")",
"out",
"=",
"ha",
".",
"State",
"(",
"\"sensor.test... | [
238,
4
] | [
247,
38
] | python | en | ['nl', 'en', 'en'] | True |
TestFilterSensor.test_range | (self) | Test if range filter works. | Test if range filter works. | def test_range(self):
"""Test if range filter works."""
lower = 10
upper = 20
filt = RangeFilter(
entity=None, precision=2, lower_bound=lower, upper_bound=upper
)
for unf_state in self.values:
unf = float(unf_state.state)
filtered = fil... | [
"def",
"test_range",
"(",
"self",
")",
":",
"lower",
"=",
"10",
"upper",
"=",
"20",
"filt",
"=",
"RangeFilter",
"(",
"entity",
"=",
"None",
",",
"precision",
"=",
"2",
",",
"lower_bound",
"=",
"lower",
",",
"upper_bound",
"=",
"upper",
")",
"for",
"u... | [
249,
4
] | [
264,
44
] | python | da | ['nl', 'da', 'en'] | False |
TestFilterSensor.test_range_zero | (self) | Test if range filter works with zeroes as bounds. | Test if range filter works with zeroes as bounds. | def test_range_zero(self):
"""Test if range filter works with zeroes as bounds."""
lower = 0
upper = 0
filt = RangeFilter(
entity=None, precision=2, lower_bound=lower, upper_bound=upper
)
for unf_state in self.values:
unf = float(unf_state.state)
... | [
"def",
"test_range_zero",
"(",
"self",
")",
":",
"lower",
"=",
"0",
"upper",
"=",
"0",
"filt",
"=",
"RangeFilter",
"(",
"entity",
"=",
"None",
",",
"precision",
"=",
"2",
",",
"lower_bound",
"=",
"lower",
",",
"upper_bound",
"=",
"upper",
")",
"for",
... | [
266,
4
] | [
281,
44
] | python | en | ['en', 'en', 'en'] | True |
TestFilterSensor.test_throttle | (self) | Test if lowpass filter works. | Test if lowpass filter works. | def test_throttle(self):
"""Test if lowpass filter works."""
filt = ThrottleFilter(window_size=3, precision=2, entity=None)
filtered = []
for state in self.values:
new_state = filt.filter_state(state)
if not filt.skip_processing:
filtered.append(ne... | [
"def",
"test_throttle",
"(",
"self",
")",
":",
"filt",
"=",
"ThrottleFilter",
"(",
"window_size",
"=",
"3",
",",
"precision",
"=",
"2",
",",
"entity",
"=",
"None",
")",
"filtered",
"=",
"[",
"]",
"for",
"state",
"in",
"self",
".",
"values",
":",
"new... | [
283,
4
] | [
291,
54
] | python | en | ['nl', 'en', 'en'] | True |
TestFilterSensor.test_time_throttle | (self) | Test if lowpass filter works. | Test if lowpass filter works. | def test_time_throttle(self):
"""Test if lowpass filter works."""
filt = TimeThrottleFilter(
window_size=timedelta(minutes=2), precision=2, entity=None
)
filtered = []
for state in self.values:
new_state = filt.filter_state(state)
if not filt.s... | [
"def",
"test_time_throttle",
"(",
"self",
")",
":",
"filt",
"=",
"TimeThrottleFilter",
"(",
"window_size",
"=",
"timedelta",
"(",
"minutes",
"=",
"2",
")",
",",
"precision",
"=",
"2",
",",
"entity",
"=",
"None",
")",
"filtered",
"=",
"[",
"]",
"for",
"... | [
293,
4
] | [
303,
58
] | python | en | ['nl', 'en', 'en'] | True |
TestFilterSensor.test_time_sma | (self) | Test if time_sma filter works. | Test if time_sma filter works. | def test_time_sma(self):
"""Test if time_sma filter works."""
filt = TimeSMAFilter(
window_size=timedelta(minutes=2), precision=2, entity=None, type="last"
)
for state in self.values:
filtered = filt.filter_state(state)
assert 21.5 == filtered.state | [
"def",
"test_time_sma",
"(",
"self",
")",
":",
"filt",
"=",
"TimeSMAFilter",
"(",
"window_size",
"=",
"timedelta",
"(",
"minutes",
"=",
"2",
")",
",",
"precision",
"=",
"2",
",",
"entity",
"=",
"None",
",",
"type",
"=",
"\"last\"",
")",
"for",
"state",... | [
305,
4
] | [
312,
37
] | python | en | ['en', 'en', 'en'] | True |
dedup | (lst) | Preservers order | Preservers order | def dedup(lst):
"""Preservers order"""
new_lst = []
for item in lst:
if not item:
continue
elif item in new_lst:
continue
else:
new_lst.append(item)
return new_lst | [
"def",
"dedup",
"(",
"lst",
")",
":",
"new_lst",
"=",
"[",
"]",
"for",
"item",
"in",
"lst",
":",
"if",
"not",
"item",
":",
"continue",
"elif",
"item",
"in",
"new_lst",
":",
"continue",
"else",
":",
"new_lst",
".",
"append",
"(",
"item",
")",
"retur... | [
1246,
0
] | [
1256,
18
] | python | en | ['en', 'af', 'en'] | False |
TatoebaConverter.resolve_lang_code | (self, r) | R is a row in ported | R is a row in ported | def resolve_lang_code(self, r) -> Tuple[List[str], str, str]:
"""R is a row in ported"""
short_pair = r.short_pair
src, tgt = short_pair.split("-")
src_tags, src_multilingual = self.get_tags(src, r.src_name)
assert isinstance(src_tags, list)
tgt_tags, tgt_multilingual = s... | [
"def",
"resolve_lang_code",
"(",
"self",
",",
"r",
")",
"->",
"Tuple",
"[",
"List",
"[",
"str",
"]",
",",
"str",
",",
"str",
"]",
":",
"short_pair",
"=",
"r",
".",
"short_pair",
"src",
",",
"tgt",
"=",
"short_pair",
".",
"split",
"(",
"\"-\"",
")",... | [
149,
4
] | [
158,
77
] | python | en | ['en', 'en', 'en'] | True |
TatoebaConverter.write_model_card | (
self,
hf_model_id: str,
repo_root=DEFAULT_REPO,
dry_run=False,
) |
Copy the most recent model's readme section from opus, and add metadata. upload command: aws s3 sync
model_card_dir s3://models.huggingface.co/bert/Helsinki-NLP/ --dryrun
|
Copy the most recent model's readme section from opus, and add metadata. upload command: aws s3 sync
model_card_dir s3://models.huggingface.co/bert/Helsinki-NLP/ --dryrun
| def write_model_card(
self,
hf_model_id: str,
repo_root=DEFAULT_REPO,
dry_run=False,
) -> str:
"""
Copy the most recent model's readme section from opus, and add metadata. upload command: aws s3 sync
model_card_dir s3://models.huggingface.co/bert/Helsinki-NLP/... | [
"def",
"write_model_card",
"(",
"self",
",",
"hf_model_id",
":",
"str",
",",
"repo_root",
"=",
"DEFAULT_REPO",
",",
"dry_run",
"=",
"False",
",",
")",
"->",
"str",
":",
"short_pair",
"=",
"remove_prefix",
"(",
"hf_model_id",
",",
"\"opus-mt-\"",
")",
"extra_... | [
160,
4
] | [
233,
32
] | python | en | ['en', 'error', 'th'] | False |
async_setup | (hass: HomeAssistant, config: dict) | Set up the NEW_NAME integration. | Set up the NEW_NAME integration. | async def async_setup(hass: HomeAssistant, config: dict):
"""Set up the NEW_NAME integration."""
return True | [
"async",
"def",
"async_setup",
"(",
"hass",
":",
"HomeAssistant",
",",
"config",
":",
"dict",
")",
":",
"return",
"True"
] | [
10,
0
] | [
12,
15
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up Z-Wave Cover from Config Entry. | Set up Z-Wave Cover from Config Entry. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up Z-Wave Cover from Config Entry."""
@callback
def async_add_cover(values):
"""Add Z-Wave Cover."""
if values.primary.command_class == CommandClass.BARRIER_OPERATOR:
cover = ZwaveGarageDoorBarrier(value... | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"@",
"callback",
"def",
"async_add_cover",
"(",
"values",
")",
":",
"\"\"\"Add Z-Wave Cover.\"\"\"",
"if",
"values",
".",
"primary",
".",
"command_class",
"... | [
23,
0
] | [
38,
5
] | python | en | ['en', 'en', 'en'] | True |
percent_to_zwave_position | (value) | Convert position in 0-100 scale to 0-99 scale.
`value` -- (int) Position byte value from 0-100.
| Convert position in 0-100 scale to 0-99 scale. | def percent_to_zwave_position(value):
"""Convert position in 0-100 scale to 0-99 scale.
`value` -- (int) Position byte value from 0-100.
"""
if value > 0:
return max(1, round((value / 100) * 99))
return 0 | [
"def",
"percent_to_zwave_position",
"(",
"value",
")",
":",
"if",
"value",
">",
"0",
":",
"return",
"max",
"(",
"1",
",",
"round",
"(",
"(",
"value",
"/",
"100",
")",
"*",
"99",
")",
")",
"return",
"0"
] | [
41,
0
] | [
48,
12
] | python | en | ['en', 'en', 'en'] | True |
ZWaveCoverEntity.supported_features | (self) | Flag supported features. | Flag supported features. | def supported_features(self):
"""Flag supported features."""
return SUPPORTED_FEATURES_POSITION | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORTED_FEATURES_POSITION"
] | [
55,
4
] | [
57,
42
] | python | en | ['da', 'en', 'en'] | True |
ZWaveCoverEntity.is_closed | (self) | Return true if cover is closed. | Return true if cover is closed. | def is_closed(self):
"""Return true if cover is closed."""
return self.values.primary.value == 0 | [
"def",
"is_closed",
"(",
"self",
")",
":",
"return",
"self",
".",
"values",
".",
"primary",
".",
"value",
"==",
"0"
] | [
60,
4
] | [
62,
45
] | python | en | ['en', 'en', 'en'] | True |
ZWaveCoverEntity.current_cover_position | (self) | Return the current position of cover where 0 means closed and 100 is fully open. | Return the current position of cover where 0 means closed and 100 is fully open. | def current_cover_position(self):
"""Return the current position of cover where 0 means closed and 100 is fully open."""
return round((self.values.primary.value / 99) * 100) | [
"def",
"current_cover_position",
"(",
"self",
")",
":",
"return",
"round",
"(",
"(",
"self",
".",
"values",
".",
"primary",
".",
"value",
"/",
"99",
")",
"*",
"100",
")"
] | [
65,
4
] | [
67,
60
] | python | en | ['en', 'en', 'en'] | True |
ZWaveCoverEntity.async_set_cover_position | (self, **kwargs) | Move the cover to a specific position. | Move the cover to a specific position. | async def async_set_cover_position(self, **kwargs):
"""Move the cover to a specific position."""
self.values.primary.send_value(percent_to_zwave_position(kwargs[ATTR_POSITION])) | [
"async",
"def",
"async_set_cover_position",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"values",
".",
"primary",
".",
"send_value",
"(",
"percent_to_zwave_position",
"(",
"kwargs",
"[",
"ATTR_POSITION",
"]",
")",
")"
] | [
69,
4
] | [
71,
88
] | python | en | ['en', 'en', 'en'] | True |
ZWaveCoverEntity.async_open_cover | (self, **kwargs) | Open the cover. | Open the cover. | async def async_open_cover(self, **kwargs):
"""Open the cover."""
self.values.primary.send_value(99) | [
"async",
"def",
"async_open_cover",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"values",
".",
"primary",
".",
"send_value",
"(",
"99",
")"
] | [
73,
4
] | [
75,
42
] | python | en | ['en', 'en', 'en'] | True |
ZWaveCoverEntity.async_close_cover | (self, **kwargs) | Close cover. | Close cover. | async def async_close_cover(self, **kwargs):
"""Close cover."""
self.values.primary.send_value(0) | [
"async",
"def",
"async_close_cover",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"values",
".",
"primary",
".",
"send_value",
"(",
"0",
")"
] | [
77,
4
] | [
79,
41
] | python | en | ['en', 'la', 'en'] | False |
ZwaveGarageDoorBarrier.supported_features | (self) | Flag supported features. | Flag supported features. | def supported_features(self):
"""Flag supported features."""
return SUPPORT_GARAGE | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORT_GARAGE"
] | [
86,
4
] | [
88,
29
] | python | en | ['da', 'en', 'en'] | True |
ZwaveGarageDoorBarrier.device_class | (self) | Return the class of this device, from component DEVICE_CLASSES. | Return the class of this device, from component DEVICE_CLASSES. | def device_class(self):
"""Return the class of this device, from component DEVICE_CLASSES."""
return DEVICE_CLASS_GARAGE | [
"def",
"device_class",
"(",
"self",
")",
":",
"return",
"DEVICE_CLASS_GARAGE"
] | [
91,
4
] | [
93,
34
] | python | en | ['en', 'en', 'en'] | True |
ZwaveGarageDoorBarrier.is_opening | (self) | Return true if cover is in an opening state. | Return true if cover is in an opening state. | def is_opening(self):
"""Return true if cover is in an opening state."""
return self.values.primary.value[VALUE_SELECTED_ID] == 3 | [
"def",
"is_opening",
"(",
"self",
")",
":",
"return",
"self",
".",
"values",
".",
"primary",
".",
"value",
"[",
"VALUE_SELECTED_ID",
"]",
"==",
"3"
] | [
96,
4
] | [
98,
64
] | python | en | ['en', 'en', 'en'] | True |
ZwaveGarageDoorBarrier.is_closing | (self) | Return true if cover is in a closing state. | Return true if cover is in a closing state. | def is_closing(self):
"""Return true if cover is in a closing state."""
return self.values.primary.value[VALUE_SELECTED_ID] == 1 | [
"def",
"is_closing",
"(",
"self",
")",
":",
"return",
"self",
".",
"values",
".",
"primary",
".",
"value",
"[",
"VALUE_SELECTED_ID",
"]",
"==",
"1"
] | [
101,
4
] | [
103,
64
] | python | en | ['en', 'en', 'en'] | True |
ZwaveGarageDoorBarrier.is_closed | (self) | Return the current position of Zwave garage door. | Return the current position of Zwave garage door. | def is_closed(self):
"""Return the current position of Zwave garage door."""
return self.values.primary.value[VALUE_SELECTED_ID] == 0 | [
"def",
"is_closed",
"(",
"self",
")",
":",
"return",
"self",
".",
"values",
".",
"primary",
".",
"value",
"[",
"VALUE_SELECTED_ID",
"]",
"==",
"0"
] | [
106,
4
] | [
108,
64
] | python | en | ['en', 'nl', 'en'] | True |
ZwaveGarageDoorBarrier.async_close_cover | (self, **kwargs) | Close the garage door. | Close the garage door. | async def async_close_cover(self, **kwargs):
"""Close the garage door."""
self.values.primary.send_value(0) | [
"async",
"def",
"async_close_cover",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"values",
".",
"primary",
".",
"send_value",
"(",
"0",
")"
] | [
110,
4
] | [
112,
41
] | python | en | ['en', 'nl', 'en'] | True |
ZwaveGarageDoorBarrier.async_open_cover | (self, **kwargs) | Open the garage door. | Open the garage door. | async def async_open_cover(self, **kwargs):
"""Open the garage door."""
self.values.primary.send_value(4) | [
"async",
"def",
"async_open_cover",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"values",
".",
"primary",
".",
"send_value",
"(",
"4",
")"
] | [
114,
4
] | [
116,
41
] | python | en | ['en', 'nl', 'en'] | True |
_add_player | (hass, async_add_entities, host, port=None, name=None) | Add Bluesound players. | Add Bluesound players. | def _add_player(hass, async_add_entities, host, port=None, name=None):
"""Add Bluesound players."""
if host in [x.host for x in hass.data[DATA_BLUESOUND]]:
return
@callback
def _init_player(event=None):
"""Start polling."""
hass.async_create_task(player.async_init())
@callb... | [
"def",
"_add_player",
"(",
"hass",
",",
"async_add_entities",
",",
"host",
",",
"port",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"if",
"host",
"in",
"[",
"x",
".",
"host",
"for",
"x",
"in",
"hass",
".",
"data",
"[",
"DATA_BLUESOUND",
"]",
"... | [
106,
0
] | [
145,
75
] | python | en | ['en', 'ny', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up the Bluesound platforms. | Set up the Bluesound platforms. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Bluesound platforms."""
if DATA_BLUESOUND not in hass.data:
hass.data[DATA_BLUESOUND] = []
if discovery_info:
_add_player(
hass,
async_add_entities,
disco... | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"if",
"DATA_BLUESOUND",
"not",
"in",
"hass",
".",
"data",
":",
"hass",
".",
"data",
"[",
"DATA_BLUESOUND",
"]",
"=",
... | [
148,
0
] | [
199,
9
] | python | en | ['en', 'cs', 'en'] | True |
BluesoundPlayer.__init__ | (self, hass, host, port=None, name=None, init_callback=None) | Initialize the media player. | Initialize the media player. | def __init__(self, hass, host, port=None, name=None, init_callback=None):
"""Initialize the media player."""
self.host = host
self._hass = hass
self.port = port
self._polling_session = async_get_clientsession(hass)
self._polling_task = None # The actual polling task.
... | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"host",
",",
"port",
"=",
"None",
",",
"name",
"=",
"None",
",",
"init_callback",
"=",
"None",
")",
":",
"self",
".",
"host",
"=",
"host",
"self",
".",
"_hass",
"=",
"hass",
"self",
".",
"port",
"... | [
205,
4
] | [
231,
36
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer._try_get_index | (string, search_string) | Get the index. | Get the index. | def _try_get_index(string, search_string):
"""Get the index."""
try:
return string.index(search_string)
except ValueError:
return -1 | [
"def",
"_try_get_index",
"(",
"string",
",",
"search_string",
")",
":",
"try",
":",
"return",
"string",
".",
"index",
"(",
"search_string",
")",
"except",
"ValueError",
":",
"return",
"-",
"1"
] | [
237,
4
] | [
242,
21
] | python | en | ['en', 'nl', 'en'] | True |
BluesoundPlayer.force_update_sync_status | (self, on_updated_cb=None, raise_timeout=False) | Update the internal status. | Update the internal status. | async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False):
"""Update the internal status."""
resp = await self.send_bluesound_command(
"SyncStatus", raise_timeout, raise_timeout
)
if not resp:
return None
self._sync_status = resp["... | [
"async",
"def",
"force_update_sync_status",
"(",
"self",
",",
"on_updated_cb",
"=",
"None",
",",
"raise_timeout",
"=",
"False",
")",
":",
"resp",
"=",
"await",
"self",
".",
"send_bluesound_command",
"(",
"\"SyncStatus\"",
",",
"raise_timeout",
",",
"raise_timeout"... | [
244,
4
] | [
284,
19
] | python | en | ['en', 'sn', 'en'] | True |
BluesoundPlayer._start_poll_command | (self) | Loop which polls the status of the player. | Loop which polls the status of the player. | async def _start_poll_command(self):
"""Loop which polls the status of the player."""
try:
while True:
await self.async_update_status()
except (asyncio.TimeoutError, ClientError, BluesoundPlayer._TimeoutException):
_LOGGER.info("Node %s is offline, retryi... | [
"async",
"def",
"_start_poll_command",
"(",
"self",
")",
":",
"try",
":",
"while",
"True",
":",
"await",
"self",
".",
"async_update_status",
"(",
")",
"except",
"(",
"asyncio",
".",
"TimeoutError",
",",
"ClientError",
",",
"BluesoundPlayer",
".",
"_TimeoutExce... | [
286,
4
] | [
301,
17
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.start_polling | (self) | Start the polling task. | Start the polling task. | def start_polling(self):
"""Start the polling task."""
self._polling_task = self._hass.async_create_task(self._start_poll_command()) | [
"def",
"start_polling",
"(",
"self",
")",
":",
"self",
".",
"_polling_task",
"=",
"self",
".",
"_hass",
".",
"async_create_task",
"(",
"self",
".",
"_start_poll_command",
"(",
")",
")"
] | [
303,
4
] | [
305,
85
] | python | en | ['en', 'no', 'en'] | True |
BluesoundPlayer.stop_polling | (self) | Stop the polling task. | Stop the polling task. | def stop_polling(self):
"""Stop the polling task."""
self._polling_task.cancel() | [
"def",
"stop_polling",
"(",
"self",
")",
":",
"self",
".",
"_polling_task",
".",
"cancel",
"(",
")"
] | [
307,
4
] | [
309,
35
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.async_init | (self, triggered=None) | Initialize the player async. | Initialize the player async. | async def async_init(self, triggered=None):
"""Initialize the player async."""
try:
if self._retry_remove is not None:
self._retry_remove()
self._retry_remove = None
await self.force_update_sync_status(self._init_callback, True)
except (as... | [
"async",
"def",
"async_init",
"(",
"self",
",",
"triggered",
"=",
"None",
")",
":",
"try",
":",
"if",
"self",
".",
"_retry_remove",
"is",
"not",
"None",
":",
"self",
".",
"_retry_remove",
"(",
")",
"self",
".",
"_retry_remove",
"=",
"None",
"await",
"s... | [
311,
4
] | [
326,
17
] | 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.