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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
list_users | (hass, provider, args) | List the users. | List the users. | async def list_users(hass, provider, args):
"""List the users."""
count = 0
for user in provider.data.users:
count += 1
print(user["username"])
print()
print("Total users:", count) | [
"async",
"def",
"list_users",
"(",
"hass",
",",
"provider",
",",
"args",
")",
":",
"count",
"=",
"0",
"for",
"user",
"in",
"provider",
".",
"data",
".",
"users",
":",
"count",
"+=",
"1",
"print",
"(",
"user",
"[",
"\"username\"",
"]",
")",
"print",
... | [
65,
0
] | [
73,
32
] | python | en | ['en', 'en', 'en'] | True |
add_user | (hass, provider, args) | Create a user. | Create a user. | async def add_user(hass, provider, args):
"""Create a user."""
try:
provider.data.add_auth(args.username, args.password)
except hass_auth.InvalidUser:
print("Username already exists!")
return
# Save username/password
await provider.data.async_save()
print("Auth created") | [
"async",
"def",
"add_user",
"(",
"hass",
",",
"provider",
",",
"args",
")",
":",
"try",
":",
"provider",
".",
"data",
".",
"add_auth",
"(",
"args",
".",
"username",
",",
"args",
".",
"password",
")",
"except",
"hass_auth",
".",
"InvalidUser",
":",
"pri... | [
76,
0
] | [
86,
25
] | python | co | ['es', 'co', 'en'] | False |
validate_login | (hass, provider, args) | Validate a login. | Validate a login. | async def validate_login(hass, provider, args):
"""Validate a login."""
try:
provider.data.validate_login(args.username, args.password)
print("Auth valid")
except hass_auth.InvalidAuth:
print("Auth invalid") | [
"async",
"def",
"validate_login",
"(",
"hass",
",",
"provider",
",",
"args",
")",
":",
"try",
":",
"provider",
".",
"data",
".",
"validate_login",
"(",
"args",
".",
"username",
",",
"args",
".",
"password",
")",
"print",
"(",
"\"Auth valid\"",
")",
"exce... | [
89,
0
] | [
95,
29
] | python | co | ['es', 'co', 'en'] | False |
change_password | (hass, provider, args) | Change password. | Change password. | async def change_password(hass, provider, args):
"""Change password."""
try:
provider.data.change_password(args.username, args.new_password)
await provider.data.async_save()
print("Password changed")
except hass_auth.InvalidUser:
print("User not found") | [
"async",
"def",
"change_password",
"(",
"hass",
",",
"provider",
",",
"args",
")",
":",
"try",
":",
"provider",
".",
"data",
".",
"change_password",
"(",
"args",
".",
"username",
",",
"args",
".",
"new_password",
")",
"await",
"provider",
".",
"data",
".... | [
98,
0
] | [
105,
31
] | python | en | ['fr', 'sr', 'en'] | False |
test_flow | (hass, first_con, second_con, exp_type, exp_result, exp_reason) | Run a flow with or without errors and return result. | Run a flow with or without errors and return result. | async def test_flow(hass, first_con, second_con, exp_type, exp_result, exp_reason):
"""Run a flow with or without errors and return result."""
host = "1.2.3.4"
with patch(
"homeassistant.components.dynalite.bridge.DynaliteDevices.async_setup",
side_effect=[first_con, second_con],
):
... | [
"async",
"def",
"test_flow",
"(",
"hass",
",",
"first_con",
",",
"second_con",
",",
"exp_type",
",",
"exp_result",
",",
"exp_reason",
")",
":",
"host",
"=",
"\"1.2.3.4\"",
"with",
"patch",
"(",
"\"homeassistant.components.dynalite.bridge.DynaliteDevices.async_setup\"",
... | [
19,
0
] | [
36,
45
] | python | en | ['en', 'en', 'en'] | True |
test_existing | (hass) | Test when the entry exists with the same config. | Test when the entry exists with the same config. | async def test_existing(hass):
"""Test when the entry exists with the same config."""
host = "1.2.3.4"
MockConfigEntry(
domain=dynalite.DOMAIN, data={dynalite.CONF_HOST: host}
).add_to_hass(hass)
with patch(
"homeassistant.components.dynalite.bridge.DynaliteDevices.async_setup",
... | [
"async",
"def",
"test_existing",
"(",
"hass",
")",
":",
"host",
"=",
"\"1.2.3.4\"",
"MockConfigEntry",
"(",
"domain",
"=",
"dynalite",
".",
"DOMAIN",
",",
"data",
"=",
"{",
"dynalite",
".",
"CONF_HOST",
":",
"host",
"}",
")",
".",
"add_to_hass",
"(",
"ha... | [
39,
0
] | [
55,
51
] | python | en | ['en', 'en', 'en'] | True |
test_existing_update | (hass) | Test when the entry exists with a different config. | Test when the entry exists with a different config. | async def test_existing_update(hass):
"""Test when the entry exists with a different config."""
host = "1.2.3.4"
port1 = 7777
port2 = 8888
entry = MockConfigEntry(
domain=dynalite.DOMAIN,
data={dynalite.CONF_HOST: host, dynalite.CONF_PORT: port1},
)
entry.add_to_hass(hass)
... | [
"async",
"def",
"test_existing_update",
"(",
"hass",
")",
":",
"host",
"=",
"\"1.2.3.4\"",
"port1",
"=",
"7777",
"port2",
"=",
"8888",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"dynalite",
".",
"DOMAIN",
",",
"data",
"=",
"{",
"dynalite",
".",
... | [
58,
0
] | [
85,
51
] | python | en | ['en', 'en', 'en'] | True |
test_two_entries | (hass) | Test when two different entries exist with different hosts. | Test when two different entries exist with different hosts. | async def test_two_entries(hass):
"""Test when two different entries exist with different hosts."""
host1 = "1.2.3.4"
host2 = "5.6.7.8"
MockConfigEntry(
domain=dynalite.DOMAIN, data={dynalite.CONF_HOST: host1}
).add_to_hass(hass)
with patch(
"homeassistant.components.dynalite.bri... | [
"async",
"def",
"test_two_entries",
"(",
"hass",
")",
":",
"host1",
"=",
"\"1.2.3.4\"",
"host2",
"=",
"\"5.6.7.8\"",
"MockConfigEntry",
"(",
"domain",
"=",
"dynalite",
".",
"DOMAIN",
",",
"data",
"=",
"{",
"dynalite",
".",
"CONF_HOST",
":",
"host1",
"}",
"... | [
88,
0
] | [
105,
45
] | python | en | ['en', 'en', 'en'] | True |
lookup_all | (
perm_lookup: PermissionLookup, lookup_dict: SubCategoryDict, object_id: str
) | Look up permission for all. | Look up permission for all. | def lookup_all(
perm_lookup: PermissionLookup, lookup_dict: SubCategoryDict, object_id: str
) -> ValueType:
"""Look up permission for all."""
# In case of ALL category, lookup_dict IS the schema.
return cast(ValueType, lookup_dict) | [
"def",
"lookup_all",
"(",
"perm_lookup",
":",
"PermissionLookup",
",",
"lookup_dict",
":",
"SubCategoryDict",
",",
"object_id",
":",
"str",
")",
"->",
"ValueType",
":",
"# In case of ALL category, lookup_dict IS the schema.",
"return",
"cast",
"(",
"ValueType",
",",
"... | [
12,
0
] | [
17,
39
] | python | en | ['en', 'en', 'en'] | True |
compile_policy | (
policy: CategoryType, subcategories: SubCatLookupType, perm_lookup: PermissionLookup
) | Compile policy into a function that tests policy.
Subcategories are mapping key -> lookup function, ordered by highest
priority first.
| Compile policy into a function that tests policy. | def compile_policy(
policy: CategoryType, subcategories: SubCatLookupType, perm_lookup: PermissionLookup
) -> Callable[[str, str], bool]:
"""Compile policy into a function that tests policy.
Subcategories are mapping key -> lookup function, ordered by highest
priority first.
"""
# None, False, ... | [
"def",
"compile_policy",
"(",
"policy",
":",
"CategoryType",
",",
"subcategories",
":",
"SubCatLookupType",
",",
"perm_lookup",
":",
"PermissionLookup",
")",
"->",
"Callable",
"[",
"[",
"str",
",",
"str",
"]",
",",
"bool",
"]",
":",
"# None, False, empty dict",
... | [
20,
0
] | [
77,
29
] | python | en | ['en', 'en', 'en'] | True |
_gen_dict_test_func | (
perm_lookup: PermissionLookup, lookup_func: LookupFunc, lookup_dict: SubCategoryDict
) | Generate a lookup function. | Generate a lookup function. | def _gen_dict_test_func(
perm_lookup: PermissionLookup, lookup_func: LookupFunc, lookup_dict: SubCategoryDict
) -> Callable[[str, str], Optional[bool]]:
"""Generate a lookup function."""
def test_value(object_id: str, key: str) -> Optional[bool]:
"""Test if permission is allowed based on the keys."... | [
"def",
"_gen_dict_test_func",
"(",
"perm_lookup",
":",
"PermissionLookup",
",",
"lookup_func",
":",
"LookupFunc",
",",
"lookup_dict",
":",
"SubCategoryDict",
")",
"->",
"Callable",
"[",
"[",
"str",
",",
"str",
"]",
",",
"Optional",
"[",
"bool",
"]",
"]",
":"... | [
80,
0
] | [
96,
21
] | python | en | ['es', 'en', 'en'] | True |
test_all | (policy: CategoryType, key: str) | Test if a policy has an ALL access for a specific key. | Test if a policy has an ALL access for a specific key. | def test_all(policy: CategoryType, key: str) -> bool:
"""Test if a policy has an ALL access for a specific key."""
if not isinstance(policy, dict):
return bool(policy)
all_policy = policy.get(SUBCAT_ALL)
if not isinstance(all_policy, dict):
return bool(all_policy)
return all_polic... | [
"def",
"test_all",
"(",
"policy",
":",
"CategoryType",
",",
"key",
":",
"str",
")",
"->",
"bool",
":",
"if",
"not",
"isinstance",
"(",
"policy",
",",
"dict",
")",
":",
"return",
"bool",
"(",
"policy",
")",
"all_policy",
"=",
"policy",
".",
"get",
"("... | [
99,
0
] | [
109,
37
] | python | en | ['en', 'en', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up the Statistics sensor. | Set up the Statistics sensor. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Statistics sensor."""
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)
entity_id = config.get(CONF_ENTITY_ID)
name = config.get(CONF_NAME)
sampling_size = config.get(CONF_SAMPLING_SIZE)
... | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"await",
"async_setup_reload_service",
"(",
"hass",
",",
"DOMAIN",
",",
"PLATFORMS",
")",
"entity_id",
"=",
"config",
"."... | [
69,
0
] | [
84,
15
] | python | en | ['en', 'ca', 'en'] | True |
StatisticsSensor.__init__ | (self, entity_id, name, sampling_size, max_age, precision) | Initialize the Statistics sensor. | Initialize the Statistics sensor. | def __init__(self, entity_id, name, sampling_size, max_age, precision):
"""Initialize the Statistics sensor."""
self._entity_id = entity_id
self.is_binary = self._entity_id.split(".")[0] == "binary_sensor"
self._name = name
self._sampling_size = sampling_size
self._max_ag... | [
"def",
"__init__",
"(",
"self",
",",
"entity_id",
",",
"name",
",",
"sampling_size",
",",
"max_age",
",",
"precision",
")",
":",
"self",
".",
"_entity_id",
"=",
"entity_id",
"self",
".",
"is_binary",
"=",
"self",
".",
"_entity_id",
".",
"split",
"(",
"\"... | [
90,
4
] | [
107,
36
] | python | en | ['en', 'bg', 'en'] | True |
StatisticsSensor.async_added_to_hass | (self) | Register callbacks. | Register callbacks. | async def async_added_to_hass(self):
"""Register callbacks."""
@callback
def async_stats_sensor_state_listener(event):
"""Handle the sensor state changes."""
new_state = event.data.get("new_state")
if new_state is None:
return
sel... | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"@",
"callback",
"def",
"async_stats_sensor_state_listener",
"(",
"event",
")",
":",
"\"\"\"Handle the sensor state changes.\"\"\"",
"new_state",
"=",
"event",
".",
"data",
".",
"get",
"(",
"\"new_state\"",... | [
109,
4
] | [
144,
9
] | python | en | ['en', 'no', 'en'] | False |
StatisticsSensor._add_state_to_queue | (self, new_state) | Add the state to the queue. | Add the state to the queue. | def _add_state_to_queue(self, new_state):
"""Add the state to the queue."""
if new_state.state in [STATE_UNKNOWN, STATE_UNAVAILABLE]:
return
try:
if self.is_binary:
self.states.append(new_state.state)
else:
self.states.append(f... | [
"def",
"_add_state_to_queue",
"(",
"self",
",",
"new_state",
")",
":",
"if",
"new_state",
".",
"state",
"in",
"[",
"STATE_UNKNOWN",
",",
"STATE_UNAVAILABLE",
"]",
":",
"return",
"try",
":",
"if",
"self",
".",
"is_binary",
":",
"self",
".",
"states",
".",
... | [
146,
4
] | [
163,
13
] | python | en | ['en', 'en', 'en'] | True |
StatisticsSensor.name | (self) | Return the name of the sensor. | Return the name of the sensor. | def name(self):
"""Return the name of the sensor."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
166,
4
] | [
168,
25
] | python | en | ['en', 'mi', 'en'] | True |
StatisticsSensor.state | (self) | Return the state of the sensor. | Return the state of the sensor. | def state(self):
"""Return the state of the sensor."""
return self.mean if not self.is_binary else self.count | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"mean",
"if",
"not",
"self",
".",
"is_binary",
"else",
"self",
".",
"count"
] | [
171,
4
] | [
173,
62
] | python | en | ['en', 'en', 'en'] | True |
StatisticsSensor.unit_of_measurement | (self) | Return the unit the value is expressed in. | Return the unit the value is expressed in. | def unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self._unit_of_measurement if not self.is_binary else None | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unit_of_measurement",
"if",
"not",
"self",
".",
"is_binary",
"else",
"None"
] | [
176,
4
] | [
178,
72
] | python | en | ['en', 'en', 'en'] | True |
StatisticsSensor.should_poll | (self) | No polling needed. | No polling needed. | def should_poll(self):
"""No polling needed."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
181,
4
] | [
183,
20
] | python | en | ['en', 'en', 'en'] | True |
StatisticsSensor.device_state_attributes | (self) | Return the state attributes of the sensor. | Return the state attributes of the sensor. | def device_state_attributes(self):
"""Return the state attributes of the sensor."""
if not self.is_binary:
return {
ATTR_SAMPLING_SIZE: self._sampling_size,
ATTR_COUNT: self.count,
ATTR_MEAN: self.mean,
ATTR_MEDIAN: self.median,... | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"is_binary",
":",
"return",
"{",
"ATTR_SAMPLING_SIZE",
":",
"self",
".",
"_sampling_size",
",",
"ATTR_COUNT",
":",
"self",
".",
"count",
",",
"ATTR_MEAN",
":",
"self",
".",
... | [
186,
4
] | [
204,
13
] | python | en | ['en', 'en', 'en'] | True |
StatisticsSensor.icon | (self) | Return the icon to use in the frontend, if any. | Return the icon to use in the frontend, if any. | def icon(self):
"""Return the icon to use in the frontend, if any."""
return ICON | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"ICON"
] | [
207,
4
] | [
209,
19
] | python | en | ['en', 'en', 'en'] | True |
StatisticsSensor._purge_old | (self) | Remove states which are older than self._max_age. | Remove states which are older than self._max_age. | def _purge_old(self):
"""Remove states which are older than self._max_age."""
now = dt_util.utcnow()
_LOGGER.debug(
"%s: purging records older then %s(%s)",
self.entity_id,
dt_util.as_local(now - self._max_age),
self._max_age,
)
w... | [
"def",
"_purge_old",
"(",
"self",
")",
":",
"now",
"=",
"dt_util",
".",
"utcnow",
"(",
")",
"_LOGGER",
".",
"debug",
"(",
"\"%s: purging records older then %s(%s)\"",
",",
"self",
".",
"entity_id",
",",
"dt_util",
".",
"as_local",
"(",
"now",
"-",
"self",
... | [
211,
4
] | [
230,
33
] | python | en | ['en', 'en', 'en'] | True |
StatisticsSensor._next_to_purge_timestamp | (self) | Find the timestamp when the next purge would occur. | Find the timestamp when the next purge would occur. | def _next_to_purge_timestamp(self):
"""Find the timestamp when the next purge would occur."""
if self.ages and self._max_age:
# Take the oldest entry from the ages list and add the configured max_age.
# If executed after purging old states, the result is the next timestamp
... | [
"def",
"_next_to_purge_timestamp",
"(",
"self",
")",
":",
"if",
"self",
".",
"ages",
"and",
"self",
".",
"_max_age",
":",
"# Take the oldest entry from the ages list and add the configured max_age.",
"# If executed after purging old states, the result is the next timestamp",
"# in ... | [
232,
4
] | [
239,
19
] | python | en | ['en', 'en', 'en'] | True |
StatisticsSensor.async_update | (self) | Get the latest data and updates the states. | Get the latest data and updates the states. | async def async_update(self):
"""Get the latest data and updates the states."""
_LOGGER.debug("%s: updating statistics", self.entity_id)
if self._max_age is not None:
self._purge_old()
self.count = len(self.states)
if not self.is_binary:
try: # require ... | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"%s: updating statistics\"",
",",
"self",
".",
"entity_id",
")",
"if",
"self",
".",
"_max_age",
"is",
"not",
"None",
":",
"self",
".",
"_purge_old",
"(",
")",
"self",
... | [
241,
4
] | [
312,
13
] | python | en | ['en', 'en', 'en'] | True |
StatisticsSensor._async_initialize_from_database | (self) | Initialize the list of states from the database.
The query will get the list of states in DESCENDING order so that we
can limit the result to self._sample_size. Afterwards reverse the
list so that we get it in the right order again.
If MaxAge is provided then query will restrict to ent... | Initialize the list of states from the database. | async def _async_initialize_from_database(self):
"""Initialize the list of states from the database.
The query will get the list of states in DESCENDING order so that we
can limit the result to self._sample_size. Afterwards reverse the
list so that we get it in the right order again.
... | [
"async",
"def",
"_async_initialize_from_database",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"%s: initializing values from the database\"",
",",
"self",
".",
"entity_id",
")",
"with",
"session_scope",
"(",
"hass",
"=",
"self",
".",
"hass",
")",
"as",
... | [
314,
4
] | [
353,
81
] | python | en | ['en', 'en', 'en'] | True |
process_story | (raw_story) | Extract the story and summary from a story file.
Arguments:
raw_story (str): content of the story file as an utf-8 encoded string.
Raises:
IndexError: If the story is empty or contains no highlights.
| Extract the story and summary from a story file. | def process_story(raw_story):
"""Extract the story and summary from a story file.
Arguments:
raw_story (str): content of the story file as an utf-8 encoded string.
Raises:
IndexError: If the story is empty or contains no highlights.
"""
nonempty_lines = list(filter(lambda x: len(x)... | [
"def",
"process_story",
"(",
"raw_story",
")",
":",
"nonempty_lines",
"=",
"list",
"(",
"filter",
"(",
"lambda",
"x",
":",
"len",
"(",
"x",
")",
"!=",
"0",
",",
"[",
"line",
".",
"strip",
"(",
")",
"for",
"line",
"in",
"raw_story",
".",
"split",
"(... | [
61,
0
] | [
92,
37
] | python | en | ['en', 'en', 'en'] | True |
truncate_or_pad | (sequence, block_size, pad_token_id) | Adapt the source and target sequences' lengths to the block size.
If the sequence is shorter we append padding token to the right of the sequence.
| Adapt the source and target sequences' lengths to the block size.
If the sequence is shorter we append padding token to the right of the sequence.
| def truncate_or_pad(sequence, block_size, pad_token_id):
"""Adapt the source and target sequences' lengths to the block size.
If the sequence is shorter we append padding token to the right of the sequence.
"""
if len(sequence) > block_size:
return sequence[:block_size]
else:
sequenc... | [
"def",
"truncate_or_pad",
"(",
"sequence",
",",
"block_size",
",",
"pad_token_id",
")",
":",
"if",
"len",
"(",
"sequence",
")",
">",
"block_size",
":",
"return",
"sequence",
"[",
":",
"block_size",
"]",
"else",
":",
"sequence",
".",
"extend",
"(",
"[",
"... | [
109,
0
] | [
117,
23
] | python | en | ['en', 'en', 'en'] | True |
build_mask | (sequence, pad_token_id) | Builds the mask. The attention mechanism will only attend to positions
with value 1. | Builds the mask. The attention mechanism will only attend to positions
with value 1. | def build_mask(sequence, pad_token_id):
"""Builds the mask. The attention mechanism will only attend to positions
with value 1."""
mask = torch.ones_like(sequence)
idx_pad_tokens = sequence == pad_token_id
mask[idx_pad_tokens] = 0
return mask | [
"def",
"build_mask",
"(",
"sequence",
",",
"pad_token_id",
")",
":",
"mask",
"=",
"torch",
".",
"ones_like",
"(",
"sequence",
")",
"idx_pad_tokens",
"=",
"sequence",
"==",
"pad_token_id",
"mask",
"[",
"idx_pad_tokens",
"]",
"=",
"0",
"return",
"mask"
] | [
120,
0
] | [
126,
15
] | python | en | ['en', 'en', 'en'] | True |
encode_for_summarization | (story_lines, summary_lines, tokenizer) | Encode the story and summary lines, and join them
as specified in [1] by using `[SEP] [CLS]` tokens to separate
sentences.
| Encode the story and summary lines, and join them
as specified in [1] by using `[SEP] [CLS]` tokens to separate
sentences.
| def encode_for_summarization(story_lines, summary_lines, tokenizer):
"""Encode the story and summary lines, and join them
as specified in [1] by using `[SEP] [CLS]` tokens to separate
sentences.
"""
story_lines_token_ids = [tokenizer.encode(line) for line in story_lines]
story_token_ids = [token... | [
"def",
"encode_for_summarization",
"(",
"story_lines",
",",
"summary_lines",
",",
"tokenizer",
")",
":",
"story_lines_token_ids",
"=",
"[",
"tokenizer",
".",
"encode",
"(",
"line",
")",
"for",
"line",
"in",
"story_lines",
"]",
"story_token_ids",
"=",
"[",
"token... | [
129,
0
] | [
139,
45
] | python | en | ['en', 'en', 'en'] | True |
compute_token_type_ids | (batch, separator_token_id) | Segment embeddings as described in [1]
The values {0,1} were found in the repository [2].
Attributes:
batch: torch.Tensor, size [batch_size, block_size]
Batch of input.
separator_token_id: int
The value of the token that separates the segments.
[1] Liu, Yang, and M... | Segment embeddings as described in [1] | def compute_token_type_ids(batch, separator_token_id):
"""Segment embeddings as described in [1]
The values {0,1} were found in the repository [2].
Attributes:
batch: torch.Tensor, size [batch_size, block_size]
Batch of input.
separator_token_id: int
The value of th... | [
"def",
"compute_token_type_ids",
"(",
"batch",
",",
"separator_token_id",
")",
":",
"batch_embeddings",
"=",
"[",
"]",
"for",
"sequence",
"in",
"batch",
":",
"sentence_num",
"=",
"-",
"1",
"embeddings",
"=",
"[",
"]",
"for",
"s",
"in",
"sequence",
":",
"if... | [
142,
0
] | [
166,
41
] | python | en | ['en', 'gl', 'en'] | True |
CNNDMDataset.__init__ | (self, path="", prefix="train") | We initialize the class by listing all the documents to summarize.
Files are not read in memory due to the size of some datasets (like CNN/DailyMail).
| We initialize the class by listing all the documents to summarize.
Files are not read in memory due to the size of some datasets (like CNN/DailyMail).
| def __init__(self, path="", prefix="train"):
"""We initialize the class by listing all the documents to summarize.
Files are not read in memory due to the size of some datasets (like CNN/DailyMail).
"""
assert os.path.isdir(path)
self.documents = []
story_filenames_list ... | [
"def",
"__init__",
"(",
"self",
",",
"path",
"=",
"\"\"",
",",
"prefix",
"=",
"\"train\"",
")",
":",
"assert",
"os",
".",
"path",
".",
"isdir",
"(",
"path",
")",
"self",
".",
"documents",
"=",
"[",
"]",
"story_filenames_list",
"=",
"os",
".",
"listdi... | [
32,
4
] | [
46,
48
] | python | en | ['en', 'en', 'en'] | True |
CNNDMDataset.__len__ | (self) | Returns the number of documents. | Returns the number of documents. | def __len__(self):
""" Returns the number of documents. """
return len(self.documents) | [
"def",
"__len__",
"(",
"self",
")",
":",
"return",
"len",
"(",
"self",
".",
"documents",
")"
] | [
48,
4
] | [
50,
34
] | python | en | ['en', 'en', 'en'] | True |
VMSchedulingAgent.choose_action | (self, decision_event: DecisionPayload, env: Env) | This method will determine whether to postpone the current VM or allocate a PM to the current VM.
| This method will determine whether to postpone the current VM or allocate a PM to the current VM.
| def choose_action(self, decision_event: DecisionPayload, env: Env) -> Action:
"""This method will determine whether to postpone the current VM or allocate a PM to the current VM.
"""
valid_pm_num: int = len(decision_event.valid_pms)
if valid_pm_num <= 0:
# No valid PM now, p... | [
"def",
"choose_action",
"(",
"self",
",",
"decision_event",
":",
"DecisionPayload",
",",
"env",
":",
"Env",
")",
"->",
"Action",
":",
"valid_pm_num",
":",
"int",
"=",
"len",
"(",
"decision_event",
".",
"valid_pms",
")",
"if",
"valid_pm_num",
"<=",
"0",
":"... | [
9,
4
] | [
23,
21
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up mobile app sensor from a config entry. | Set up mobile app sensor from a config entry. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up mobile app sensor from a config entry."""
entities = []
webhook_id = config_entry.data[CONF_WEBHOOK_ID]
for config in hass.data[DOMAIN][ENTITY_TYPE].values():
if config[CONF_WEBHOOK_ID] != webhook_id:
co... | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"entities",
"=",
"[",
"]",
"webhook_id",
"=",
"config_entry",
".",
"data",
"[",
"CONF_WEBHOOK_ID",
"]",
"for",
"config",
"in",
"hass",
".",
"data",
"[... | [
18,
0
] | [
56,
5
] | python | en | ['en', 'en', 'en'] | True |
MobileAppSensor.state | (self) | Return the state of the sensor. | Return the state of the sensor. | def state(self):
"""Return the state of the sensor."""
return self._config[ATTR_SENSOR_STATE] | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_config",
"[",
"ATTR_SENSOR_STATE",
"]"
] | [
63,
4
] | [
65,
46
] | python | en | ['en', 'en', 'en'] | True |
MobileAppSensor.unit_of_measurement | (self) | Return the unit of measurement this sensor expresses itself in. | Return the unit of measurement this sensor expresses itself in. | def unit_of_measurement(self):
"""Return the unit of measurement this sensor expresses itself in."""
return self._config.get(ATTR_SENSOR_UOM) | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"self",
".",
"_config",
".",
"get",
"(",
"ATTR_SENSOR_UOM",
")"
] | [
68,
4
] | [
70,
48
] | python | en | ['en', 'en', 'en'] | True |
TestEventBuffer.test_gen_event | (self) | Test event generating correct | Test event generating correct | def test_gen_event(self):
"""Test event generating correct"""
evt = self.eb.gen_atom_event(1, 1, (0, 0))
# fields should be same as specified
self.assertEqual(AtomEvent, type(evt))
self.assertEqual(evt.tick, 1)
self.assertEqual(evt.event_type, 1)
self.assertEqual... | [
"def",
"test_gen_event",
"(",
"self",
")",
":",
"evt",
"=",
"self",
".",
"eb",
".",
"gen_atom_event",
"(",
"1",
",",
"1",
",",
"(",
"0",
",",
"0",
")",
")",
"# fields should be same as specified",
"self",
".",
"assertEqual",
"(",
"AtomEvent",
",",
"type"... | [
12,
4
] | [
27,
48
] | python | en | ['nl', 'en', 'en'] | True |
TestEventBuffer.test_insert_event | (self) | Test insert event works as expected | Test insert event works as expected | def test_insert_event(self):
"""Test insert event works as expected"""
# pending pool should be empty at beginning
self.assertEqual(len(self.eb._pending_events), 0)
evt = self.eb.gen_atom_event(1, 1, 1)
self.eb.insert_event(evt)
# after insert one event, we should hav... | [
"def",
"test_insert_event",
"(",
"self",
")",
":",
"# pending pool should be empty at beginning",
"self",
".",
"assertEqual",
"(",
"len",
"(",
"self",
".",
"eb",
".",
"_pending_events",
")",
",",
"0",
")",
"evt",
"=",
"self",
".",
"eb",
".",
"gen_atom_event",
... | [
29,
4
] | [
40,
57
] | python | en | ['en', 'en', 'en'] | True |
TestEventBuffer.test_event_dispatch | (self) | Test event dispatching work as expected | Test event dispatching work as expected | def test_event_dispatch(self):
"""Test event dispatching work as expected"""
def cb(evt):
# test event tick
self.assertEqual(
1, evt.tick, msg="recieved event tick should be 1")
# test event payload
self.assertTupleEqual(
(... | [
"def",
"test_event_dispatch",
"(",
"self",
")",
":",
"def",
"cb",
"(",
"evt",
")",
":",
"# test event tick",
"self",
".",
"assertEqual",
"(",
"1",
",",
"evt",
".",
"tick",
",",
"msg",
"=",
"\"recieved event tick should be 1\"",
")",
"# test event payload",
"se... | [
42,
4
] | [
59,
26
] | python | en | ['en', 'en', 'en'] | True |
TestEventBuffer.test_get_finish_events | (self) | Test if we can get correct finished events | Test if we can get correct finished events | def test_get_finish_events(self):
"""Test if we can get correct finished events"""
# no finised at first
self.assertListEqual([], self.eb.get_finished_events(),
msg="finished pool should be empty")
evt = self.eb.gen_atom_event(1, 1, (1, 3))
self.eb... | [
"def",
"test_get_finish_events",
"(",
"self",
")",
":",
"# no finised at first",
"self",
".",
"assertListEqual",
"(",
"[",
"]",
",",
"self",
".",
"eb",
".",
"get_finished_events",
"(",
")",
",",
"msg",
"=",
"\"finished pool should be empty\"",
")",
"evt",
"=",
... | [
61,
4
] | [
76,
71
] | python | en | ['nl', 'en', 'en'] | True |
TestEventBuffer.test_get_pending_events | (self) | Test if we can get correct pending events | Test if we can get correct pending events | def test_get_pending_events(self):
"""Test if we can get correct pending events"""
# not pending at first
self.assertEqual(0, len(self.eb.get_pending_events(1)),
msg="pending pool should be empty")
evt = self.eb.gen_atom_event(1, 1, (1, 3))
self.eb.ins... | [
"def",
"test_get_pending_events",
"(",
"self",
")",
":",
"# not pending at first",
"self",
".",
"assertEqual",
"(",
"0",
",",
"len",
"(",
"self",
".",
"eb",
".",
"get_pending_events",
"(",
"1",
")",
")",
",",
"msg",
"=",
"\"pending pool should be empty\"",
")"... | [
78,
4
] | [
90,
70
] | python | en | ['nl', 'en', 'en'] | True |
TestEventBuffer.test_reset | (self) | Test reset, all internal states should be reset | Test reset, all internal states should be reset | def test_reset(self):
"""Test reset, all internal states should be reset"""
evt = self.eb.gen_atom_event(1, 1, 1)
self.eb.insert_event(evt)
self.eb.reset()
# reset will not clear the tick (key), just clear the pending pool
self.assertEqual(len(self.eb._pending_events),... | [
"def",
"test_reset",
"(",
"self",
")",
":",
"evt",
"=",
"self",
".",
"eb",
".",
"gen_atom_event",
"(",
"1",
",",
"1",
",",
"1",
")",
"self",
".",
"eb",
".",
"insert_event",
"(",
"evt",
")",
"self",
".",
"eb",
".",
"reset",
"(",
")",
"# reset will... | [
92,
4
] | [
106,
58
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Add switches for a config entry. | Add switches for a config entry. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Add switches for a config entry."""
broker = hass.data[DOMAIN][DATA_BROKERS][config_entry.entry_id]
async_add_entities([SmartThingsScene(scene) for scene in broker.scenes.values()]) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"broker",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"DATA_BROKERS",
"]",
"[",
"config_entry",
".",
"entry_id",
"]",
"async_add_entities",
"(",
... | [
8,
0
] | [
11,
85
] | python | en | ['en', 'en', 'en'] | True |
SmartThingsScene.__init__ | (self, scene) | Init the scene class. | Init the scene class. | def __init__(self, scene):
"""Init the scene class."""
self._scene = scene | [
"def",
"__init__",
"(",
"self",
",",
"scene",
")",
":",
"self",
".",
"_scene",
"=",
"scene"
] | [
17,
4
] | [
19,
27
] | python | en | ['en', 'it', 'en'] | True |
SmartThingsScene.async_activate | (self, **kwargs: Any) | Activate scene. | Activate scene. | async def async_activate(self, **kwargs: Any) -> None:
"""Activate scene."""
await self._scene.execute() | [
"async",
"def",
"async_activate",
"(",
"self",
",",
"*",
"*",
"kwargs",
":",
"Any",
")",
"->",
"None",
":",
"await",
"self",
".",
"_scene",
".",
"execute",
"(",
")"
] | [
21,
4
] | [
23,
35
] | python | en | ['it', 'la', 'en'] | False |
SmartThingsScene.device_state_attributes | (self) | Get attributes about the state. | Get attributes about the state. | def device_state_attributes(self):
"""Get attributes about the state."""
return {
"icon": self._scene.icon,
"color": self._scene.color,
"location_id": self._scene.location_id,
} | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"return",
"{",
"\"icon\"",
":",
"self",
".",
"_scene",
".",
"icon",
",",
"\"color\"",
":",
"self",
".",
"_scene",
".",
"color",
",",
"\"location_id\"",
":",
"self",
".",
"_scene",
".",
"location_id",... | [
26,
4
] | [
32,
9
] | python | en | ['en', 'en', 'en'] | True |
SmartThingsScene.name | (self) | Return the name of the device. | Return the name of the device. | def name(self) -> str:
"""Return the name of the device."""
return self._scene.name | [
"def",
"name",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_scene",
".",
"name"
] | [
35,
4
] | [
37,
31
] | python | en | ['en', 'en', 'en'] | True |
SmartThingsScene.unique_id | (self) | Return a unique ID. | Return a unique ID. | def unique_id(self) -> str:
"""Return a unique ID."""
return self._scene.scene_id | [
"def",
"unique_id",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_scene",
".",
"scene_id"
] | [
40,
4
] | [
42,
35
] | python | ca | ['fr', 'ca', 'en'] | False |
async_setup | (hass, config) | Activate Snips component. | Activate Snips component. | async def async_setup(hass, config):
"""Activate Snips component."""
@callback
def async_set_feedback(site_ids, state):
"""Set Feedback sound state."""
site_ids = site_ids if site_ids else config[DOMAIN].get(CONF_SITE_IDS)
topic = FEEDBACK_ON_TOPIC if state else FEEDBACK_OFF_TOPIC
... | [
"async",
"def",
"async_setup",
"(",
"hass",
",",
"config",
")",
":",
"@",
"callback",
"def",
"async_set_feedback",
"(",
"site_ids",
",",
"state",
")",
":",
"\"\"\"Set Feedback sound state.\"\"\"",
"site_ids",
"=",
"site_ids",
"if",
"site_ids",
"else",
"config",
... | [
89,
0
] | [
217,
15
] | python | en | ['de', 'en', 'en'] | True |
resolve_slot_values | (slot) | Convert snips builtin types to usable values. | Convert snips builtin types to usable values. | def resolve_slot_values(slot):
"""Convert snips builtin types to usable values."""
if "value" in slot["value"]:
value = slot["value"]["value"]
else:
value = slot["rawValue"]
if slot.get("entity") == "snips/duration":
delta = timedelta(
weeks=slot["value"]["weeks"],
... | [
"def",
"resolve_slot_values",
"(",
"slot",
")",
":",
"if",
"\"value\"",
"in",
"slot",
"[",
"\"value\"",
"]",
":",
"value",
"=",
"slot",
"[",
"\"value\"",
"]",
"[",
"\"value\"",
"]",
"else",
":",
"value",
"=",
"slot",
"[",
"\"rawValue\"",
"]",
"if",
"sl... | [
220,
0
] | [
237,
16
] | python | en | ['en', 'en', 'en'] | True |
get_service | (hass, config, discovery_info=None) | Get the Discord notification service. | Get the Discord notification service. | def get_service(hass, config, discovery_info=None):
"""Get the Discord notification service."""
token = config[CONF_TOKEN]
return DiscordNotificationService(hass, token) | [
"def",
"get_service",
"(",
"hass",
",",
"config",
",",
"discovery_info",
"=",
"None",
")",
":",
"token",
"=",
"config",
"[",
"CONF_TOKEN",
"]",
"return",
"DiscordNotificationService",
"(",
"hass",
",",
"token",
")"
] | [
23,
0
] | [
26,
50
] | python | en | ['en', 'en', 'en'] | True |
DiscordNotificationService.__init__ | (self, hass, token) | Initialize the service. | Initialize the service. | def __init__(self, hass, token):
"""Initialize the service."""
self.token = token
self.hass = hass | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"token",
")",
":",
"self",
".",
"token",
"=",
"token",
"self",
".",
"hass",
"=",
"hass"
] | [
32,
4
] | [
35,
24
] | python | en | ['en', 'en', 'en'] | True |
DiscordNotificationService.file_exists | (self, filename) | Check if a file exists on disk and is in authorized path. | Check if a file exists on disk and is in authorized path. | def file_exists(self, filename):
"""Check if a file exists on disk and is in authorized path."""
if not self.hass.config.is_allowed_path(filename):
return False
return os.path.isfile(filename) | [
"def",
"file_exists",
"(",
"self",
",",
"filename",
")",
":",
"if",
"not",
"self",
".",
"hass",
".",
"config",
".",
"is_allowed_path",
"(",
"filename",
")",
":",
"return",
"False",
"return",
"os",
".",
"path",
".",
"isfile",
"(",
"filename",
")"
] | [
37,
4
] | [
41,
39
] | python | en | ['en', 'en', 'en'] | True |
DiscordNotificationService.async_send_message | (self, message, **kwargs) | Login to Discord, send message to channel(s) and log out. | Login to Discord, send message to channel(s) and log out. | async def async_send_message(self, message, **kwargs):
"""Login to Discord, send message to channel(s) and log out."""
discord.VoiceClient.warn_nacl = False
discord_bot = discord.Client()
images = None
if ATTR_TARGET not in kwargs:
_LOGGER.error("No target specified... | [
"async",
"def",
"async_send_message",
"(",
"self",
",",
"message",
",",
"*",
"*",
"kwargs",
")",
":",
"discord",
".",
"VoiceClient",
".",
"warn_nacl",
"=",
"False",
"discord_bot",
"=",
"discord",
".",
"Client",
"(",
")",
"images",
"=",
"None",
"if",
"ATT... | [
43,
4
] | [
95,
60
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the QNAP NAS sensor. | Set up the QNAP NAS sensor. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the QNAP NAS sensor."""
api = QNAPStatsAPI(config)
api.update()
# QNAP is not available
if not api.data:
raise PlatformNotReady
sensors = []
# Basic sensors
for variable in config[CONF_MONITORED_CON... | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"api",
"=",
"QNAPStatsAPI",
"(",
"config",
")",
"api",
".",
"update",
"(",
")",
"# QNAP is not available",
"if",
"not",
"api",
".",
"dat... | [
114,
0
] | [
158,
25
] | python | en | ['en', 'ca', 'en'] | True |
round_nicely | (number) | Round a number based on its size (so it looks nice). | Round a number based on its size (so it looks nice). | def round_nicely(number):
"""Round a number based on its size (so it looks nice)."""
if number < 10:
return round(number, 2)
if number < 100:
return round(number, 1)
return round(number) | [
"def",
"round_nicely",
"(",
"number",
")",
":",
"if",
"number",
"<",
"10",
":",
"return",
"round",
"(",
"number",
",",
"2",
")",
"if",
"number",
"<",
"100",
":",
"return",
"round",
"(",
"number",
",",
"1",
")",
"return",
"round",
"(",
"number",
")"... | [
161,
0
] | [
168,
24
] | python | en | ['en', 'en', 'en'] | True |
QNAPStatsAPI.__init__ | (self, config) | Initialize the API wrapper. | Initialize the API wrapper. | def __init__(self, config):
"""Initialize the API wrapper."""
protocol = "https" if config[CONF_SSL] else "http"
self._api = QNAPStats(
f"{protocol}://{config.get(CONF_HOST)}",
config.get(CONF_PORT),
config.get(CONF_USERNAME),
config.get(CONF_PASS... | [
"def",
"__init__",
"(",
"self",
",",
"config",
")",
":",
"protocol",
"=",
"\"https\"",
"if",
"config",
"[",
"CONF_SSL",
"]",
"else",
"\"http\"",
"self",
".",
"_api",
"=",
"QNAPStats",
"(",
"f\"{protocol}://{config.get(CONF_HOST)}\"",
",",
"config",
".",
"get",... | [
174,
4
] | [
187,
22
] | python | en | ['en', 'en', 'en'] | True |
QNAPStatsAPI.update | (self) | Update API information and store locally. | Update API information and store locally. | def update(self):
"""Update API information and store locally."""
try:
self.data["system_stats"] = self._api.get_system_stats()
self.data["system_health"] = self._api.get_system_health()
self.data["smart_drive_health"] = self._api.get_smart_disk_health()
s... | [
"def",
"update",
"(",
"self",
")",
":",
"try",
":",
"self",
".",
"data",
"[",
"\"system_stats\"",
"]",
"=",
"self",
".",
"_api",
".",
"get_system_stats",
"(",
")",
"self",
".",
"data",
"[",
"\"system_health\"",
"]",
"=",
"self",
".",
"_api",
".",
"ge... | [
190,
4
] | [
199,
72
] | python | en | ['en', 'en', 'en'] | True |
QNAPSensor.__init__ | (self, api, variable, variable_info, monitor_device=None) | Initialize the sensor. | Initialize the sensor. | def __init__(self, api, variable, variable_info, monitor_device=None):
"""Initialize the sensor."""
self.var_id = variable
self.var_name = variable_info[0]
self.var_units = variable_info[1]
self.var_icon = variable_info[2]
self.monitor_device = monitor_device
self... | [
"def",
"__init__",
"(",
"self",
",",
"api",
",",
"variable",
",",
"variable_info",
",",
"monitor_device",
"=",
"None",
")",
":",
"self",
".",
"var_id",
"=",
"variable",
"self",
".",
"var_name",
"=",
"variable_info",
"[",
"0",
"]",
"self",
".",
"var_units... | [
205,
4
] | [
212,
23
] | python | en | ['en', 'en', 'en'] | True |
QNAPSensor.name | (self) | Return the name of the sensor, if any. | Return the name of the sensor, if any. | def name(self):
"""Return the name of the sensor, if any."""
server_name = self._api.data["system_stats"]["system"]["name"]
if self.monitor_device is not None:
return f"{server_name} {self.var_name} ({self.monitor_device})"
return f"{server_name} {self.var_name}" | [
"def",
"name",
"(",
"self",
")",
":",
"server_name",
"=",
"self",
".",
"_api",
".",
"data",
"[",
"\"system_stats\"",
"]",
"[",
"\"system\"",
"]",
"[",
"\"name\"",
"]",
"if",
"self",
".",
"monitor_device",
"is",
"not",
"None",
":",
"return",
"f\"{server_n... | [
215,
4
] | [
221,
47
] | python | en | ['en', 'en', 'en'] | True |
QNAPSensor.icon | (self) | Return the icon to use in the frontend, if any. | Return the icon to use in the frontend, if any. | def icon(self):
"""Return the icon to use in the frontend, if any."""
return self.var_icon | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"self",
".",
"var_icon"
] | [
224,
4
] | [
226,
28
] | python | en | ['en', 'en', 'en'] | True |
QNAPSensor.unit_of_measurement | (self) | Return the unit the value is expressed in. | Return the unit the value is expressed in. | def unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self.var_units | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"self",
".",
"var_units"
] | [
229,
4
] | [
231,
29
] | python | en | ['en', 'en', 'en'] | True |
QNAPSensor.update | (self) | Get the latest data for the states. | Get the latest data for the states. | def update(self):
"""Get the latest data for the states."""
self._api.update() | [
"def",
"update",
"(",
"self",
")",
":",
"self",
".",
"_api",
".",
"update",
"(",
")"
] | [
233,
4
] | [
235,
26
] | python | en | ['en', 'en', 'en'] | True |
QNAPCPUSensor.state | (self) | Return the state of the sensor. | Return the state of the sensor. | def state(self):
"""Return the state of the sensor."""
if self.var_id == "cpu_temp":
return self._api.data["system_stats"]["cpu"]["temp_c"]
if self.var_id == "cpu_usage":
return self._api.data["system_stats"]["cpu"]["usage_percent"] | [
"def",
"state",
"(",
"self",
")",
":",
"if",
"self",
".",
"var_id",
"==",
"\"cpu_temp\"",
":",
"return",
"self",
".",
"_api",
".",
"data",
"[",
"\"system_stats\"",
"]",
"[",
"\"cpu\"",
"]",
"[",
"\"temp_c\"",
"]",
"if",
"self",
".",
"var_id",
"==",
"... | [
242,
4
] | [
247,
73
] | python | en | ['en', 'en', 'en'] | True |
QNAPMemorySensor.state | (self) | Return the state of the sensor. | Return the state of the sensor. | def state(self):
"""Return the state of the sensor."""
free = float(self._api.data["system_stats"]["memory"]["free"]) / 1024
if self.var_id == "memory_free":
return round_nicely(free)
total = float(self._api.data["system_stats"]["memory"]["total"]) / 1024
used = tot... | [
"def",
"state",
"(",
"self",
")",
":",
"free",
"=",
"float",
"(",
"self",
".",
"_api",
".",
"data",
"[",
"\"system_stats\"",
"]",
"[",
"\"memory\"",
"]",
"[",
"\"free\"",
"]",
")",
"/",
"1024",
"if",
"self",
".",
"var_id",
"==",
"\"memory_free\"",
":... | [
254,
4
] | [
267,
44
] | python | en | ['en', 'en', 'en'] | True |
QNAPMemorySensor.device_state_attributes | (self) | Return the state attributes. | Return the state attributes. | def device_state_attributes(self):
"""Return the state attributes."""
if self._api.data:
data = self._api.data["system_stats"]["memory"]
size = round_nicely(float(data["total"]) / 1024)
return {ATTR_MEMORY_SIZE: f"{size} {DATA_GIBIBYTES}"} | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"if",
"self",
".",
"_api",
".",
"data",
":",
"data",
"=",
"self",
".",
"_api",
".",
"data",
"[",
"\"system_stats\"",
"]",
"[",
"\"memory\"",
"]",
"size",
"=",
"round_nicely",
"(",
"float",
"(",
"... | [
270,
4
] | [
275,
65
] | python | en | ['en', 'en', 'en'] | True |
QNAPNetworkSensor.state | (self) | Return the state of the sensor. | Return the state of the sensor. | def state(self):
"""Return the state of the sensor."""
if self.var_id == "network_link_status":
nic = self._api.data["system_stats"]["nics"][self.monitor_device]
return nic["link_status"]
data = self._api.data["bandwidth"][self.monitor_device]
if self.var_id == "... | [
"def",
"state",
"(",
"self",
")",
":",
"if",
"self",
".",
"var_id",
"==",
"\"network_link_status\"",
":",
"nic",
"=",
"self",
".",
"_api",
".",
"data",
"[",
"\"system_stats\"",
"]",
"[",
"\"nics\"",
"]",
"[",
"self",
".",
"monitor_device",
"]",
"return",... | [
282,
4
] | [
293,
57
] | python | en | ['en', 'en', 'en'] | True |
QNAPNetworkSensor.device_state_attributes | (self) | Return the state attributes. | Return the state attributes. | def device_state_attributes(self):
"""Return the state attributes."""
if self._api.data:
data = self._api.data["system_stats"]["nics"][self.monitor_device]
return {
ATTR_IP: data["ip"],
ATTR_MASK: data["mask"],
ATTR_MAC: data["mac"]... | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"if",
"self",
".",
"_api",
".",
"data",
":",
"data",
"=",
"self",
".",
"_api",
".",
"data",
"[",
"\"system_stats\"",
"]",
"[",
"\"nics\"",
"]",
"[",
"self",
".",
"monitor_device",
"]",
"return",
... | [
296,
4
] | [
308,
13
] | python | en | ['en', 'en', 'en'] | True |
QNAPSystemSensor.state | (self) | Return the state of the sensor. | Return the state of the sensor. | def state(self):
"""Return the state of the sensor."""
if self.var_id == "status":
return self._api.data["system_health"]
if self.var_id == "system_temp":
return int(self._api.data["system_stats"]["system"]["temp_c"]) | [
"def",
"state",
"(",
"self",
")",
":",
"if",
"self",
".",
"var_id",
"==",
"\"status\"",
":",
"return",
"self",
".",
"_api",
".",
"data",
"[",
"\"system_health\"",
"]",
"if",
"self",
".",
"var_id",
"==",
"\"system_temp\"",
":",
"return",
"int",
"(",
"se... | [
315,
4
] | [
321,
74
] | python | en | ['en', 'en', 'en'] | True |
QNAPSystemSensor.device_state_attributes | (self) | Return the state attributes. | Return the state attributes. | def device_state_attributes(self):
"""Return the state attributes."""
if self._api.data:
data = self._api.data["system_stats"]
days = int(data["uptime"]["days"])
hours = int(data["uptime"]["hours"])
minutes = int(data["uptime"]["minutes"])
ret... | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"if",
"self",
".",
"_api",
".",
"data",
":",
"data",
"=",
"self",
".",
"_api",
".",
"data",
"[",
"\"system_stats\"",
"]",
"days",
"=",
"int",
"(",
"data",
"[",
"\"uptime\"",
"]",
"[",
"\"days\"",... | [
324,
4
] | [
337,
13
] | python | en | ['en', 'en', 'en'] | True |
QNAPDriveSensor.state | (self) | Return the state of the sensor. | Return the state of the sensor. | def state(self):
"""Return the state of the sensor."""
data = self._api.data["smart_drive_health"][self.monitor_device]
if self.var_id == "drive_smart_status":
return data["health"]
if self.var_id == "drive_temp":
return int(data["temp_c"]) if data["temp_c"] is ... | [
"def",
"state",
"(",
"self",
")",
":",
"data",
"=",
"self",
".",
"_api",
".",
"data",
"[",
"\"smart_drive_health\"",
"]",
"[",
"self",
".",
"monitor_device",
"]",
"if",
"self",
".",
"var_id",
"==",
"\"drive_smart_status\"",
":",
"return",
"data",
"[",
"\... | [
344,
4
] | [
352,
75
] | python | en | ['en', 'en', 'en'] | True |
QNAPDriveSensor.name | (self) | Return the name of the sensor, if any. | Return the name of the sensor, if any. | def name(self):
"""Return the name of the sensor, if any."""
server_name = self._api.data["system_stats"]["system"]["name"]
return f"{server_name} {self.var_name} (Drive {self.monitor_device})" | [
"def",
"name",
"(",
"self",
")",
":",
"server_name",
"=",
"self",
".",
"_api",
".",
"data",
"[",
"\"system_stats\"",
"]",
"[",
"\"system\"",
"]",
"[",
"\"name\"",
"]",
"return",
"f\"{server_name} {self.var_name} (Drive {self.monitor_device})\""
] | [
355,
4
] | [
359,
77
] | python | en | ['en', 'en', 'en'] | True |
QNAPDriveSensor.device_state_attributes | (self) | Return the state attributes. | Return the state attributes. | def device_state_attributes(self):
"""Return the state attributes."""
if self._api.data:
data = self._api.data["smart_drive_health"][self.monitor_device]
return {
ATTR_DRIVE: data["drive_number"],
ATTR_MODEL: data["model"],
ATTR_SER... | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"if",
"self",
".",
"_api",
".",
"data",
":",
"data",
"=",
"self",
".",
"_api",
".",
"data",
"[",
"\"smart_drive_health\"",
"]",
"[",
"self",
".",
"monitor_device",
"]",
"return",
"{",
"ATTR_DRIVE",
... | [
362,
4
] | [
371,
13
] | python | en | ['en', 'en', 'en'] | True |
QNAPVolumeSensor.state | (self) | Return the state of the sensor. | Return the state of the sensor. | def state(self):
"""Return the state of the sensor."""
data = self._api.data["volumes"][self.monitor_device]
free_gb = int(data["free_size"]) / 1024 / 1024 / 1024
if self.var_id == "volume_size_free":
return round_nicely(free_gb)
total_gb = int(data["total_size"]) /... | [
"def",
"state",
"(",
"self",
")",
":",
"data",
"=",
"self",
".",
"_api",
".",
"data",
"[",
"\"volumes\"",
"]",
"[",
"self",
".",
"monitor_device",
"]",
"free_gb",
"=",
"int",
"(",
"data",
"[",
"\"free_size\"",
"]",
")",
"/",
"1024",
"/",
"1024",
"/... | [
378,
4
] | [
393,
50
] | python | en | ['en', 'en', 'en'] | True |
QNAPVolumeSensor.device_state_attributes | (self) | Return the state attributes. | Return the state attributes. | def device_state_attributes(self):
"""Return the state attributes."""
if self._api.data:
data = self._api.data["volumes"][self.monitor_device]
total_gb = int(data["total_size"]) / 1024 / 1024 / 1024
return {ATTR_VOLUME_SIZE: f"{round_nicely(total_gb)} {DATA_GIBIBYTES... | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"if",
"self",
".",
"_api",
".",
"data",
":",
"data",
"=",
"self",
".",
"_api",
".",
"data",
"[",
"\"volumes\"",
"]",
"[",
"self",
".",
"monitor_device",
"]",
"total_gb",
"=",
"int",
"(",
"data",
... | [
396,
4
] | [
402,
83
] | python | en | ['en', 'en', 'en'] | True |
_handle_cropped | (y_p) |
A straightforward helper that simply averages multiple crops if they are present.
Parameters
----------
y_p: np.ndarray
The predicted values with shape batch x targets (x <optional crops>)
Returns
-------
y_p_mean: np.ndarray
If there is an additional crop dimension... |
A straightforward helper that simply averages multiple crops if they are present. | def _handle_cropped(y_p):
"""
A straightforward helper that simply averages multiple crops if they are present.
Parameters
----------
y_p: np.ndarray
The predicted values with shape batch x targets (x <optional crops>)
Returns
-------
y_p_mean: np.ndarray
If ther... | [
"def",
"_handle_cropped",
"(",
"y_p",
")",
":",
"if",
"len",
"(",
"y_p",
".",
"shape",
")",
"==",
"2",
":",
"return",
"y_p",
"elif",
"len",
"(",
"y_p",
".",
"shape",
")",
"==",
"3",
":",
"return",
"y_p",
".",
"mean",
"(",
"-",
"1",
")",
"else",... | [
5,
0
] | [
24,
96
] | python | en | ['en', 'error', 'th'] | False |
_get_prediction | (outputs) | Checks if multiple outputs were provided, and selects | Checks if multiple outputs were provided, and selects | def _get_prediction(outputs):
"""Checks if multiple outputs were provided, and selects"""
if isinstance(outputs, (list, tuple)):
return outputs[0]
return outputs | [
"def",
"_get_prediction",
"(",
"outputs",
")",
":",
"if",
"isinstance",
"(",
"outputs",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"return",
"outputs",
"[",
"0",
"]",
"return",
"outputs"
] | [
35,
0
] | [
39,
18
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up Hive sensor devices. | Set up Hive sensor devices. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up Hive sensor devices."""
if discovery_info is None:
return
session = hass.data.get(DATA_HIVE)
devs = []
for dev in discovery_info:
devs.append(HiveBinarySensorEntity(session, dev))
add_entities(devs) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"if",
"discovery_info",
"is",
"None",
":",
"return",
"session",
"=",
"hass",
".",
"data",
".",
"get",
"(",
"DATA_HIVE",
")",
"devs",
"... | [
15,
0
] | [
24,
22
] | python | en | ['es', 'fr', 'en'] | False |
HiveBinarySensorEntity.unique_id | (self) | Return unique ID of entity. | Return unique ID of entity. | def unique_id(self):
"""Return unique ID of entity."""
return self._unique_id | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unique_id"
] | [
31,
4
] | [
33,
30
] | python | en | ['en', 'cy', 'en'] | True |
HiveBinarySensorEntity.device_info | (self) | Return device information. | Return device information. | def device_info(self):
"""Return device information."""
return {"identifiers": {(DOMAIN, self.unique_id)}, "name": self.name} | [
"def",
"device_info",
"(",
"self",
")",
":",
"return",
"{",
"\"identifiers\"",
":",
"{",
"(",
"DOMAIN",
",",
"self",
".",
"unique_id",
")",
"}",
",",
"\"name\"",
":",
"self",
".",
"name",
"}"
] | [
36,
4
] | [
38,
77
] | python | da | ['es', 'da', 'en'] | False |
HiveBinarySensorEntity.device_class | (self) | Return the class of this sensor. | Return the class of this sensor. | def device_class(self):
"""Return the class of this sensor."""
return DEVICETYPE_DEVICE_CLASS.get(self.node_device_type) | [
"def",
"device_class",
"(",
"self",
")",
":",
"return",
"DEVICETYPE_DEVICE_CLASS",
".",
"get",
"(",
"self",
".",
"node_device_type",
")"
] | [
41,
4
] | [
43,
65
] | python | en | ['en', 'en', 'en'] | True |
HiveBinarySensorEntity.name | (self) | Return the name of the binary sensor. | Return the name of the binary sensor. | def name(self):
"""Return the name of the binary sensor."""
return self.node_name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"node_name"
] | [
46,
4
] | [
48,
29
] | python | en | ['en', 'mi', 'en'] | True |
HiveBinarySensorEntity.device_state_attributes | (self) | Show Device Attributes. | Show Device Attributes. | def device_state_attributes(self):
"""Show Device Attributes."""
return self.attributes | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"return",
"self",
".",
"attributes"
] | [
51,
4
] | [
53,
30
] | python | en | ['en', 'en', 'en'] | True |
HiveBinarySensorEntity.is_on | (self) | Return true if the binary sensor is on. | Return true if the binary sensor is on. | def is_on(self):
"""Return true if the binary sensor is on."""
return self.session.sensor.get_state(self.node_id, self.node_device_type) | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"session",
".",
"sensor",
".",
"get_state",
"(",
"self",
".",
"node_id",
",",
"self",
".",
"node_device_type",
")"
] | [
56,
4
] | [
58,
81
] | python | en | ['en', 'fy', 'en'] | True |
HiveBinarySensorEntity.update | (self) | Update all Node data from Hive. | Update all Node data from Hive. | def update(self):
"""Update all Node data from Hive."""
self.session.core.update_data(self.node_id)
self.attributes = self.session.attributes.state_attributes(self.node_id) | [
"def",
"update",
"(",
"self",
")",
":",
"self",
".",
"session",
".",
"core",
".",
"update_data",
"(",
"self",
".",
"node_id",
")",
"self",
".",
"attributes",
"=",
"self",
".",
"session",
".",
"attributes",
".",
"state_attributes",
"(",
"self",
".",
"no... | [
60,
4
] | [
63,
80
] | python | en | ['en', 'en', 'en'] | True |
_async_reproduce_states | (
hass: HomeAssistantType,
state: State,
*,
context: Optional[Context] = None,
reproduce_options: Optional[Dict[str, Any]] = None,
) | Reproduce component states. | Reproduce component states. | async def _async_reproduce_states(
hass: HomeAssistantType,
state: State,
*,
context: Optional[Context] = None,
reproduce_options: Optional[Dict[str, Any]] = None,
) -> None:
"""Reproduce component states."""
async def call_service(service: str, keys: Iterable, data=None):
"""Call s... | [
"async",
"def",
"_async_reproduce_states",
"(",
"hass",
":",
"HomeAssistantType",
",",
"state",
":",
"State",
",",
"*",
",",
"context",
":",
"Optional",
"[",
"Context",
"]",
"=",
"None",
",",
"reproduce_options",
":",
"Optional",
"[",
"Dict",
"[",
"str",
"... | [
27,
0
] | [
71,
65
] | python | en | ['de', 'en', 'en'] | True |
async_reproduce_states | (
hass: HomeAssistantType,
states: Iterable[State],
*,
context: Optional[Context] = None,
reproduce_options: Optional[Dict[str, Any]] = None,
) | Reproduce component states. | Reproduce component states. | async def async_reproduce_states(
hass: HomeAssistantType,
states: Iterable[State],
*,
context: Optional[Context] = None,
reproduce_options: Optional[Dict[str, Any]] = None,
) -> None:
"""Reproduce component states."""
await asyncio.gather(
*(
_async_reproduce_states(
... | [
"async",
"def",
"async_reproduce_states",
"(",
"hass",
":",
"HomeAssistantType",
",",
"states",
":",
"Iterable",
"[",
"State",
"]",
",",
"*",
",",
"context",
":",
"Optional",
"[",
"Context",
"]",
"=",
"None",
",",
"reproduce_options",
":",
"Optional",
"[",
... | [
74,
0
] | [
89,
5
] | python | en | ['de', 'en', 'en'] | True |
AsyncMediaPlayer.__init__ | (self, hass) | Initialize the test media player. | Initialize the test media player. | def __init__(self, hass):
"""Initialize the test media player."""
self.hass = hass
self._volume = 0
self._state = STATE_OFF | [
"def",
"__init__",
"(",
"self",
",",
"hass",
")",
":",
"self",
".",
"hass",
"=",
"hass",
"self",
".",
"_volume",
"=",
"0",
"self",
".",
"_state",
"=",
"STATE_OFF"
] | [
19,
4
] | [
23,
31
] | python | en | ['en', 'en', 'en'] | True |
AsyncMediaPlayer.state | (self) | State of the player. | State of the player. | def state(self):
"""State of the player."""
return self._state | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
26,
4
] | [
28,
26
] | python | en | ['en', 'en', 'en'] | True |
AsyncMediaPlayer.volume_level | (self) | Volume level of the media player (0..1). | Volume level of the media player (0..1). | def volume_level(self):
"""Volume level of the media player (0..1)."""
return self._volume | [
"def",
"volume_level",
"(",
"self",
")",
":",
"return",
"self",
".",
"_volume"
] | [
31,
4
] | [
33,
27
] | python | en | ['en', 'en', 'en'] | True |
AsyncMediaPlayer.supported_features | (self) | Flag media player features that are supported. | Flag media player features that are supported. | def supported_features(self):
"""Flag media player features that are supported."""
return (
mp.const.SUPPORT_VOLUME_SET
| mp.const.SUPPORT_PLAY
| mp.const.SUPPORT_PAUSE
| mp.const.SUPPORT_TURN_OFF
| mp.const.SUPPORT_TURN_ON
) | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"(",
"mp",
".",
"const",
".",
"SUPPORT_VOLUME_SET",
"|",
"mp",
".",
"const",
".",
"SUPPORT_PLAY",
"|",
"mp",
".",
"const",
".",
"SUPPORT_PAUSE",
"|",
"mp",
".",
"const",
".",
"SUPPORT_TURN_OFF",... | [
36,
4
] | [
44,
9
] | python | en | ['en', 'en', 'en'] | True |
AsyncMediaPlayer.async_set_volume_level | (self, volume) | Set volume level, range 0..1. | Set volume level, range 0..1. | async def async_set_volume_level(self, volume):
"""Set volume level, range 0..1."""
self._volume = volume | [
"async",
"def",
"async_set_volume_level",
"(",
"self",
",",
"volume",
")",
":",
"self",
".",
"_volume",
"=",
"volume"
] | [
46,
4
] | [
48,
29
] | python | en | ['fr', 'zu', 'en'] | False |
AsyncMediaPlayer.async_media_play | (self) | Send play command. | Send play command. | async def async_media_play(self):
"""Send play command."""
self._state = STATE_PLAYING | [
"async",
"def",
"async_media_play",
"(",
"self",
")",
":",
"self",
".",
"_state",
"=",
"STATE_PLAYING"
] | [
50,
4
] | [
52,
35
] | python | en | ['en', 'en', 'en'] | True |
AsyncMediaPlayer.async_media_pause | (self) | Send pause command. | Send pause command. | async def async_media_pause(self):
"""Send pause command."""
self._state = STATE_PAUSED | [
"async",
"def",
"async_media_pause",
"(",
"self",
")",
":",
"self",
".",
"_state",
"=",
"STATE_PAUSED"
] | [
54,
4
] | [
56,
34
] | python | en | ['en', 'en', 'en'] | True |
AsyncMediaPlayer.async_turn_on | (self) | Turn the media player on. | Turn the media player on. | async def async_turn_on(self):
"""Turn the media player on."""
self._state = STATE_ON | [
"async",
"def",
"async_turn_on",
"(",
"self",
")",
":",
"self",
".",
"_state",
"=",
"STATE_ON"
] | [
58,
4
] | [
60,
30
] | python | en | ['en', 'en', 'en'] | True |
AsyncMediaPlayer.async_turn_off | (self) | Turn the media player off. | Turn the media player off. | async def async_turn_off(self):
"""Turn the media player off."""
self._state = STATE_OFF | [
"async",
"def",
"async_turn_off",
"(",
"self",
")",
":",
"self",
".",
"_state",
"=",
"STATE_OFF"
] | [
62,
4
] | [
64,
31
] | python | en | ['en', 'en', 'en'] | True |
SyncMediaPlayer.__init__ | (self, hass) | Initialize the test media player. | Initialize the test media player. | def __init__(self, hass):
"""Initialize the test media player."""
self.hass = hass
self._volume = 0
self._state = STATE_OFF | [
"def",
"__init__",
"(",
"self",
",",
"hass",
")",
":",
"self",
".",
"hass",
"=",
"hass",
"self",
".",
"_volume",
"=",
"0",
"self",
".",
"_state",
"=",
"STATE_OFF"
] | [
70,
4
] | [
74,
31
] | python | en | ['en', 'en', 'en'] | True |
SyncMediaPlayer.state | (self) | State of the player. | State of the player. | def state(self):
"""State of the player."""
return self._state | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
77,
4
] | [
79,
26
] | python | en | ['en', 'en', 'en'] | True |
SyncMediaPlayer.volume_level | (self) | Volume level of the media player (0..1). | Volume level of the media player (0..1). | def volume_level(self):
"""Volume level of the media player (0..1)."""
return self._volume | [
"def",
"volume_level",
"(",
"self",
")",
":",
"return",
"self",
".",
"_volume"
] | [
82,
4
] | [
84,
27
] | 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.